Skip to content

Commit 1e876e5

Browse files
Abdun NihaalBartosz Golaszewski
authored andcommitted
gpio: mpsse: fix reference leak in gpio_mpsse_probe() error paths
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: [email protected] Fixes: c46a74f ("gpio: add support for FTDI's MPSSE as GPIO") Signed-off-by: Abdun Nihaal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 014a17d commit 1e876e5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/gpio/gpio-mpsse.c

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

551+
static void gpio_mpsse_usb_put_dev(void *data)
552+
{
553+
struct mpsse_priv *priv = data;
554+
555+
usb_put_dev(priv->udev);
556+
}
557+
551558
static int mpsse_init_valid_mask(struct gpio_chip *chip,
552559
unsigned long *valid_mask,
553560
unsigned int ngpios)
@@ -592,6 +599,10 @@ static int gpio_mpsse_probe(struct usb_interface *interface,
592599
INIT_LIST_HEAD(&priv->workers);
593600

594601
priv->udev = usb_get_dev(interface_to_usbdev(interface));
602+
err = devm_add_action_or_reset(dev, gpio_mpsse_usb_put_dev, priv);
603+
if (err)
604+
return err;
605+
595606
priv->intf = interface;
596607
priv->intf_id = interface->cur_altsetting->desc.bInterfaceNumber;
597608

@@ -713,7 +724,6 @@ static void gpio_mpsse_disconnect(struct usb_interface *intf)
713724

714725
priv->intf = NULL;
715726
usb_set_intfdata(intf, NULL);
716-
usb_put_dev(priv->udev);
717727
}
718728

719729
static struct usb_driver gpio_mpsse_driver = {

0 commit comments

Comments
 (0)