[PATCH 7/8] mtd: rawnand: qcom: Early structure initialization

Miquel Raynal miquel.raynal at bootlin.com
Thu Jul 27 08:14:11 PDT 2023


Hi Tudor,

tudor.ambarus at linaro.org wrote on Thu, 27 Jul 2023 16:03:40 +0100:

> On 7/16/23 15:46, Miquel Raynal wrote:
> > Instead of allocating a structure on the stack with random data and then
> > expect the callee to perform the initialization (which is, in general,
> > error prone), prefer zeroing the structure explicitly at allocation and
> > provide the already zeroed area, so no explicit memset operation is
> > needed. It is probably safer to do so, so we limit the timeframe when
> > dirty data could actually be accessed by mistake.  
> 
> Why is zeroed data considered safe or sane?

I believe allocating structures like that on the stack will make their
content inherit from previous values used there, which is generally a
bad idea if we expect the structure to be zeroed, which is the case
here.

This structure is meant to be zeroed before being used, so instead of
carrying stale data that will be wiped off later, I prefer to have it
zeroed earlier. Reducing the time when one could access stale data or
write something that will be reset does not sound totally useless to
me, in particular given the number of changes this driver has been
subject to recently.

Thanks,
Miquèl



More information about the linux-mtd mailing list