Skip to contentSkip to conversation

misc/apds9802als: Adjustments for apds9802als_probe()

PATCH New SF Markus Elfring 1 participant 3 messages Jan 7, 2018

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

cover misc/apds9802als: Adjustments for apds9802als_probe()

From: Markus Elfring <[email protected]>
Date: Sun, 7 Jan 2018 21:58:42 +0100

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

Markus Elfring (2):
Delete an error message for a failed memory allocation Improve a size determination

 drivers/misc/apds9802als.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/2 misc/apds9802als: Delete an error message for a failed memory allocation in apds9802als_probe()

From: Markus Elfring <[email protected]>
Date: Sun, 7 Jan 2018 21:42:07 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/misc/apds9802als.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/misc/apds9802als.c +2 -3
index d8ac036f01ab..fa548796c92e 100644
@@ -231,10 +231,9 @@ static int apds9802als_probe(struct i2c_client *client,
 	struct als_data *data;
 
 	data = kzalloc(sizeof(struct als_data), GFP_KERNEL);
-	if (data = NULL) {
-		dev_err(&client->dev, "Memory allocation failed\n");
+	if (!data)
 		return -ENOMEM;
-	}
+
 	i2c_set_clientdata(client, data);
 	res = sysfs_create_group(&client->dev.kobj, &m_als_gr);
 	if (res) {
Signature · 1 line
2.15.1
#2 lore raw

PATCH 2/2 misc/apds9802als: Improve a size determination in apds9802als_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 7 Jan 2018 21:48:50 +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/misc/apds9802als.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/apds9802als.c +1 -2
index fa548796c92e..acf467666737 100644
@@ -228,9 +228,8 @@ static int apds9802als_probe(struct i2c_client *client,
 			     const struct i2c_device_id *id)
 {
 	int res;
-	struct als_data *data;
+	struct als_data *data = kzalloc(sizeof(*data), GFP_KERNEL);
 
-	data = kzalloc(sizeof(struct als_data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
Signature · 1 line
2.15.1