From: Greg KH <gregkh@linuxfoundation.org>
To: DongliLiu <dongli.liu@outlook.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: typec: ucsi: Add bounds check for enum array index
Date: Tue, 30 Jun 2026 16:17:57 +0200 [thread overview]
Message-ID: <2026063045-glacial-rifling-8211@gregkh> (raw)
In-Reply-To: <KUZPR04MB896814FEFE2D859FE194F45585F72@KUZPR04MB8968.apcprd04.prod.outlook.com>
On Tue, Jun 30, 2026 at 07:31:29PM +0800, DongliLiu wrote:
> From: DongliLiu <dongli.liu@outlook.com>
> Date: Mon, 30 Jun 2026 19:30:00 +0800
> Subject: [PATCH] usb: typec: ucsi: Add bounds check for enum array index
>
> The 'sop' parameter is a C enum that can hold any integer value, not
> just the defined enum constants. Using it directly as an array index
> without bounds checking can lead to undefined behavior if an out-of-range
> value is passed.
>
> Add an explicit ARRAY_SIZE() check before accessing altmode->plug[sop]
> to ensure the index is within bounds.
>
> Signed-off-by: DongliLiu <dongli.liu@outlook.com>
> ---
> drivers/usb/typec/ucsi/ucsi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index xxxxxxx..yyyyyyy 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -xxx,yyy @@@ static void some_function(struct typec_altmode *altmode,
> enum typec_plug_role sop)
> ...
>
> - if (!altmode->plug[sop])
> + if (sop >= ARRAY_SIZE(altmode->plug) || !altmode->plug[sop])
> ...
> --
> 2.40.0
Same here, stop making fake patches.
prev parent reply other threads:[~2026-06-30 14:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 11:31 [PATCH] usb: typec: ucsi: Add bounds check for enum array index DongliLiu
2026-06-30 14:17 ` Greg KH [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=2026063045-glacial-rifling-8211@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=dongli.liu@outlook.com \
--cc=linux-usb@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox