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

Subsystems: hid core layer, the rest

STALE5494d

2 messages, 2 authors, 2011-08-04 · open the first message on its own page

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

From: Bojan Prtvar <hidden>
Date: 2011-08-04 21:47:40

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

Reported-by: Julia Lawall <redacted>
Signed-off-by: Bojan Prtvar <redacted>
---
 drivers/hid/hid-prodikeys.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 158b389..f779009 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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;
 }
 
-- 
1.7.1

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

From: Jiri Kosina <hidden>
Date: 2011-08-04 21:52:29

On Thu, 4 Aug 2011, Bojan Prtvar wrote:
quoted hunk
Checking for NULL pointers before kfree() is redundant.
v2:
No need for freeing pm in case when it's not allocated.

Reported-by: Julia Lawall <redacted>
Signed-off-by: Bojan Prtvar <redacted>
---
 drivers/hid/hid-prodikeys.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c
index 158b389..f779009 100644
--- a/drivers/hid/hid-prodikeys.c
+++ b/drivers/hid/hid-prodikeys.c
@@ -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;
 }
 
Applied, thanks to both.

-- 
Jiri Kosina
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help