netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: mvpp2: Improve data types and use min()
@ 2024-07-11 15:47 Thorsten Blum
  2024-07-12 18:25 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thorsten Blum @ 2024-07-11 15:47 UTC (permalink / raw)
  To: marcin.s.wojtas, linux, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, Thorsten Blum

Change the data type of the variable freq in mvpp2_rx_time_coal_set()
and mvpp2_tx_time_coal_set() to u32 because port->priv->tclk also has
the data type u32.

Change the data type of the function parameter clk_hz in
mvpp2_usec_to_cycles() and mvpp2_cycles_to_usec() to u32 accordingly
and remove the following Coccinelle/coccicheck warning reported by
do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead

Use min() to simplify the code and improve its readability.

Compile-tested only.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 9adf4301c9b1..1e52256a9ea8 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -2766,29 +2766,29 @@ static void mvpp2_tx_pkts_coal_set(struct mvpp2_port *port,
 	}
 }
 
-static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz)
+static u32 mvpp2_usec_to_cycles(u32 usec, u32 clk_hz)
 {
 	u64 tmp = (u64)clk_hz * usec;
 
 	do_div(tmp, USEC_PER_SEC);
 
-	return tmp > U32_MAX ? U32_MAX : tmp;
+	return min(tmp, U32_MAX);
 }
 
-static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz)
+static u32 mvpp2_cycles_to_usec(u32 cycles, u32 clk_hz)
 {
 	u64 tmp = (u64)cycles * USEC_PER_SEC;
 
 	do_div(tmp, clk_hz);
 
-	return tmp > U32_MAX ? U32_MAX : tmp;
+	return min(tmp, U32_MAX);
 }
 
 /* Set the time delay in usec before Rx interrupt */
 static void mvpp2_rx_time_coal_set(struct mvpp2_port *port,
 				   struct mvpp2_rx_queue *rxq)
 {
-	unsigned long freq = port->priv->tclk;
+	u32 freq = port->priv->tclk;
 	u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq);
 
 	if (val > MVPP2_MAX_ISR_RX_THRESHOLD) {
@@ -2804,7 +2804,7 @@ static void mvpp2_rx_time_coal_set(struct mvpp2_port *port,
 
 static void mvpp2_tx_time_coal_set(struct mvpp2_port *port)
 {
-	unsigned long freq = port->priv->tclk;
+	u32 freq = port->priv->tclk;
 	u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq);
 
 	if (val > MVPP2_MAX_ISR_TX_THRESHOLD) {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-17 12:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-11 15:47 [PATCH net-next] net: mvpp2: Improve data types and use min() Thorsten Blum
2024-07-12 18:25 ` Simon Horman
2024-07-13 22:50 ` patchwork-bot+netdevbpf
2024-07-15 15:44 ` Russell King (Oracle)
2024-07-15 16:07   ` Jakub Kicinski
2024-07-15 18:39   ` Simon Horman
2024-07-16 17:48   ` Thorsten Blum
2024-07-17 12:30     ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).