linux/drivers/mtd/spi-nor
Arnd Bergmann 71c8f9cf26 mtd: spi-nor: avoid holes in struct spi_mem_op
gcc gets confused when -ftrivial-auto-var-init=pattern is used on sparse
bit fields such as 'struct spi_mem_op', which caused the previous false
positive warning about an uninitialized variable:

drivers/mtd/spi-nor/spansion.c: error: 'op' is used uninitialized [-Werror=uninitialized]

In fact, the variable is fully initialized and gcc does not see it being
used, so the warning is entirely bogus. The problem appears to be
a misoptimization in the initialization of single bit fields when the
rest of the bytes are not initialized.

A previous workaround added another initialization, which ended up
shutting up the warning in spansion.c, though it apparently still happens
in other files as reported by Peter Foley in the gcc bugzilla. The
workaround of adding a fake initialization seems particularly bad
because it would set values that can never be correct but prevent the
compiler from warning about actually missing initializations.

Revert the broken workaround and instead pad the structure to only
have bitfields that add up to full bytes, which should avoid this
behavior in all drivers.

I also filed a new bug against gcc with what I found, so this can
hopefully be addressed in future gcc releases. At the moment, only
gcc-12 and gcc-13 are affected.

Cc: Peter Foley <pefoley2@pefoley.com>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110743
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108402
Link: https://godbolt.org/z/efMMsG1Kx
Fixes: 420c4495b5 ("mtd: spi-nor: spansion: make sure local struct does not contain garbage")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230719190045.4007391-1-arnd@kernel.org
2023-07-27 16:54:22 +02:00
..
controllers mtd: Use of_property_read_bool() for boolean properties 2023-03-22 17:02:17 +01:00
atmel.c mtd: spi-nor: atmel: unify function names 2022-02-25 09:44:31 +02:00
catalyst.c mtd: spi-nor: catalyst: unify function names 2022-02-25 09:44:31 +02:00
core.c mtd: spi-nor: Fix divide by zero for spi-nor-generic flashes 2023-05-26 19:40:32 +02:00
core.h Core MTD changes: 2023-04-25 17:23:42 -07:00
debugfs.c Core MTD changes: 2023-04-25 17:23:42 -07:00
eon.c mtd: spi-nor: support eon en25qh256a variant 2022-05-09 16:58:24 +05:30
esmt.c mtd: spi-nor: esmt: Use correct name of f25l32qa 2022-07-19 13:05:31 +03:00
everspin.c mtd: spi-nor: everspin: unify function names 2022-02-25 09:44:31 +02:00
fujitsu.c mtd: spi-nor: fujitsu: unify function names 2022-02-25 09:44:31 +02:00
gigadevice.c mtd: spi-nor: gigadevice: gd25q256: replace gd25q256_default_init with gd25q256_post_bfpt 2022-11-21 16:27:10 +02:00
intel.c mtd: spi-nor: intel: unify function names 2022-02-25 09:44:31 +02:00
issi.c mtd: spi-nor: sfdp: Rename BFPT_DWORD() macro to SFDP_DWORD() 2022-12-26 09:47:04 +02:00
Kconfig
macronix.c mtd: spi-nor: Set the 4-Byte Address Mode method based on SFDP data 2023-04-04 09:43:50 +03:00
Makefile mtd: spi-nor: expose internal parameters via debugfs 2022-05-09 16:55:22 +05:30
micron-st.c mtd: spi-nor: Allow post_sfdp hook to return errors 2023-04-08 09:30:17 +03:00
otp.c mtd: spi-nor: Reorder the preparation vs. locking steps 2023-03-29 13:46:07 +03:00
sfdp.c mtd: spi-nor: sfdp: Add support for SCCR map for multi-chip device 2023-04-08 09:30:17 +03:00
sfdp.h mtd: spi-nor: Set the 4-Byte Address Mode method based on SFDP data 2023-04-04 09:43:50 +03:00
spansion.c mtd: spi-nor: avoid holes in struct spi_mem_op 2023-07-27 16:54:22 +02:00
sst.c mtd: spi-nor: Reorder the preparation vs. locking steps 2023-03-29 13:46:07 +03:00
swp.c mtd: spi-nor: Reorder the preparation vs. locking steps 2023-03-29 13:46:07 +03:00
sysfs.c mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver 2022-11-21 15:37:16 +02:00
winbond.c mtd: spi-nor: Set the 4-Byte Address Mode method based on SFDP data 2023-04-04 09:43:50 +03:00
xilinx.c mtd: spi-nor: Introduce the concept of bank 2023-03-29 13:46:07 +03:00
xmc.c mtd: spi-nor: xmc: unify function names 2022-02-25 09:44:32 +02:00