From: Benjamin Tissoires <benjamin.tissoi...@redhat.com>

The sysfs group was indeed removed by kobject_put(wacom->remote_dir) in
wacom_remove(), but the name of the group was never freed.

Also remove the misplaced kobject_put(wacom->remote_dir) in the error
path of wacom_remote_create_attr_group().

Signed-off-by: Benjamin Tissoires <benjamin.tissoi...@redhat.com>
Acked-by: Ping Cheng <pi...@wacom.com>
Signed-off-by: Jiri Kosina <jkos...@suse.cz>
[aaron.sko...@wacom.com: Imported into input-wacom repository (c1f5409)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
[aaron.sko...@wacom.com: Backported from input-wacom repository (0f1b043)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
---
 2.6.38/wacom_sys.c |  8 +++++++-
 3.17/wacom_sys.c   | 14 ++++++--------
 3.7/wacom_sys.c    |  8 +++++++-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/2.6.38/wacom_sys.c b/2.6.38/wacom_sys.c
index a41104e..0c70faf 100644
--- a/2.6.38/wacom_sys.c
+++ b/2.6.38/wacom_sys.c
@@ -1291,7 +1291,6 @@ int wacom_remote_create_attr_group(struct wacom *wacom, 
__u32 serial, int index)
        if (error) {
                dev_err(&wacom->intf->dev,
                        "cannot create sysfs group err: %d\n", error);
-               kobject_put(wacom->remote_dir);
                return error;
        }
 
@@ -1751,12 +1750,19 @@ static int wacom_probe(struct usb_interface *intf, 
const struct usb_device_id *i
 static void wacom_disconnect(struct usb_interface *intf)
 {
        struct wacom *wacom = usb_get_intfdata(intf);
+       int i;
 
        usb_set_intfdata(intf, NULL);
 
        usb_kill_urb(wacom->irq);
        cancel_work_sync(&wacom->wireless_work);
        cancel_work_sync(&wacom->battery_work);
+       for (i = 0; i < WACOM_MAX_REMOTES; i++) {
+               if (wacom->remote_group[i].name) {
+                       wacom_remote_destroy_attr_group(wacom,
+                                               wacom->wacom_wac.serial[i]);
+               }
+       }
        kobject_put(wacom->remote_dir);
        wacom_unregister_inputs(wacom);
        wacom_destroy_battery(wacom);
diff --git a/3.17/wacom_sys.c b/3.17/wacom_sys.c
index f4e1fd9..6afa06d 100644
--- a/3.17/wacom_sys.c
+++ b/3.17/wacom_sys.c
@@ -25,7 +25,6 @@
 #define WAC_CMD_RETRIES                10
 #define WAC_CMD_DELETE_PAIRING 0x20
 #define WAC_CMD_UNPAIR_ALL     0xFF
-#define WAC_REMOTE_SERIAL_MAX_STRLEN   9
 
 #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
 #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
@@ -1273,23 +1272,21 @@ DEVICE_EKR_ATTR_GROUP(4);
 int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int 
index)
 {
        int error = 0;
-       char *buf;
        struct wacom_wac *wacom_wac = &wacom->wacom_wac;
 
        wacom_wac->serial[index] = serial;
 
-       buf = kzalloc(WAC_REMOTE_SERIAL_MAX_STRLEN, GFP_KERNEL);
-       if (!buf)
+       wacom->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev,
+                                                        GFP_KERNEL,
+                                                        "%d", serial);
+       if (!wacom->remote_group[index].name)
                return -ENOMEM;
-       snprintf(buf, WAC_REMOTE_SERIAL_MAX_STRLEN, "%d", serial);
-       wacom->remote_group[index].name = buf;
 
        error = sysfs_create_group(wacom->remote_dir,
                                   &wacom->remote_group[index]);
        if (error) {
                hid_err(wacom->hdev,
                        "cannot create sysfs group err: %d\n", error);
-               kobject_put(wacom->remote_dir);
                return error;
        }
 
@@ -1311,7 +1308,8 @@ void wacom_remote_destroy_attr_group(struct wacom *wacom, 
__u32 serial)
                        if (wacom->remote_group[i].name) {
                                sysfs_remove_group(wacom->remote_dir,
                                                   &wacom->remote_group[i]);
-                               kfree(wacom->remote_group[i].name);
+                               devm_kfree(&wacom->hdev->dev,
+                                          (char *)wacom->remote_group[i].name);
                                wacom->remote_group[i].name = NULL;
                        }
                }
diff --git a/3.7/wacom_sys.c b/3.7/wacom_sys.c
index 7948ab8..b3273f3 100644
--- a/3.7/wacom_sys.c
+++ b/3.7/wacom_sys.c
@@ -1284,7 +1284,6 @@ int wacom_remote_create_attr_group(struct wacom *wacom, 
__u32 serial, int index)
        if (error) {
                dev_err(&wacom->intf->dev,
                        "cannot create sysfs group err: %d\n", error);
-               kobject_put(wacom->remote_dir);
                return error;
        }
 
@@ -1747,12 +1746,19 @@ static int wacom_probe(struct usb_interface *intf, 
const struct usb_device_id *i
 static void wacom_disconnect(struct usb_interface *intf)
 {
        struct wacom *wacom = usb_get_intfdata(intf);
+       int i;
 
        usb_set_intfdata(intf, NULL);
 
        usb_kill_urb(wacom->irq);
        cancel_work_sync(&wacom->wireless_work);
        cancel_work_sync(&wacom->battery_work);
+       for (i = 0; i < WACOM_MAX_REMOTES; i++) {
+               if (wacom->remote_group[i].name) {
+                       wacom_remote_destroy_attr_group(wacom,
+                                               wacom->wacom_wac.serial[i]);
+               }
+       }
        kobject_put(wacom->remote_dir);
        wacom_unregister_inputs(wacom);
        wacom_destroy_battery(wacom);
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to