wacom_release_shared_data() and wacom_remove_shared_data() are moved up
so they can be referenced in wacom_add_shared_data().

There is no point in explicitly setting wacom_wac1->shared->type to 0 in
wacom_wireless_work() (plus this would give an oops).

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 (1c817c8)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
[aaron.sko...@wacom.com: Backported from input-wacom repository (561e444)]
Signed-off-by: Aaron Armstrong Skomra <aaron.sko...@wacom.com>
---
 3.17/wacom_sys.c | 72 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 33 deletions(-)

diff --git a/3.17/wacom_sys.c b/3.17/wacom_sys.c
index 070cdaf..c26a1b4 100644
--- a/3.17/wacom_sys.c
+++ b/3.17/wacom_sys.c
@@ -571,6 +571,38 @@ static struct wacom_hdev_data *wacom_get_hdev_data(struct 
hid_device *hdev)
        return NULL;
 }
 
+static void wacom_release_shared_data(struct kref *kref)
+{
+       struct wacom_hdev_data *data =
+               container_of(kref, struct wacom_hdev_data, kref);
+
+       mutex_lock(&wacom_udev_list_lock);
+       list_del(&data->list);
+       mutex_unlock(&wacom_udev_list_lock);
+
+       kfree(data);
+}
+
+static void wacom_remove_shared_data(void *res)
+{
+       struct wacom *wacom = res;
+       struct wacom_hdev_data *data;
+       struct wacom_wac *wacom_wac = &wacom->wacom_wac;
+
+       if (wacom_wac->shared) {
+               data = container_of(wacom_wac->shared, struct wacom_hdev_data,
+                                   shared);
+
+               if (wacom_wac->shared->touch == wacom->hdev)
+                       wacom_wac->shared->touch = NULL;
+               else if (wacom_wac->shared->pen == wacom->hdev)
+                       wacom_wac->shared->pen = NULL;
+
+               kref_put(&data->kref, wacom_release_shared_data);
+               wacom_wac->shared = NULL;
+       }
+}
+
 static int wacom_add_shared_data(struct hid_device *hdev)
 {
        struct wacom *wacom = hid_get_drvdata(hdev);
@@ -595,6 +627,13 @@ static int wacom_add_shared_data(struct hid_device *hdev)
 
        wacom_wac->shared = &data->shared;
 
+       retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
+       if (retval) {
+               mutex_unlock(&wacom_udev_list_lock);
+               wacom_remove_shared_data(wacom);
+               return retval;
+       }
+
        if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)
                wacom_wac->shared->touch = hdev;
        else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
@@ -605,37 +644,6 @@ out:
        return retval;
 }
 
-static void wacom_release_shared_data(struct kref *kref)
-{
-       struct wacom_hdev_data *data =
-               container_of(kref, struct wacom_hdev_data, kref);
-
-       mutex_lock(&wacom_udev_list_lock);
-       list_del(&data->list);
-       mutex_unlock(&wacom_udev_list_lock);
-
-       kfree(data);
-}
-
-static void wacom_remove_shared_data(struct wacom *wacom)
-{
-       struct wacom_hdev_data *data;
-       struct wacom_wac *wacom_wac = &wacom->wacom_wac;
-
-       if (wacom_wac->shared) {
-               data = container_of(wacom_wac->shared, struct wacom_hdev_data,
-                                   shared);
-
-               if (wacom_wac->shared->touch == wacom->hdev)
-                       wacom_wac->shared->touch = NULL;
-               else if (wacom_wac->shared->pen == wacom->hdev)
-                       wacom_wac->shared->pen = NULL;
-
-               kref_put(&data->kref, wacom_release_shared_data);
-               wacom_wac->shared = NULL;
-       }
-}
-
 static int wacom_led_control(struct wacom *wacom)
 {
        unsigned char *buf;
@@ -1782,7 +1790,6 @@ fail_register_inputs:
        wacom_destroy_battery(wacom);
 #endif
 fail_battery:
-       wacom_remove_shared_data(wacom);
 fail_shared_data:
 fail_parsed:
 fail_allocate_inputs:
@@ -1822,7 +1829,6 @@ static void wacom_wireless_work(struct work_struct *work)
 
        if (wacom_wac->pid == 0) {
                hid_info(wacom->hdev, "wireless tablet disconnected\n");
-               wacom_wac1->shared->type = 0;
        } else {
                const struct hid_device_id *id = wacom_ids;
 
-- 
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