Re: [PATCH] usb: legousbtower: clear interface data on probe failure and disconnect
From: Johan Hovold
Date: Tue Aug 18 2026 - 10:48:30 EST
On Tue, Aug 18, 2026 at 04:41:28PM +0400, Jiawen Liu wrote:
> From: jiawen <1298662399@xxxxxx>
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@xxxxxx>
Johan