From: Benjamin Tissoires <benjamin.tissoi...@redhat.com> The wacom_remote_create_attr_group() and wacom_remote_destroy_attr_group() functions were both allocating/destroying the sysfs groups but also initializing the parameters for the remotes. Have proper functions that can be called and extended.
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 (04bfa27)] Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com> [aaron.sko...@wacom.com: Backported from input-wacom repository (d1be8d4)] Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com> --- 2.6.38/wacom_sys.c | 96 ++++++++++++++++++++++++++++++------------------------ 3.17/wacom_sys.c | 93 +++++++++++++++++++++++++++++----------------------- 3.7/wacom_sys.c | 96 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 161 insertions(+), 124 deletions(-) diff --git a/2.6.38/wacom_sys.c b/2.6.38/wacom_sys.c index 303814b..85f08f2 100644 --- a/2.6.38/wacom_sys.c +++ b/2.6.38/wacom_sys.c @@ -1277,8 +1277,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int int error = 0; struct wacom_remote *remote = wacom->remote; - remote->serial[index] = serial; - remote->remote_group[index].name = kasprintf(GFP_KERNEL, "%d", serial); if (!remote->remote_group[index].name) return -ENOMEM; @@ -1295,26 +1293,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int return 0; } -static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) +static void wacom_remote_destroy_attr_group(struct wacom *wacom, int i) { struct wacom_remote *remote = wacom->remote; - int i; - if (!serial) - return; - - for (i = 0; i < WACOM_MAX_REMOTES; i++) { - if (remote->serial[i] == serial) { - remote->serial[i] = 0; - wacom->led.select[i] = WACOM_STATUS_UNKNOWN; - if (remote->remote_group[i].name) { - sysfs_remove_group(remote->remote_dir, - &remote->remote_group[i]); - kfree((char *)remote->remote_group[i].name); - remote->remote_group[i].name = NULL; - } - } - } + sysfs_remove_group(remote->remote_dir, &remote->remote_group[i]); + kfree((char *)remote->remote_group[i].name); + remote->remote_group[i].name = NULL; } static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) @@ -1338,6 +1323,50 @@ static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) return retval; } +static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + u32 serial = remote->serial[index]; + int i; + + wacom_remote_destroy_attr_group(wacom, index); + + for (i = 0; i < WACOM_MAX_REMOTES; i++) { + if (remote->serial[i] == serial) { + remote->serial[i] = 0; + wacom->led.select[i] = WACOM_STATUS_UNKNOWN; + } + } +} + +static int wacom_remote_create_one(struct wacom *wacom, u32 serial, + unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + int error, k; + + /* A remote can pair more than once with an EKR, + * check to make sure this serial isn't already paired. + */ + for (k = 0; k < WACOM_MAX_REMOTES; k++) { + if (remote->serial[k] == serial) + break; + } + + if (k < WACOM_MAX_REMOTES) { + remote->serial[index] = serial; + return 0; + } + + error = wacom_remote_create_attr_group(wacom, serial, index); + if (error) + return error; + + remote->serial[index] = serial; + + return 0; +} + static ssize_t wacom_store_unpair_remote(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) @@ -1384,8 +1413,7 @@ static void wacom_remotes_destroy(void *data) for (i = 0; i < WACOM_MAX_REMOTES; i++) { if (wacom->remote->remote_group[i].name) { - wacom_remote_destroy_attr_group(wacom, - wacom->wacom_wac.serial[i]); + wacom_remote_destroy_one(wacom, i); } } kobject_put(remote->remote_dir); @@ -1658,7 +1686,7 @@ static void wacom_remote_work(struct work_struct *work) unsigned long flags; unsigned int count; u32 serial; - int i, k; + int i; spin_lock_irqsave(&remote->remote_lock, flags); @@ -1683,28 +1711,13 @@ static void wacom_remote_work(struct work_struct *work) if (remote->serial[i] == serial) continue; - if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); - } - - /* A remote can pair more than once with an EKR, - * check to make sure this serial isn't already paired. - */ - for (k = 0; k < WACOM_MAX_REMOTES; k++) { - if (remote->serial[k] == serial) - break; - } + if (remote->serial[i]) + wacom_remote_destroy_one(wacom, i); - if (k < WACOM_MAX_REMOTES) { - remote->serial[i] = serial; - continue; - } - wacom_remote_create_attr_group(wacom, serial, i); + wacom_remote_create_one(wacom, serial, i); } else if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); + wacom_remote_destroy_one(wacom, i); } } } @@ -1855,7 +1868,6 @@ static void wacom_disconnect(struct usb_interface *intf) cancel_work_sync(&wacom->wireless_work); cancel_work_sync(&wacom->battery_work); cancel_work_sync(&wacom->remote_work); - wacom_remotes_destroy(wacom); wacom_unregister_inputs(wacom); wacom_destroy_battery(wacom); diff --git a/3.17/wacom_sys.c b/3.17/wacom_sys.c index 2dcd873..4c5c76b 100644 --- a/3.17/wacom_sys.c +++ b/3.17/wacom_sys.c @@ -1352,8 +1352,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int error = 0; struct wacom_remote *remote = wacom->remote; - remote->serial[index] = serial; - remote->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev, GFP_KERNEL, "%d", serial); @@ -1371,27 +1369,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, return 0; } -static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) +static void wacom_remote_destroy_attr_group(struct wacom *wacom, unsigned int i) { struct wacom_remote *remote = wacom->remote; - int i; - if (!serial) - return; - - for (i = 0; i < WACOM_MAX_REMOTES; i++) { - if (remote->serial[i] == serial) { - remote->serial[i] = 0; - wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; - if (remote->remote_group[i].name) { - sysfs_remove_group(remote->remote_dir, - &remote->remote_group[i]); - devm_kfree(&wacom->hdev->dev, - (char *)remote->remote_group[i].name); - remote->remote_group[i].name = NULL; - } - } - } + sysfs_remove_group(remote->remote_dir, &remote->remote_group[i]); + devm_kfree(&wacom->hdev->dev, (char *)remote->remote_group[i].name); + remote->remote_group[i].name = NULL; } static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) @@ -1987,6 +1971,50 @@ fail: return; } +static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + u32 serial = remote->serial[index]; + int i; + + wacom_remote_destroy_attr_group(wacom, index); + + for (i = 0; i < WACOM_MAX_REMOTES; i++) { + if (remote->serial[i] == serial) { + remote->serial[i] = 0; + wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; + } + } +} + +static int wacom_remote_create_one(struct wacom *wacom, u32 serial, + unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + int error, k; + + /* A remote can pair more than once with an EKR, + * check to make sure this serial isn't already paired. + */ + for (k = 0; k < WACOM_MAX_REMOTES; k++) { + if (remote->serial[k] == serial) + break; + } + + if (k < WACOM_MAX_REMOTES) { + remote->serial[index] = serial; + return 0; + } + + error = wacom_remote_create_attr_group(wacom, serial, index); + if (error) + return error; + + remote->serial[index] = serial; + + return 0; +} + static void wacom_remote_work(struct work_struct *work) { struct wacom *wacom = container_of(work, struct wacom, remote_work); @@ -1995,7 +2023,7 @@ static void wacom_remote_work(struct work_struct *work) unsigned long flags; unsigned int count; u32 serial; - int i, k; + int i; spin_lock_irqsave(&remote->remote_lock, flags); @@ -2020,28 +2048,13 @@ static void wacom_remote_work(struct work_struct *work) if (remote->serial[i] == serial) continue; - if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); - } - - /* A remote can pair more than once with an EKR, - * check to make sure this serial isn't already paired. - */ - for (k = 0; k < WACOM_MAX_REMOTES; k++) { - if (remote->serial[k] == serial) - break; - } + if (remote->serial[i]) + wacom_remote_destroy_one(wacom, i); - if (k < WACOM_MAX_REMOTES) { - remote->serial[i] = serial; - continue; - } - wacom_remote_create_attr_group(wacom, serial, i); + wacom_remote_create_one(wacom, serial, i); } else if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); + wacom_remote_destroy_one(wacom, i); } } } diff --git a/3.7/wacom_sys.c b/3.7/wacom_sys.c index 9755952..453ddaa 100644 --- a/3.7/wacom_sys.c +++ b/3.7/wacom_sys.c @@ -1270,8 +1270,6 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int int error = 0; struct wacom_remote *remote = wacom->remote; - remote->serial[index] = serial; - remote->remote_group[index].name = kasprintf(GFP_KERNEL, "%d", serial); if (!remote->remote_group[index].name) return -ENOMEM; @@ -1287,26 +1285,13 @@ static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, int return 0; } -static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) +static void wacom_remote_destroy_attr_group(struct wacom *wacom, int i) { struct wacom_remote *remote = wacom->remote; - int i; - if (!serial) - return; - - for (i = 0; i < WACOM_MAX_REMOTES; i++) { - if (remote->serial[i] == serial) { - remote->serial[i] = 0; - wacom->led.select[i] = WACOM_STATUS_UNKNOWN; - if (remote->remote_group[i].name) { - sysfs_remove_group(remote->remote_dir, - &remote->remote_group[i]); - kfree((char *)remote->remote_group[i].name); - remote->remote_group[i].name = NULL; - } - } - } + sysfs_remove_group(remote->remote_dir, &remote->remote_group[i]); + kfree((char *)remote->remote_group[i].name); + remote->remote_group[i].name = NULL; } static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) @@ -1330,6 +1315,50 @@ static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) return retval; } +static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + u32 serial = remote->serial[index]; + int i; + + wacom_remote_destroy_attr_group(wacom, index); + + for (i = 0; i < WACOM_MAX_REMOTES; i++) { + if (remote->serial[i] == serial) { + remote->serial[i] = 0; + wacom->led.select[i] = WACOM_STATUS_UNKNOWN; + } + } +} + +static int wacom_remote_create_one(struct wacom *wacom, u32 serial, + unsigned int index) +{ + struct wacom_remote *remote = wacom->remote; + int error, k; + + /* A remote can pair more than once with an EKR, + * check to make sure this serial isn't already paired. + */ + for (k = 0; k < WACOM_MAX_REMOTES; k++) { + if (remote->serial[k] == serial) + break; + } + + if (k < WACOM_MAX_REMOTES) { + remote->serial[index] = serial; + return 0; + } + + error = wacom_remote_create_attr_group(wacom, serial, index); + if (error) + return error; + + remote->serial[index] = serial; + + return 0; +} + static ssize_t wacom_store_unpair_remote(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) @@ -1375,8 +1404,7 @@ static void wacom_remotes_destroy(struct wacom *wacom) for (i = 0; i < WACOM_MAX_REMOTES; i++) { if (wacom->remote->remote_group[i].name) { - wacom_remote_destroy_attr_group(wacom, - wacom->wacom_wac.serial[i]); + wacom_remote_destroy_one(wacom, i); } } kobject_put(remote->remote_dir); @@ -1652,7 +1680,7 @@ static void wacom_remote_work(struct work_struct *work) unsigned long flags; unsigned int count; u32 serial; - int i, k; + int i; spin_lock_irqsave(&remote->remote_lock, flags); @@ -1677,28 +1705,13 @@ static void wacom_remote_work(struct work_struct *work) if (remote->serial[i] == serial) continue; - if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); - } - - /* A remote can pair more than once with an EKR, - * check to make sure this serial isn't already paired. - */ - for (k = 0; k < WACOM_MAX_REMOTES; k++) { - if (remote->serial[k] == serial) - break; - } + if (remote->serial[i]) + wacom_remote_destroy_one(wacom, i); - if (k < WACOM_MAX_REMOTES) { - remote->serial[i] = serial; - continue; - } - wacom_remote_create_attr_group(wacom, serial, i); + wacom_remote_create_one(wacom, serial, i); } else if (remote->serial[i]) { - wacom_remote_destroy_attr_group(wacom, - remote->serial[i]); + wacom_remote_destroy_one(wacom, i); } } } @@ -1849,7 +1862,6 @@ static void wacom_disconnect(struct usb_interface *intf) cancel_work_sync(&wacom->wireless_work); cancel_work_sync(&wacom->battery_work); cancel_work_sync(&wacom->remote_work); - wacom_remotes_destroy(wacom); 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