gpio: sysfs: fix memory leak in gpiod_export_link
authorJohan Hovold <johan@kernel.org>
Mon, 26 Jan 2015 11:02:45 +0000 (12:02 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 6 Mar 2015 00:39:18 +0000 (00:39 +0000)
commit 0f303db08df0df9bd0966443ad6001e63960af16 upstream.

Fix memory leak in the gpio sysfs interface due to failure to drop
reference to device returned by class_find_device when creating a link.

Fixes: a4177ee7f1a8 ("gpiolib: allow exported GPIO nodes to be named
using sysfs links")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
[bwh: Backported to 3.2: adjust filename]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/gpio/gpiolib.c

index 51e5ee8..72ebde4 100644 (file)
@@ -821,6 +821,7 @@ int gpio_export_link(struct device *dev, const char *name, unsigned gpio)
                if (tdev != NULL) {
                        status = sysfs_create_link(&dev->kobj, &tdev->kobj,
                                                name);
                if (tdev != NULL) {
                        status = sysfs_create_link(&dev->kobj, &tdev->kobj,
                                                name);
+                       put_device(tdev);
                } else {
                        status = -ENODEV;
                }
                } else {
                        status = -ENODEV;
                }