Skip to contentSkip to conversation

HID: kfree() NULL pointer cleanup

PATCH Applied Bojan Prtvar 2 participants 2 messages Aug 4, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 HID: kfree() NULL pointer cleanup

Checking for NULL pointers before kfree() is redundant. v2:
No need for freeing pm in case when it's not allocated.

---
 drivers/hid/hid-prodikeys.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/hid/hid-prodikeys.c +4 -4
index 158b389..f779009 100644
@@ -816,7 +816,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (pm = NULL) {
 		hid_err(hdev, "can't alloc descriptor\n");
 		ret = -ENOMEM;
-		goto err_free;
+		goto err_free_pk;
 	}
 
 	pm->pk = pk;
@@ -849,10 +849,10 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
 err_stop:
 	hid_hw_stop(hdev);
 err_free:
-	if (pm != NULL)
-		kfree(pm);
-
+	kfree(pm);
+err_free_pk:
 	kfree(pk);
+
 	return ret;
 }
 
Signature · 1 line
1.7.1
Applied
#1 lore raw
Quoted 27 lines · Bojan Prtvar

Checking for NULL pointers before kfree() is redundant. v2:
No need for freeing pm in case when it's not allocated.

---
 drivers/hid/hid-prodikeys.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/hid/hid-prodikeys.c +1 -1
index 158b389..f779009 100644
@@ -816,7 +816,7 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (pm = NULL) {
 		hid_err(hdev, "can't alloc descriptor\n");
 		ret = -ENOMEM;
-		goto err_free;
+		goto err_free_pk;
 	}
 
 	pm->pk = pk;
@@ -849,10 +849,10 @@ static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id)
 err_stop:
 	hid_hw_stop(hdev);
 err_free:

drivers/hid/hid-prodikeys.c static int pk_probe(struct hid_device *hdev, const struct hid_device_id *id) · line 858

Quoted 10 lines
drivers/hid/hid-prodikeys.c +3 -3
-	if (pm != NULL)
-		kfree(pm);
-
+	kfree(pm);
+err_free_pk:
 	kfree(pk);
+
 	return ret;
 }
 

Applied, thanks to both.

Signature · 2 lines
Jiri Kosina
SUSE Labs