linux-stable/drivers/gpio
Linus Torvalds 64f42625d8 gpiolib: acpi: use correct format characters
[ Upstream commit 213d266ebf ]

When compiling with -Wformat, clang emits the following warning:

  gpiolib-acpi.c:393:4: warning: format specifies type 'unsigned char' but the argument has type 'int' [-Wformat]
                        pin);
                        ^~~

So warning that '%hhX' is paired with an 'int' is all just completely
mindless and wrong. Sadly, I can see a different bogus warning reason
why people would want to use '%02hhX'.

Again, the *sane* thing from a human perspective is to use '%02X. But
if the compiler doesn't do any range analysis at all, it could decide
that "Oh, that print format could need up to 8 bytes of space in the
result". Using '%02hhX' would cut that down to two.

And since we use

        char ev_name[5];

and currently use "_%c%02hhX" as the format string, even a compiler
that doesn't notice that "pin <= 255" test that guards this all will
go "OK, that's at most 4 bytes and the final NUL termination, so it's
fine".

While a compiler - like gcc - that only sees that the original source
of the 'pin' value is a 'unsigned short' array, and then doesn't take
the "pin <= 255" into account, will warn like this:

  gpiolib-acpi.c: In function 'acpi_gpiochip_request_interrupt':
  gpiolib-acpi.c:206:24: warning: '%02X' directive writing between 2 and 4 bytes into a region of size 3 [-Wformat-overflow=]
       sprintf(ev_name, "_%c%02X",
                            ^~~~
  gpiolib-acpi.c:206:20: note: directive argument in the range [0, 65535]

because gcc isn't being very good at that argument range analysis either.

In other words, the original use of 'hhx' was bogus to begin with, and
due to *another* compiler warning being bad, and we had that bad code
being written back in 2016 to work around _that_ compiler warning
(commit e40a3ae1f7: "gpio: acpi: work around false-positive
-Wstring-overflow warning").

Sadly, two different bad compiler warnings together does not make for
one good one.

It just makes for even more pain.

End result: I think the simplest and cleanest option is simply the
proposed change which undoes that '%hhX' change for gcc, and replaces
it with just using a slightly bigger stack allocation. It's not like
a 5-byte allocation is in any way likely to have saved any actual stack,
since all the other variables in that function are 'int' or bigger.

False-positive compiler warnings really do make people write worse
code, and that's a problem. But on a scale of bad code, I feel that
extending the buffer trivially is better than adding a pointless cast
that literally makes no sense.

At least in this case the end result isn't unreadable or buggy. We've
had several cases of bad compiler warnings that caused changes that
were actually horrendously wrong.

Fixes: e40a3ae1f7 ("gpio: acpi: work around false-positive -Wstring-overflow warning")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-04-20 09:08:31 +02:00
..
devres.c gpio: devres: Improve kerneldoc 2017-08-14 15:01:13 +02:00
gpio-74x164.c gpio: 74x164: Fix crash during .remove() 2018-02-25 11:07:56 +01:00
gpio-74xx-mmio.c
gpio-104-dio-48e.c Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
gpio-104-idi-48.c Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
gpio-104-idio-16.c Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
gpio-adnp.c gpio: adnp: Fix testing wrong value in adnp_gpio_direction_input 2019-04-03 06:25:19 +02:00
gpio-adp5520.c
gpio-adp5588.c gpio: adp5588: Fix sleep-in-atomic-context bug 2018-10-10 08:54:19 +02:00
gpio-altera-a10sr.c gpio: altera-a10sr: Set proper output level for direction_output 2019-02-06 17:31:35 +01:00
gpio-altera.c gpio: Convert to using %pOF instead of full_name 2017-08-14 15:01:12 +02:00
gpio-amd8111.c
gpio-amdpt.c
gpio-arizona.c gpio: arizona: put pm_runtime in case of failure 2020-07-29 07:42:51 +02:00
gpio-aspeed.c gpio: aspeed: fix a potential NULL pointer dereference 2019-05-04 09:15:21 +02:00
gpio-ath79.c gpio: ath79: add missing MODULE_DESCRIPTION/LICENSE 2018-02-03 17:38:52 +01:00
gpio-axp209.c
gpio-bcm-kona.c gpio: bcm-kona: make use of raw_spinlock variants 2017-03-16 21:52:07 +01:00
gpio-bd9571mwv.c gpio: Add ROHM BD9571MWV-M PMIC GPIO driver 2017-04-28 09:47:46 +02:00
gpio-brcmstb.c gpio: brcmstb: release the bgpio lock during irq handlers 2018-11-21 09:24:17 +01:00
gpio-bt8xx.c
gpio-clps711x.c
gpio-crystalcove.c gpio: crystalcove: Do not write regular gpio registers for virtual GPIOs 2017-05-23 10:02:01 +02:00
gpio-cs5535.c
gpio-da9052.c
gpio-da9055.c
gpio-davinci.c gpio: davinci: Assign first bank regs for unbanked case 2018-02-25 11:07:56 +01:00
gpio-dln2.c
gpio-dwapb.c gpio: dwapb: fix missing first irq for edgeboth irq type 2017-06-21 09:36:46 +02:00
gpio-em.c
gpio-ep93xx.c
gpio-etraxfs.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
gpio-exar.c gpio: exar: Fix bad handling for ida_simple_get error path 2020-06-03 08:17:59 +02:00
gpio-f7188x.c gpio: f7188x: Add a missing break 2017-04-28 10:09:16 +02:00
gpio-ftgpio010.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
gpio-ge.c gpio: Convert to using %pOF instead of full_name 2017-08-14 15:01:12 +02:00
gpio-gpio-mm.c Annotate hardware config module parameters in drivers/gpio/ 2017-04-20 12:02:32 +01:00
gpio-grgpio.c gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_irq_map/unmap() 2020-02-28 16:35:56 +01:00
gpio-htc-egpio.c
gpio-ich.c
gpio-ingenic.c gpio: Add gpio-ingenic driver 2017-05-22 17:18:19 +02:00
gpio-intel-mid.c
gpio-iop.c gpio: iop: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE 2018-02-03 17:38:52 +01:00
gpio-it87.c gpio: it87: add support for IT8772F Super I/O. 2017-08-14 15:03:38 +02:00
gpio-janz-ttl.c
gpio-kempld.c
gpio-ks8695.c
gpio-loongson.c
gpio-loongson1.c
gpio-lp873x.c
gpio-lp3943.c
gpio-lp87565.c gpio: lp87565: Set proper output level and direction for direction_output 2017-07-31 15:26:57 +02:00
gpio-lpc18xx.c
gpio-lpc32xx.c
gpio-lynxpoint.c
gpio-max730x.c
gpio-max732x.c gpio: max732x: move header file out of I2C realm 2017-05-23 11:33:59 +02:00
gpio-max7300.c
gpio-max7301.c gpio: max7301: fix driver for use with CONFIG_VMAP_STACK 2018-12-29 13:39:09 +01:00
gpio-max77620.c gpio: max77620: Fixup debounce delays 2019-12-01 09:13:12 +01:00
gpio-mb86s7x.c gpio: mb86s7x: Handle return value of clk_prepare_enable. 2017-08-14 15:03:38 +02:00
gpio-mc9s08dz60.c
gpio-mc33880.c
gpio-menz127.c gpio: Fix wrong rounding in gpio-menz127 2018-10-03 17:00:53 -07:00
gpio-merrifield.c gpio: merrifield: Remove unused header 2017-06-16 11:13:11 +02:00
gpio-ml-ioh.c gpio: ml-ioh: Fix buffer underwrite on probe error path 2018-09-19 22:43:42 +02:00
gpio-mm-lantiq.c
gpio-mmio.c gpio: mmio: add support for NI 169445 NAND GPIO 2017-03-23 09:49:06 +01:00
gpio-mockup.c gpio: mockup: fix resource leak in error path 2020-11-22 10:00:24 +01:00
gpio-mpc8xxx.c gpio: mpc8xxx: Add platform device to gpiochip->parent 2020-01-17 19:45:53 +01:00
gpio-mpc5200.c
gpio-msic.c gpio: msic: fix error return code in platform_msic_gpio_probe() 2017-08-14 15:03:38 +02:00
gpio-mvebu.c gpio: mvebu: fix pwm .get_state period calculation 2021-01-30 13:31:15 +01:00
gpio-mxc.c gpio: mxc: use devres for irq generic chip 2017-08-21 00:09:33 +02:00
gpio-mxs.c gpio: mxs: Get rid of external API call 2018-11-10 07:48:34 -08:00
gpio-octeon.c
gpio-omap.c gpio: omap: ensure irq is enabled before wakeup 2019-07-31 07:28:25 +02:00
gpio-palmas.c
gpio-pca953x.c gpio: pca953x: remove incorrect le16_to_cpu calls 2017-08-14 15:01:12 +02:00
gpio-pcf857x.c gpio: pcf857x: Fix missing first interrupt 2021-03-03 18:22:55 +01:00
gpio-pch.c gpio: pch: use devres for irq generic chip 2017-08-21 00:08:52 +02:00
gpio-pci-idio-16.c gpio: pci-idio-16: make use of raw_spinlock variants 2017-03-28 11:13:59 +02:00
gpio-pisosr.c
gpio-pl061.c gpio: pl061: Move irq_chip definition inside struct pl061 2019-01-26 09:37:01 +01:00
gpio-pxa.c gpio: pxa: handle corner case of unprobed device 2019-04-20 09:15:04 +02:00
gpio-rc5t583.c
gpio-rcar.c gpio: rcar: add gen[123] fallback compatibility strings 2017-08-14 15:01:12 +02:00
gpio-rdc321x.c
gpio-reg.c gpio: gpio-reg: add irq mapping for gpio-reg users 2017-03-24 14:05:00 +01:00
gpio-sa1100.c gpio: sa1100: implement get_direction method 2017-03-24 14:04:37 +01:00
gpio-sch.c
gpio-sch311x.c
gpio-sodaville.c
gpio-spear-spics.c
gpio-sta2x11.c gpio: sta2x11: use devres for irq generic chip 2017-08-21 00:06:04 +02:00
gpio-stmpe.c gpio: stmpe: i2c transfer are forbiden in atomic context 2018-02-03 17:38:48 +01:00
gpio-stp-xway.c
gpio-syscon.c gpio: syscon: Fix possible NULL ptr usage 2019-11-24 08:23:27 +01:00
gpio-tb10x.c gpio: Convert to using %pOF instead of full_name 2017-08-14 15:01:12 +02:00
gpio-tc3589x.c gpio: tc35894: fix up tc35894 interrupt configuration 2020-10-14 09:51:06 +02:00
gpio-tegra.c gpio: tegra: mask GPIO IRQs during IRQ shutdown 2020-06-03 08:17:48 +02:00
gpio-thunderx.c gpio: thunderx: fix error return code in thunderx_gpio_probe() 2018-04-12 12:32:20 +02:00
gpio-timberdale.c
gpio-tpic2810.c
gpio-tps6586x.c
gpio-tps65086.c
gpio-tps65218.c
gpio-tps65910.c
gpio-tps65912.c
gpio-tps68470.c gpio: Add support for TPS68470 GPIOs 2017-08-14 15:37:38 +02:00
gpio-ts4800.c
gpio-ts4900.c gpio: ts4900: Do not set DAT and OE together 2022-03-16 12:57:07 +01:00
gpio-ts5500.c
gpio-twl4030.c mfd: twl: Move header file out of I2C realm 2017-09-04 14:41:02 +01:00
gpio-twl6040.c gpio: twl6040: remove unneeded forward declaration 2017-08-23 10:20:16 +02:00
gpio-tz1090-pdc.c
gpio-tz1090.c gpio: Convert to using %pOF instead of full_name 2017-08-14 15:01:12 +02:00
gpio-ucb1400.c
gpio-vf610.c gpio: vf610: Do not share irq_chip 2019-06-15 11:54:59 +02:00
gpio-viperboard.c
gpio-vr41xx.c
gpio-vx855.c
gpio-wcove.c Merge (most of) tag 'mfd-next-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd 2017-07-07 13:30:05 -07:00
gpio-wm831x.c gpio: wm831x: Add basic device tree support 2017-03-23 11:45:55 +00:00
gpio-wm8350.c
gpio-wm8994.c
gpio-ws16c48.c Annotation of module parameters that specify device settings 2017-05-10 19:13:03 -07:00
gpio-xgene-sb.c
gpio-xgene.c
gpio-xilinx.c gpio: Convert to using %pOF instead of full_name 2017-08-14 15:01:12 +02:00
gpio-xlp.c gpio: xlp: Update for ARCH_THUNDER2 2017-03-16 21:52:10 +01:00
gpio-xra1403.c gpio: xra1403: Add EXAR XRA1403 SPI GPIO expander driver 2017-05-22 17:48:41 +02:00
gpio-xtensa.c
gpio-zevio.c gpio: zevio: make gpio_chip const 2017-08-23 09:21:54 +02:00
gpio-zx.c gpio: zx: make use of raw_spinlock variants 2017-03-16 21:52:10 +01:00
gpio-zynq.c gpio: zynq: Check return value of pm_runtime_get_sync 2021-07-20 16:17:50 +02:00
gpiolib-acpi.c gpiolib: acpi: use correct format characters 2022-04-20 09:08:31 +02:00
gpiolib-devprop.c gpio: fix "gpio-line-names" property retrieval 2018-01-02 20:31:04 +01:00
gpiolib-legacy.c
gpiolib-of.c gpio: of: Fix of_gpiochip_add() error path 2019-05-04 09:15:22 +02:00
gpiolib-sysfs.c This is the bulk of the GPIO changes for the v4.14 cycle: 2017-09-05 11:49:48 -07:00
gpiolib.c Revert "gpio: set up initial state from .get_direction()" 2020-04-24 08:01:02 +02:00
gpiolib.h gpiolib: Mark gpio_suffixes array with __maybe_unused 2018-09-26 08:38:12 +02:00
Kconfig gpio: max77620: Add missing dependency on GPIOLIB_IRQCHIP 2020-02-05 14:18:07 +00:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00