diff options
author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2015-05-07 17:26:34 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2015-05-12 08:13:20 -0400 |
commit | 2d94e5224e81c58986a8cf44a3bf4830ce5cb96e (patch) | |
tree | b12b410a0dc0fea939f8da807e8d83471bc1c111 | |
parent | 5006c1052aafa01dab5b0e643b7dac755b41f3bb (diff) |
HID: hid-sensor-hub: Fix debug lock warning
When CONFIG_DEBUG_LOCK_ALLOC is defined, mutex magic is compared and
warned for (l->magic != l), here l is the address of mutex pointer.
In hid-sensor-hub as part of hsdev creation, a per hsdev mutex is
initialized during MFD cell creation. This hsdev, which contains, mutex
is part of platform data for the a cell. But platform_data is copied
in platform_device_add_data() in platform.c. This copy will copy the
whole hsdev structure including mutex. But once copied the magic
will no longer match. So when client driver call
sensor_hub_input_attr_get_raw_value, this will trigger mutex warning.
So to avoid this allocate mutex dynamically. This will be same even
after copy.
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/hid-sensor-hub.c | 13 | ||||
-rw-r--r-- | include/linux/hid-sensor-hub.h | 4 |
2 files changed, 12 insertions, 5 deletions
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index c3f6f1e311ea..090a1ba0abb6 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c | |||
@@ -294,7 +294,7 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, | |||
294 | if (!report) | 294 | if (!report) |
295 | return -EINVAL; | 295 | return -EINVAL; |
296 | 296 | ||
297 | mutex_lock(&hsdev->mutex); | 297 | mutex_lock(hsdev->mutex_ptr); |
298 | if (flag == SENSOR_HUB_SYNC) { | 298 | if (flag == SENSOR_HUB_SYNC) { |
299 | memset(&hsdev->pending, 0, sizeof(hsdev->pending)); | 299 | memset(&hsdev->pending, 0, sizeof(hsdev->pending)); |
300 | init_completion(&hsdev->pending.ready); | 300 | init_completion(&hsdev->pending.ready); |
@@ -328,7 +328,7 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, | |||
328 | kfree(hsdev->pending.raw_data); | 328 | kfree(hsdev->pending.raw_data); |
329 | hsdev->pending.status = false; | 329 | hsdev->pending.status = false; |
330 | } | 330 | } |
331 | mutex_unlock(&hsdev->mutex); | 331 | mutex_unlock(hsdev->mutex_ptr); |
332 | 332 | ||
333 | return ret_val; | 333 | return ret_val; |
334 | } | 334 | } |
@@ -667,7 +667,14 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
667 | hsdev->vendor_id = hdev->vendor; | 667 | hsdev->vendor_id = hdev->vendor; |
668 | hsdev->product_id = hdev->product; | 668 | hsdev->product_id = hdev->product; |
669 | hsdev->usage = collection->usage; | 669 | hsdev->usage = collection->usage; |
670 | mutex_init(&hsdev->mutex); | 670 | hsdev->mutex_ptr = devm_kzalloc(&hdev->dev, |
671 | sizeof(struct mutex), | ||
672 | GFP_KERNEL); | ||
673 | if (!hsdev->mutex_ptr) { | ||
674 | ret = -ENOMEM; | ||
675 | goto err_stop_hw; | ||
676 | } | ||
677 | mutex_init(hsdev->mutex_ptr); | ||
671 | hsdev->start_collection_index = i; | 678 | hsdev->start_collection_index = i; |
672 | if (last_hsdev) | 679 | if (last_hsdev) |
673 | last_hsdev->end_collection_index = i; | 680 | last_hsdev->end_collection_index = i; |
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 0408421d885f..0042bf330b99 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h | |||
@@ -74,7 +74,7 @@ struct sensor_hub_pending { | |||
74 | * @usage: Usage id for this hub device instance. | 74 | * @usage: Usage id for this hub device instance. |
75 | * @start_collection_index: Starting index for a phy type collection | 75 | * @start_collection_index: Starting index for a phy type collection |
76 | * @end_collection_index: Last index for a phy type collection | 76 | * @end_collection_index: Last index for a phy type collection |
77 | * @mutex: synchronizing mutex. | 77 | * @mutex_ptr: synchronizing mutex pointer. |
78 | * @pending: Holds information of pending sync read request. | 78 | * @pending: Holds information of pending sync read request. |
79 | */ | 79 | */ |
80 | struct hid_sensor_hub_device { | 80 | struct hid_sensor_hub_device { |
@@ -84,7 +84,7 @@ struct hid_sensor_hub_device { | |||
84 | u32 usage; | 84 | u32 usage; |
85 | int start_collection_index; | 85 | int start_collection_index; |
86 | int end_collection_index; | 86 | int end_collection_index; |
87 | struct mutex mutex; | 87 | struct mutex *mutex_ptr; |
88 | struct sensor_hub_pending pending; | 88 | struct sensor_hub_pending pending; |
89 | }; | 89 | }; |
90 | 90 | ||