]> git.karo-electronics.de Git - linux-beck.git/commitdiff
HID: lg4ff: Remove sysfs iface before deallocating memory
authorMichal Malý <madcatxster@gmail.com>
Sat, 31 Mar 2012 09:35:05 +0000 (11:35 +0200)
committerJiri Kosina <jkosina@suse.cz>
Tue, 3 Apr 2012 02:11:12 +0000 (04:11 +0200)
This patch fixes a possible race condition caused by the sysfs
interface being removed after the memory used by the interface
was already kfree'd.

Signed-off-by: Michal Malý <madcatsxter@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-lg.h
drivers/hid/hid-lg4ff.c

index 500457b67b21780235c599313c06b5db2f430a88..d64cf8d2751e51033b77a58b852dd1ba7ecc7e04 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef __HID_LG_H
 #define __HID_LG_H
 
-#include <linux/spinlock.h>
-
 struct lg_drv_data {
        unsigned long quirks;
        void *device_props;     /* Device specific properties */
index 6ecc9e2204409c1451e90086a4edd7f0639cdb01..11452920a6c3577bd509d59085a0afbb5853ffc8 100644 (file)
@@ -466,6 +466,9 @@ int lg4ff_deinit(struct hid_device *hid)
        bool found = 0;
        struct lg4ff_device_entry *entry;
        struct list_head *h, *g;
+       
+       device_remove_file(&hid->dev, &dev_attr_range);
+
        list_for_each_safe(h, g, &device_list.list) {
                entry = list_entry(h, struct lg4ff_device_entry, list);
                if (strcmp(entry->device_id, (&hid->dev)->kobj.name) == 0) {
@@ -478,11 +481,10 @@ int lg4ff_deinit(struct hid_device *hid)
        }
 
        if (!found) {
-               dbg_hid("Device entry not found!\n");
+               hid_err(hid, "Device entry not found!\n");
                return -1;
        }
 
-       device_remove_file(&hid->dev, &dev_attr_range);
        dbg_hid("Device successfully unregistered\n");
        return 0;
 }