All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michał Nazarewicz" <mina86@mina86.com>
To: Sasha Levin <sashal@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sasha Levin <sashal@kernel.org>
Subject: Re: [PATCH v2] tools: usb: ffs-test: read the descriptor counts with unaligned accesses
Date: Tue, 13 Oct 2026 04:14:36 +0200	[thread overview]
Message-ID: <10ibi+um8lcsadwjotc6p04h@mina86.com> (raw)
In-Reply-To: <20261011234707.2475490-1-sashal@kernel.org>

On Sun, Oct 11 2026, Sasha Levin wrote:
> 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>

Acked-by: Michał Nazarewicz <mina86@mina86.com>

> ---
> Changes in v2:
> - Take the byte pointer from in->counts instead of computing it from
>   descriptors_v2 (Michał Nazarewicz)
> - Link to v1: https://lore.kernel.org/r/20261011223445.2328181-1-sashal@kernel.org
>
>  tools/usb/ffs-test.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
> index 22b938fbdfb77..4453d810e9412 100644
> --- a/tools/usb/ffs-test.c
> +++ b/tools/usb/ffs-test.c
> @@ -232,7 +232,7 @@ 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 void *)in->counts;
>  		__u32 flags;
>  
>  		if (le32_to_cpu(in->header.magic) !=
> @@ -252,9 +252,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);

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴィツ
«If at first you don’t succeed, give up skydiving»

      parent reply	other threads:[~2026-10-13  2:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-11 22:34 [PATCH] tools: usb: ffs-test: read the descriptor counts with unaligned accesses Sasha Levin
2026-10-11 22:41 ` sashiko-bot
2026-10-11 23:09 ` Michał Nazarewicz
2026-10-11 23:47   ` [PATCH v2] " Sasha Levin
2026-10-11 23:54     ` sashiko-bot
2026-10-13  2:14     ` Michał Nazarewicz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10ibi+um8lcsadwjotc6p04h@mina86.com \
    --to=mina86@mina86.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashal@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.