Skip to content

Commit 7ea26e6

Browse files
Abdun Nihaalgregkh
authored andcommitted
gpio: mpsse: fix reference leak in gpio_mpsse_probe() error paths
[ Upstream commit 1e876e5 ] The reference obtained by calling usb_get_dev() is not released in the gpio_mpsse_probe() error paths. Fix that by using device managed helper functions. Also remove the usb_put_dev() call in the disconnect function since now it will be released automatically. Cc: stable@vger.kernel.org Fixes: c46a74f ("gpio: add support for FTDI's MPSSE as GPIO") Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in> Link: https://lore.kernel.org/r/20251226060414.20785-1-nihaal@cse.iitm.ac.in Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7882637 commit 7ea26e6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

drivers/gpio/gpio-mpsse.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ static void gpio_mpsse_ida_remove(void *data)
538538
ida_free(&gpio_mpsse_ida, priv->id);
539539
}
540540

541+
static void gpio_mpsse_usb_put_dev(void *data)
542+
{
543+
struct mpsse_priv *priv = data;
544+
545+
usb_put_dev(priv->udev);
546+
}
547+
541548
static int mpsse_init_valid_mask(struct gpio_chip *chip,
542549
unsigned long *valid_mask,
543550
unsigned int ngpios)
@@ -582,6 +589,10 @@ static int gpio_mpsse_probe(struct usb_interface *interface,
582589
INIT_LIST_HEAD(&priv->workers);
583590

584591
priv->udev = usb_get_dev(interface_to_usbdev(interface));
592+
err = devm_add_action_or_reset(dev, gpio_mpsse_usb_put_dev, priv);
593+
if (err)
594+
return err;
595+
585596
priv->intf = interface;
586597
priv->intf_id = interface->cur_altsetting->desc.bInterfaceNumber;
587598

@@ -703,7 +714,6 @@ static void gpio_mpsse_disconnect(struct usb_interface *intf)
703714

704715
priv->intf = NULL;
705716
usb_set_intfdata(intf, NULL);
706-
usb_put_dev(priv->udev);
707717
}
708718

709719
static struct usb_driver gpio_mpsse_driver = {

0 commit comments

Comments
 (0)