public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: weipeng <coderlogicwei@gmail.com>
To: syzbot+30b78308ba7e64647ff8@syzkaller.appspotmail.com, oneukum@suse.com
Cc: anna-maria@linutronix.de, frederic@kernel.org,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	syzkaller-bugs@googlegroups.com, tglx@linutronix.de
Subject: Re: [syzbot] [usb?] INFO: task hung in i2c_tiny_usb_disconnect
Date: Tue, 13 Jan 2026 23:45:30 +0800	[thread overview]
Message-ID: <20260113154530.340123-1-coderlogicwei@gmail.com> (raw)
In-Reply-To: <6963d09e.050a0220.eaf7.0070.GAE@google.com>

diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 57dfe5f1a7d9..30679c2b787b 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/string_choices.h>
 #include <linux/types.h>
+#include <linux/workqueue.h>
 
 /* include interfaces to usb layer */
 #include <linux/usb.h>
@@ -172,6 +173,9 @@ struct i2c_tiny_usb {
 	struct usb_device *usb_dev; /* the usb device for this device */
 	struct usb_interface *interface; /* the interface for this device */
 	struct i2c_adapter adapter; /* i2c related things */
+	bool disconnected; /* set to true on disconnect */
+	struct work_struct release_work; /* work struct to release the adapter */
+	struct mutex usb_lock; /* lock for usb operations */
 };
 
 static int usb_read(struct i2c_adapter *adapter, int cmd,
@@ -184,11 +188,20 @@ static int usb_read(struct i2c_adapter *adapter, int cmd,
 	if (!dmadata)
 		return -ENOMEM;
 
+	mutex_lock(&dev->usb_lock);
+	if (dev->disconnected) {
+		mutex_unlock(&dev->usb_lock);
+		kfree(dmadata);
+		return -ENODEV;
+	}
+
 	/* do control transfer */
 	ret = usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0),
 			       cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE |
 			       USB_DIR_IN, value, index, dmadata, len, 2000);
 
+	mutex_unlock(&dev->usb_lock);
+
 	memcpy(data, dmadata, len);
 	kfree(dmadata);
 	return ret;
@@ -204,11 +217,20 @@ static int usb_write(struct i2c_adapter *adapter, int cmd,
 	if (!dmadata)
 		return -ENOMEM;
 
+	mutex_lock(&dev->usb_lock);
+	if (dev->disconnected) {
+		mutex_unlock(&dev->usb_lock);
+		kfree(dmadata);
+		return -ENODEV;
+	}
+
 	/* do control transfer */
 	ret = usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0),
 			       cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 			       value, index, dmadata, len, 2000);
 
+	mutex_unlock(&dev->usb_lock);
+
 	kfree(dmadata);
 	return ret;
 }
@@ -219,6 +241,15 @@ static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
 	kfree(dev);
 }
 
+static void i2c_tiny_usb_release(struct work_struct *work)
+{
+	struct i2c_tiny_usb *dev = container_of(work, struct i2c_tiny_usb,
+					       release_work);
+
+	i2c_del_adapter(&dev->adapter);
+	i2c_tiny_usb_free(dev);
+}
+
 static int i2c_tiny_usb_probe(struct usb_interface *interface,
 			      const struct usb_device_id *id)
 {
@@ -239,6 +270,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
 
 	dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
 	dev->interface = interface;
+	mutex_init(&dev->usb_lock);
 
 	/* save our data pointer in this interface device */
 	usb_set_intfdata(interface, dev);
@@ -268,6 +300,8 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
 
 	dev->adapter.dev.parent = &dev->interface->dev;
 
+	INIT_WORK(&dev->release_work, i2c_tiny_usb_release);
+
 	/* and finally attach to i2c layer */
 	i2c_add_adapter(&dev->adapter);
 
@@ -287,9 +321,12 @@ static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
 {
 	struct i2c_tiny_usb *dev = usb_get_intfdata(interface);
 
-	i2c_del_adapter(&dev->adapter);
+	mutex_lock(&dev->usb_lock);
 	usb_set_intfdata(interface, NULL);
-	i2c_tiny_usb_free(dev);
+	dev->disconnected = true;
+	mutex_unlock(&dev->usb_lock);
+
+	queue_work(system_long_wq, &dev->release_work);
 
 	dev_dbg(&interface->dev, "disconnected\n");
 }

  parent reply	other threads:[~2026-01-13 15:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 16:32 [syzbot] [usb?] INFO: task hung in i2c_tiny_usb_disconnect syzbot
2026-01-12 13:11 ` Wei Peng
2026-01-12 13:24   ` syzbot
2026-01-12 13:31 ` Wei Peng
2026-01-12 13:38 ` Wei Peng
2026-01-12 13:41   ` syzbot
2026-01-13  3:11 ` weipeng
2026-01-13  4:22   ` syzbot
2026-01-13  6:25 ` weipeng
2026-01-13  7:28   ` syzbot
2026-01-13  7:52 ` weipeng
2026-01-13  8:35   ` syzbot
2026-01-13  9:49   ` Oliver Neukum
2026-01-13 15:35     ` weipeng
2026-01-13 15:45 ` weipeng [this message]
2026-01-13 15:47 ` weipeng
2026-01-13 16:18   ` syzbot
2026-01-13 20:23   ` Oliver Neukum
2026-01-14  8:11     ` weipeng
2026-01-14  8:26       ` Oliver Neukum
2026-01-14  8:51         ` weipeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260113154530.340123-1-coderlogicwei@gmail.com \
    --to=coderlogicwei@gmail.com \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=syzbot+30b78308ba7e64647ff8@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox