Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: stable@vger.kernel.org
Fixes: c46a74ff05c0 ("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>

authored by

Abdun Nihaal and committed by
Bartosz Golaszewski
1e876e5a 014a17de

+11 -1
+11 -1
drivers/gpio/gpio-mpsse.c
··· 548 548 ida_free(&gpio_mpsse_ida, priv->id); 549 549 } 550 550 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 + 551 558 static int mpsse_init_valid_mask(struct gpio_chip *chip, 552 559 unsigned long *valid_mask, 553 560 unsigned int ngpios) ··· 599 592 INIT_LIST_HEAD(&priv->workers); 600 593 601 594 priv->udev = usb_get_dev(interface_to_usbdev(interface)); 595 + err = devm_add_action_or_reset(dev, gpio_mpsse_usb_put_dev, priv); 596 + if (err) 597 + return err; 598 + 602 599 priv->intf = interface; 603 600 priv->intf_id = interface->cur_altsetting->desc.bInterfaceNumber; 604 601 ··· 724 713 725 714 priv->intf = NULL; 726 715 usb_set_intfdata(intf, NULL); 727 - usb_put_dev(priv->udev); 728 716 } 729 717 730 718 static struct usb_driver gpio_mpsse_driver = {