Re: [PATCH] dmaengine: mcf-edma: Use struct_size()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, May 06, 2023 at 06:22:06PM +0200, Christophe JAILLET wrote:
> Use struct_size() instead of hand writing it.
> This is less verbose and more informative.
> 
> 'mcf_chan' is now unused and can be removed. In fact, it is shadowed by
> another variable in the 'for' loop below. Keep this one.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
> ---
> It will also help scripts when __counted_by macro will be added.
> See [1].
> 
> [1]: https://lore.kernel.org/all/6453f739.170a0220.62695.7785@xxxxxxxxxxxxx/

Of course, the main selling point of struct_size() for me is that it
protects you against integer overflows.  Open coding the math might end
up giving you a size which is smaller than expected but struct_size()
will give you ULONG_MAX in that same situation.  The allocation will
fail as expected.  #Safe.

Even when the open coded math is safe, this is easier to audit in an
automated way.

regards,
dan carpenter




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux