public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: asihpi: work around clang-17+ false positive fortify-string warning
@ 2024-02-28 14:01 Arnd Bergmann
  2024-02-28 14:37 ` Takashi Iwai
  0 siblings, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2024-02-28 14:01 UTC (permalink / raw)
  To: Kees Cook, Jaroslav Kysela, Takashi Iwai, Nathan Chancellor
  Cc: Arnd Bergmann, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-sound, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

One of the memory copies in this driver triggers a warning about a
possible out of range access:

In file included from /home/arnd/arm-soc/sound/pci/asihpi/hpimsgx.c:13:
/home/arnd/arm-soc/include/linux/fortify-string.h:553:4: error: call to '__write_overflow_field' declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
  553 |                         __write_overflow_field(p_size_field, size);
      |                         ^

Adding a range check avoids the problem, though I don't quite see
why it warns in the first place if clang has no knowledge of the
actual range of the type, or why I never saw the warning in previous
randconfig tests.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sound/pci/asihpi/hpimsgx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/pci/asihpi/hpimsgx.c b/sound/pci/asihpi/hpimsgx.c
index d0caef299481..4f245c3956b1 100644
--- a/sound/pci/asihpi/hpimsgx.c
+++ b/sound/pci/asihpi/hpimsgx.c
@@ -576,6 +576,9 @@ static u16 adapter_prepare(u16 adapter)
 	/* Open the adapter and streams */
 	u16 i;
 
+	if (adapter >= ARRAY_SIZE(rESP_HPI_ADAPTER_OPEN))
+		return 0;
+
 	/* call to HPI_ADAPTER_OPEN */
 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
 		HPI_ADAPTER_OPEN);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-29  1:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-28 14:01 [PATCH] ALSA: asihpi: work around clang-17+ false positive fortify-string warning Arnd Bergmann
2024-02-28 14:37 ` Takashi Iwai
2024-02-28 15:03   ` Arnd Bergmann
2024-02-28 16:24     ` Takashi Iwai
2024-02-28 17:23       ` Arnd Bergmann
2024-02-28 17:39     ` Clang __bos vs loop unrolling (was Re: [PATCH] ALSA: asihpi: work around clang-17+ false positive fortify-string warning) Kees Cook
2024-02-29  1:20       ` Bill Wendling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox