Re: [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup()
From: Xu Yang
Date: Thu Jul 09 2026 - 02:28:07 EST
On Thu, Jul 09, 2026 at 07:33:03AM +0200, Greg KH wrote:
> On Wed, Jul 08, 2026 at 03:54:03PM -0500, Frank Li wrote:
> > On Wed, Jul 08, 2026 at 05:05:03PM +0200, Greg KH wrote:
> > > On Thu, Jun 25, 2026 at 07:31:54PM +0800, Xu Yang wrote:
> > > > From: Xu Yang <xu.yang_2@xxxxxxx>
> > > >
> > > > 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@xxxxxxxxxxxxxxx
> > > > Assisted-by: Claude:claude-sonnet-4-6
> > > > Signed-off-by: Xu Yang <xu.yang_2@xxxxxxx>
> > > > ---
> > > > 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?
> >
> > I think just no one use sys interface to change name.
>
> So it can just be removed? Please submit a patch to do that instead.
>
> Ideally this whole file can be removed, does anyone still use it?
This legacy driver is still built in kernel in multi_v7_defconfig:
~/work/usb$ grep -nr CONFIG_USB_CONFIGFS_F_UAC1_LEGACY arch/*/configs/
arch/arm/configs/multi_v7_defconfig:939:CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y
It seems we can't simply remove it.
BTW, do we have other ways to figure out if it can be removed?
Thanks,
Xu Yang