The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup()
@ 2026-06-25 11:31 Xu Yang
  2026-06-25 12:15 ` Frank Li
  2026-07-08 15:05 ` Greg KH
  0 siblings, 2 replies; 9+ messages in thread
From: Xu Yang @ 2026-06-25 11:31 UTC (permalink / raw)
  To: gregkh, kees, christophe.jaillet, xu.yang_2, hataegu0826
  Cc: balbi, andrzej.p, linux-usb, linux-kernel, imx

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-07-10 12:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 11:31 [PATCH] usb: gadget: f_uac1_legacy: fix inverted NULL check after kstrndup() Xu Yang
2026-06-25 12:15 ` Frank Li
2026-07-08 15:05 ` Greg KH
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox