* [PATCH] usb: legousbtower: clear interface data on probe failure and disconnect
@ 2026-08-18 12:41 Jiawen Liu
2026-08-18 14:48 ` Johan Hovold
0 siblings, 1 reply; 2+ messages in thread
From: Jiawen Liu @ 2026-08-18 12:41 UTC (permalink / raw)
To: Juergen Stuber, Greg Kroah-Hartman, legousb-devel, linux-usb,
linux-kernel
Cc: jiawen
From: jiawen <1298662399@qq.com>
In tower_probe(), usb_set_intfdata() is called before
usb_register_dev(). If registration fails, the error path calls
tower_delete() which frees the device, but the interface data still
points to the freed memory. A subsequent disconnect would dereference
stale data.
Clear the interface data before freeing the device on the registration
failure path. Similarly, tower_disconnect() retrieves the interface data
but never clears it before possibly calling tower_delete(). Clear the
interface data before the possible tower_delete() call to avoid leaving
stale interface data after disconnect.
Signed-off-by: jiawen <1298662399@qq.com>
---
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 111111111111..222222222222 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -814,7 +814,8 @@ static int tower_probe(struct usb_interface *interface, const struct usb_device_id *id)
retval = usb_register_dev(interface, &tower_class);
if (retval) {
/* something prevented us from registering this driver */
dev_err(idev, "Not able to get a minor for this device.\n");
+ usb_set_intfdata(interface, NULL);
goto error;
}
dev->minor = interface->minor;
@@ -846,6 +847,8 @@ static void tower_disconnect(struct usb_interface *interface)
dev = usb_get_intfdata(interface);
minor = dev->minor;
+
+ usb_set_intfdata(interface, NULL);
/* give back our minor and prevent further open() */
usb_deregister_dev(interface, &tower_class);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: legousbtower: clear interface data on probe failure and disconnect
2026-08-18 12:41 [PATCH] usb: legousbtower: clear interface data on probe failure and disconnect Jiawen Liu
@ 2026-08-18 14:48 ` Johan Hovold
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2026-08-18 14:48 UTC (permalink / raw)
To: Jiawen Liu
Cc: Juergen Stuber, Greg Kroah-Hartman, legousb-devel, linux-usb,
linux-kernel
On Tue, Aug 18, 2026 at 04:41:28PM +0400, Jiawen Liu wrote:
> From: jiawen <1298662399@qq.com>
Your full name is needed here and below.
> In tower_probe(), usb_set_intfdata() is called before
> usb_register_dev(). If registration fails, the error path calls
> tower_delete() which frees the device, but the interface data still
> points to the freed memory. A subsequent disconnect would dereference
> stale data.
This makes no sense as disconnect() is not called if probe() fails.
> Clear the interface data before freeing the device on the registration
> failure path. Similarly, tower_disconnect() retrieves the interface data
> but never clears it before possibly calling tower_delete(). Clear the
> interface data before the possible tower_delete() call to avoid leaving
> stale interface data after disconnect.
That's not needed either as disconnect() will not free the driver data
until after deregistering the class device (which takes care of any
racing call to open() which accesses the driver data).
> Signed-off-by: jiawen <1298662399@qq.com>
Johan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-18 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 12:41 [PATCH] usb: legousbtower: clear interface data on probe failure and disconnect Jiawen Liu
2026-08-18 14:48 ` Johan Hovold
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.