mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools: usb: ffs-test: read the descriptor counts with unaligned accesses
@ 2026-10-11 22:34 Sasha Levin
  2026-10-11 23:09 ` Michał Nazarewicz
  0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-10-11 22:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, Michal Nazarewicz, linux-kernel, Sasha Levin

descs_to_legacy() reads the descriptor counts through a __le32 pointer
taken from a member of a packed struct, which may be unaligned:

  ffs-test.c:235:40: warning: taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value [-Waddress-of-packed-member]

Walk the counts with a byte pointer and get_unaligned_le32().

Fixes: b9a4274699c69 ("tools: ffs-test: add compatibility code for old kernels")
Assisted-by: LLM
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 tools/usb/ffs-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index 22b938fbdfb77..f08060459b3f1 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -232,7 +232,8 @@ static size_t descs_to_legacy(void **legacy, const void *descriptors_v2)
 			const struct usb_functionfs_descs_head_v2 header;
 			const __le32 counts[];
 		} __attribute__((packed)) *const in = descriptors_v2;
-		const __le32 *counts = in->counts;
+		const unsigned char *counts =
+			(const unsigned char *)descriptors_v2 + sizeof(in->header);
 		__u32 flags;
 
 		if (le32_to_cpu(in->header.magic) !=
@@ -252,9 +253,9 @@ static size_t descs_to_legacy(void **legacy, const void *descriptors_v2)
 				break;			\
 			if (length < 4)			\
 				return 0;		\
-			ret = le32_to_cpu(*counts);	\
+			ret = get_unaligned_le32(counts); \
 			length -= 4;			\
-			++counts;			\
+			counts += 4;			\
 		} while (0)
 
 		GET_NEXT_COUNT_IF_FLAG(fs_count, FUNCTIONFS_HAS_FS_DESC);
-- 
2.53.0


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

end of thread, other threads:[~2026-10-11 23:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11 22:34 [PATCH] tools: usb: ffs-test: read the descriptor counts with unaligned accesses Sasha Levin
2026-10-11 23:09 ` Michał Nazarewicz
2026-10-11 23:47   ` [PATCH v2] " Sasha Levin

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

all inboxes | Powered by JetHome®