Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Xu Yang <xu.yang_2@oss.nxp.com>
Cc: kees@kernel.org, christophe.jaillet@wanadoo.fr,
	xu.yang_2@nxp.com, hataegu0826@gmail.com, balbi@ti.com,
	andrzej.p@samsung.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup()
Date: Wed, 8 Jul 2026 17:05:03 +0200	[thread overview]
Message-ID: <2026070831-peso-aluminum-df0c@gregkh> (raw)
In-Reply-To: <20260625113154.1954813-1-xu.yang_2@oss.nxp.com>

On Thu, Jun 25, 2026 at 07:31:54PM +0800, Xu Yang wrote:
> From: Xu Yang <xu.yang_2@nxp.com>
> 
> kstrndup() returns NULL on allocation failure. The condition was
> checking 'if (tmp)' to detect failure, but this is inverted — it
> would treat a successful allocation as an error and return -ENOMEM
> while leaking the string, and proceed with a NULL pointer on failure.
> 
> Fix by changing the condition to 'if (!tmp)'.
> 
> Fixes: 0854611a19ae ("usb: gadget: f_uac1: add configfs support")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-sonnet-4-6
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/gadget/function/f_uac1_legacy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c
> index 5d201a2e30e7..e9f2632ce785 100644
> --- a/drivers/usb/gadget/function/f_uac1_legacy.c
> +++ b/drivers/usb/gadget/function/f_uac1_legacy.c
> @@ -914,7 +914,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item,	\
>  		goto end;						\
>  									\
>  	tmp = kstrndup(page, len, GFP_KERNEL);				\
> -	if (tmp) {							\
> +	if (!tmp) {							\
>  		ret = -ENOMEM;						\
>  		goto end;						\
>  	}								\
> -- 
> 2.34.1
> 
> 

So this has never worked?  How has no one ever noticed that in the
decade this has been in the kernel?  Does that mean that no one uses
this file/driver and we can just remove it?

thanks,

greg k-h

  parent reply	other threads:[~2026-07-08 15:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 11:31 [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup() Xu Yang
2026-06-25 11:40 ` sashiko-bot
2026-06-25 12:15 ` Frank Li
2026-07-08 15:05 ` Greg KH [this message]
2026-07-08 20:54   ` Frank Li
2026-07-09  5:33     ` Greg KH
2026-07-09  6:23       ` Xu Yang
2026-07-09  6:48         ` Greg KH
2026-07-10 12:58           ` Greg KH
2026-07-09 16:39     ` David Laight

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=2026070831-peso-aluminum-df0c@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=hataegu0826@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=xu.yang_2@nxp.com \
    --cc=xu.yang_2@oss.nxp.com \
    /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