gpio_mpsse_disconnect() clears priv->intf and the interface drvdata, but the GPIO callbacks keep dereferencing priv->intf. A line request issued while the device is being unplugged reaches gpio_mpsse_set_bank() after priv->intf has been cleared, and mpsse_bulk_xfer() calls usb_get_intfdata(NULL), which faults on &intf->dev.driver_data. Return -ENODEV when the interface or its drvdata is gone, and check the same before mpsse_read() dereferences the private data. This covers both the direction input and direction output paths. Fixes: c46a74ff05c0 ("gpio: add support for FTDI's MPSSE as GPIO") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- drivers/gpio/gpio-mpsse.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-mpsse.c b/drivers/gpio/gpio-mpsse.c index 61c5ca96314b..ae1a97645214 100644 --- a/drivers/gpio/gpio-mpsse.c +++ b/drivers/gpio/gpio-mpsse.c @@ -105,11 +105,20 @@ static DEFINE_IDA(gpio_mpsse_ida); static int mpsse_bulk_xfer(struct usb_interface *intf, struct bulk_desc *desc) { - struct mpsse_priv *priv = usb_get_intfdata(intf); - struct usb_device *udev = priv->udev; + struct mpsse_priv *priv; + struct usb_device *udev; unsigned int pipe; int ret; + if (!intf) + return -ENODEV; + + priv = usb_get_intfdata(intf); + if (!priv) + return -ENODEV; + + udev = priv->udev; + if (desc->tx) pipe = usb_sndbulkpipe(udev, priv->bulk_out->bEndpointAddress); else @@ -144,7 +153,14 @@ static int mpsse_read(struct usb_interface *intf, u8 *buf, size_t len) { int ret; struct bulk_desc desc; - struct mpsse_priv *priv = usb_get_intfdata(intf); + struct mpsse_priv *priv; + + if (!intf) + return -ENODEV; + + priv = usb_get_intfdata(intf); + if (!priv) + return -ENODEV; desc.len_actual = 0; desc.tx = false; -- 2.34.1