Re: [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup()
From: Frank Li
Date: Thu Jun 25 2026 - 08:17:31 EST
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>
> ---
Reviewed-by: Frank Li <Frank.Li@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
>
>