* [PATCH] i2c: tiny-usb: drop redundant device reference
@ 2026-03-05 12:54 Johan Hovold
2026-03-09 12:03 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2026-03-05 12:54 UTC (permalink / raw)
To: Till Harbaum; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold
Driver core holds a reference to the USB interface and its parent USB
device while the interface is bound to a driver and there is no need to
take additional references unless the structures are needed after
disconnect.
Drop the redundant device reference to reduce cargo culting, make it
easier to spot drivers where an extra reference is needed, and reduce
the risk of memory leaks when drivers fail to release it.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/busses/i2c-tiny-usb.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 9ef495f88ef2..88d66593d9fc 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -213,12 +213,6 @@ static int usb_write(struct i2c_adapter *adapter, int cmd,
return ret;
}
-static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
-{
- usb_put_dev(dev->usb_dev);
- kfree(dev);
-}
-
static int i2c_tiny_usb_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
@@ -237,7 +231,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
if (!dev)
goto error;
- dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
+ dev->usb_dev = interface_to_usbdev(interface);
dev->interface = interface;
/* save our data pointer in this interface device */
@@ -277,8 +271,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
return 0;
error:
- if (dev)
- i2c_tiny_usb_free(dev);
+ kfree(dev);
return retval;
}
@@ -289,7 +282,7 @@ static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
i2c_del_adapter(&dev->adapter);
usb_set_intfdata(interface, NULL);
- i2c_tiny_usb_free(dev);
+ kfree(dev);
dev_dbg(&interface->dev, "disconnected\n");
}
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] i2c: tiny-usb: drop redundant device reference
2026-03-05 12:54 [PATCH] i2c: tiny-usb: drop redundant device reference Johan Hovold
@ 2026-03-09 12:03 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2026-03-09 12:03 UTC (permalink / raw)
To: Johan Hovold; +Cc: Till Harbaum, Andi Shyti, linux-i2c, linux-kernel
On Thu, Mar 05, 2026 at 01:54:03PM +0100, Johan Hovold wrote:
> Driver core holds a reference to the USB interface and its parent USB
> device while the interface is bound to a driver and there is no need to
> take additional references unless the structures are needed after
> disconnect.
>
> Drop the redundant device reference to reduce cargo culting, make it
> easier to spot drivers where an extra reference is needed, and reduce
> the risk of memory leaks when drivers fail to release it.
>
> Signed-off-by: Johan Hovold <johan@kernel.org>
Applied to for-next, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-09 12:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05 12:54 [PATCH] i2c: tiny-usb: drop redundant device reference Johan Hovold
2026-03-09 12:03 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox