Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: mvpp2: Improve data types and use min()

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>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20240711154741.174745-1-thorsten.blum@toblux.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Thorsten Blum and committed by
Jakub Kicinski
f7023b3d 275a63c9

+6 -6
+6 -6
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
··· 2766 2766 } 2767 2767 } 2768 2768 2769 - static u32 mvpp2_usec_to_cycles(u32 usec, unsigned long clk_hz) 2769 + static u32 mvpp2_usec_to_cycles(u32 usec, u32 clk_hz) 2770 2770 { 2771 2771 u64 tmp = (u64)clk_hz * usec; 2772 2772 2773 2773 do_div(tmp, USEC_PER_SEC); 2774 2774 2775 - return tmp > U32_MAX ? U32_MAX : tmp; 2775 + return min(tmp, U32_MAX); 2776 2776 } 2777 2777 2778 - static u32 mvpp2_cycles_to_usec(u32 cycles, unsigned long clk_hz) 2778 + static u32 mvpp2_cycles_to_usec(u32 cycles, u32 clk_hz) 2779 2779 { 2780 2780 u64 tmp = (u64)cycles * USEC_PER_SEC; 2781 2781 2782 2782 do_div(tmp, clk_hz); 2783 2783 2784 - return tmp > U32_MAX ? U32_MAX : tmp; 2784 + return min(tmp, U32_MAX); 2785 2785 } 2786 2786 2787 2787 /* Set the time delay in usec before Rx interrupt */ 2788 2788 static void mvpp2_rx_time_coal_set(struct mvpp2_port *port, 2789 2789 struct mvpp2_rx_queue *rxq) 2790 2790 { 2791 - unsigned long freq = port->priv->tclk; 2791 + u32 freq = port->priv->tclk; 2792 2792 u32 val = mvpp2_usec_to_cycles(rxq->time_coal, freq); 2793 2793 2794 2794 if (val > MVPP2_MAX_ISR_RX_THRESHOLD) { ··· 2804 2804 2805 2805 static void mvpp2_tx_time_coal_set(struct mvpp2_port *port) 2806 2806 { 2807 - unsigned long freq = port->priv->tclk; 2807 + u32 freq = port->priv->tclk; 2808 2808 u32 val = mvpp2_usec_to_cycles(port->tx_time_coal, freq); 2809 2809 2810 2810 if (val > MVPP2_MAX_ISR_TX_THRESHOLD) {