lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D2AAC5AF-59D0-4985-A3DD-EC9E72324CD7@toblux.com>
Date: Tue, 16 Jul 2024 19:48:31 +0200
From: Thorsten Blum <thorsten.blum@...lux.com>
To: "Russell King (Oracle)" <linux@...linux.org.uk>
Cc: marcin.s.wojtas@...il.com,
 davem@...emloft.net,
 edumazet@...gle.com,
 kuba@...nel.org,
 pabeni@...hat.com,
 netdev@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next] net: mvpp2: Improve data types and use min()

On 15. Jul 2024, at 17:44, Russell King (Oracle) <linux@...linux.org.uk> wrote:
> On Thu, Jul 11, 2024 at 05:47:43PM +0200, Thorsten Blum wrote:
>> 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@...lux.com>
> 
> I'm still on holiday, but it's a wet day today. Don't expect replies
> from me to be regular.
> 
> I don't think this is a good idea.
> 
> priv->tclk comes from clk_get_rate() which returns an unsigned long.
> tclk should _also_ be an unsigned long, not a u32, so that the range
> of values clk_get_rate() returns can be represented without being
> truncted.
> 
> Thus the use of unsigned long elsewhere where tclk is passed into is
> actually correct.

I don't think tclk should be an unsigned long.

In [1] Eric Dumazet wrote:

  "This is silly, clk_hz fits in a u32, why pretends it is 64bit ?"

and all functions in mvpp2_main.c (mvpp2_write(), do_div(),
device_property_read_u32(), and mvpp22_gop_fca_set_timer()), which have
tclk as a direct or indirect argument, assume tclk is a u32.

Although mvpp2_cycles_to_usec() suggests it can be called with an
unsigned long clk_hz, do_div() then immediately casts it to a u32
anyway.

Yes, the function clk_get_rate() returns an unsigned long according to
its signature, but tclk is always used as a u32 afterwards.

I'm not familiar with the hardware, but I guess the clock rate always
fits into 32 bits (just like Eric wrote)?

Thanks,
Thorsten

> If we need to limit tclk to values that u32 can represent, then that
> needs to be done here:
> 
>                priv->tclk = clk_get_rate(priv->pp_clk);
> 
> by assigning the return value to an unsigned long local variable,
> then checking its upper liit before assigning it to priv->tclk.

[1] https://lore.kernel.org/linux-kernel/cbcdb354-04de-2a9a-1754-c32dd014e859@gmail.com/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ