public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Wei Peng <coderlogicwei@gmail.com>
To: syzbot <syzbot+30b78308ba7e64647ff8@syzkaller.appspotmail.com>
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org
Subject: Re: [syzbot] [usb?] INFO: task hung in i2c_tiny_usb_disconnect
Date: Mon, 12 Jan 2026 21:38:55 +0800	[thread overview]
Message-ID: <1d3ebfdb-2c12-4388-99bc-3cbcc11eea79@gmail.com> (raw)
In-Reply-To: <6963d09e.050a0220.eaf7.0070.GAE@google.com>

#syz test

diff --git a/drivers/i2c/busses/i2c-tiny-usb.c 
b/drivers/i2c/busses/i2c-tiny-usb.c
index 57dfe5f1a7d9..79b7c97514c9 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,8 @@ 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 */
  };

  static int usb_read(struct i2c_adapter *adapter, int cmd,
@@ -184,6 +187,11 @@ static int usb_read(struct i2c_adapter *adapter, 
int cmd,
      if (!dmadata)
          return -ENOMEM;

+    if (READ_ONCE(dev->disconnected)) {
+        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 |
@@ -204,6 +212,11 @@ static int usb_write(struct i2c_adapter *adapter, 
int cmd,
      if (!dmadata)
          return -ENOMEM;

+    if (READ_ONCE(dev->disconnected)) {
+        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,
@@ -219,6 +232,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)
  {
@@ -268,6 +290,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 +311,9 @@ static void i2c_tiny_usb_disconnect(struct 
usb_interface *interface)
  {
      struct i2c_tiny_usb *dev = usb_get_intfdata(interface);

-    i2c_del_adapter(&dev->adapter);
      usb_set_intfdata(interface, NULL);
-    i2c_tiny_usb_free(dev);
+    WRITE_ONCE(dev->disconnected, true);
+    queue_work(system_long_wq, &dev->release_work);

      dev_dbg(&interface->dev, "disconnected\n");
  }


  parent reply	other threads:[~2026-01-12 13:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6963d09e.050a0220.eaf7.0070.GAE@google.com>
2026-01-12 13:11 ` [syzbot] [usb?] INFO: task hung in i2c_tiny_usb_disconnect Wei Peng
2026-01-12 13:24   ` syzbot
2026-01-12 13:31 ` Wei Peng
2026-01-12 13:38 ` Wei Peng [this message]
2026-01-12 13:41   ` syzbot
     [not found] <8bed5082-0aef-4dee-8239-c3e8aba50f9f@suse.com>
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=1d3ebfdb-2c12-4388-99bc-3cbcc11eea79@gmail.com \
    --to=coderlogicwei@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+30b78308ba7e64647ff8@syzkaller.appspotmail.com \
    /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