Re: [PATCH v4 6/7] mtd: spi-nor: Use the spi_mem_xx() API

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

 



Hi Cyrille,

On Wed, May 23, 2018 at 5:56 PM, Cyrille Pitchen
<cyrille.pitchen@xxxxxxxxxxxxx> wrote:
> Le 23/05/2018 à 17:44, Cyrille Pitchen a écrit :
>> Le 26/04/2018 à 18:18, Boris Brezillon a écrit :
>>>  static int m25p80_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
>>>  {
>>>      struct m25p *flash = nor->priv;
>>> -    struct spi_device *spi = flash->spi;
>>> -
>>> -    flash->command[0] = opcode;
>>> -    if (buf)
>>> -            memcpy(&flash->command[1], buf, len);
>>> +    struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 1),
>>> +                                      SPI_MEM_OP_NO_ADDR,
>>> +                                      SPI_MEM_OP_NO_DUMMY,
>>
>> I didn't test nor compiled to verify but I have some doubt:
>> here the 'op' variable is allocated on the stack and both definitions
>> of SPI_MEM_OP_NO_ADDR and SPI_MEM_OP_NO_DUMMY macros are { }.
>>
>> It might be some rule of the C language that I ignore but are we guaranteed
>> that the .nbytes member of both structures is actually initialized to 0 ?
>>
>> I would say no: I think since the structure is allocated on the stack all
>> members not being explicitly initialized are left uninitialized by the
>> compiler when it generates the assembler code. However, I'm not 100% sure of
>> that.
>
> Actually, I'm reading that with C99 extensions, "omitted field members are
> implicitly initialized the same as objects that have static storage duration."
> https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

JFTR, omitted field members are.
But IIRC, implicit gaps due to alignment rules aren't, which mostly matters
for leaking random data to userspace.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux