Skip to contentSkip to conversation

HID: sensor-hub: don't hold spin lock while calling kzalloc with GFP_KERNEL

PATCH In review Axel Lin 2 participants 2 messages Sep 16, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 HID: sensor-hub: don't hold spin lock while calling kzalloc with GFP_KERNEL

kzalloc might cause sleep, so don't hold spin lock while calling kzalloc with GFP_KERNEL.

---
 drivers/hid/hid-sensor-hub.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/hid/hid-sensor-hub.c +6 -3
index 4ac759c..162bf6a 100644
@@ -173,14 +173,17 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
 			spin_unlock(&pdata->dyn_callback_lock);
 			return -EINVAL;
 		}
+	spin_unlock(&pdata->dyn_callback_lock);
+
 	callback = kzalloc(sizeof(*callback), GFP_KERNEL);
-	if (!callback) {
-		spin_unlock(&pdata->dyn_callback_lock);
+	if (!callback)
 		return -ENOMEM;
-	}
+
 	callback->usage_callback = usage_callback;
 	callback->usage_id = usage_id;
 	callback->priv = NULL;
+
+	spin_lock(&pdata->dyn_callback_lock);
 	list_add_tail(&callback->list, &pdata->dyn_callback_list);
 	spin_unlock(&pdata->dyn_callback_lock);
 
Signature · 1 line
1.7.9.5
#1 lore raw

There is already a patch submitted to change to GFP_ATOMIC, which address this.

-----Original Message-----
From: Axel Lin [mailto:[email protected]]
Sent: Saturday, September 15, 2012 7:58 PM
To: Jiri Kosina
Cc: Pandruvada, Srinivas; Jonathan Cameron; [email protected]
Subject: [PATCH RFT] HID: sensor-hub: don't hold spin lock while calling kzalloc with GFP_KERNEL

kzalloc might cause sleep, so don't hold spin lock while calling kzalloc with GFP_KERNEL.

---
 drivers/hid/hid-sensor-hub.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/hid/hid-sensor-hub.c +6 -3
@@ -173,14 +173,17 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
 			spin_unlock(&pdata->dyn_callback_lock);
 			return -EINVAL;
 		}
+	spin_unlock(&pdata->dyn_callback_lock);
+
 	callback = kzalloc(sizeof(*callback), GFP_KERNEL);
-	if (!callback) {
-		spin_unlock(&pdata->dyn_callback_lock);
+	if (!callback)
 		return -ENOMEM;
-	}
+
 	callback->usage_callback = usage_callback;
 	callback->usage_id = usage_id;
 	callback->priv = NULL;
+
+	spin_lock(&pdata->dyn_callback_lock);
 	list_add_tail(&callback->list, &pdata->dyn_callback_list);
 	spin_unlock(&pdata->dyn_callback_lock);
 

--
1.7.9.5