Skip to contentSkip to conversation

HID-Lenovo: Adjustments for three function implementations

PATCH New SF Markus Elfring 1 participant 4 messages Feb 6, 2018

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

cover HID-Lenovo: Adjustments for three function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2018 17:12:34 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete an error message for a failed memory allocation in two functions Improve a size determination in lenovo_probe_tpkbd()
Adjust four checks for null pointers

 drivers/hid/hid-lenovo.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.16.1
#1 lore raw

PATCH 1/3 HID: lenovo: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2018 16:48:52 +0100

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

---
 drivers/hid/hid-lenovo.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hid/hid-lenovo.c +2 -4
index 1ac4ff4d57a6..549b84d01b46 100644
@@ -688,7 +688,6 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
 				    sizeof(struct lenovo_drvdata_tpkbd),
 				    GFP_KERNEL);
 	if (data_pointer = NULL) {
-		hid_err(hdev, "Could not allocate memory for driver data\n");
 		ret = -ENOMEM;
 		goto err;
 	}
@@ -746,10 +745,9 @@ static int lenovo_probe_cptkbd(struct hid_device *hdev)
 	cptkbd_data = devm_kzalloc(&hdev->dev,
 					sizeof(*cptkbd_data),
 					GFP_KERNEL);
-	if (cptkbd_data = NULL) {
-		hid_err(hdev, "can't alloc keyboard descriptor\n");
+	if (!cptkbd_data)
 		return -ENOMEM;
-	}
+
 	hid_set_drvdata(hdev, cptkbd_data);
 
 	/*
Signature · 1 line
2.16.1
#2 lore raw

PATCH 2/3 HID: lenovo: Improve a size determination in lenovo_probe_tpkbd()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2018 16:52:58 +0100

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

---
 drivers/hid/hid-lenovo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-lenovo.c +1 -1
index 549b84d01b46..f863b94f3476 100644
@@ -685,7 +685,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
 		hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
 
 	data_pointer = devm_kzalloc(&hdev->dev,
-				    sizeof(struct lenovo_drvdata_tpkbd),
+				    sizeof(*data_pointer),
 				    GFP_KERNEL);
 	if (data_pointer = NULL) {
 		ret = -ENOMEM;
Signature · 1 line
2.16.1
#3 lore raw

PATCH 3/3 HID: lenovo: Adjust four checks for null pointers

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 6 Feb 2018 17:02:53 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

---
 drivers/hid/hid-lenovo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hid/hid-lenovo.c +3 -3
index f863b94f3476..ba128123466b 100644
@@ -687,7 +687,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
 	data_pointer = devm_kzalloc(&hdev->dev,
 				    sizeof(*data_pointer),
 				    GFP_KERNEL);
-	if (data_pointer = NULL) {
+	if (!data_pointer) {
 		ret = -ENOMEM;
 		goto err;
 	}
@@ -698,7 +698,7 @@ static int lenovo_probe_tpkbd(struct hid_device *hdev)
 
 	name_mute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
 	name_micmute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
-	if (name_mute = NULL || name_micmute = NULL) {
+	if (!name_mute || !name_micmute) {
 		hid_err(hdev, "Could not allocate memory for led data\n");
 		ret = -ENOMEM;
 		goto err;
@@ -823,7 +823,7 @@ static void lenovo_remove_tpkbd(struct hid_device *hdev)
 	 * Only the trackpoint half of the keyboard has drvdata and stuff that
 	 * needs unregistering.
 	 */
-	if (data_pointer = NULL)
+	if (!data_pointer)
 		return;
 
 	sysfs_remove_group(&hdev->dev.kobj,
Signature · 1 line
2.16.1