Skip to contentSkip to conversation

EEPROM: Introduce the use of devm_kzalloc

PATCH In review Himangi Saraogi 2 participants 2 messages Aug 1, 2014 – Aug 3, 2014 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 EEPROM: Introduce the use of devm_kzalloc

This patch introduces the use of devm_kzalloc and does away with the kfrees in the probe and remove functions. Also, a label and the err variable are removed. The header device.h is included to make the devm_ function explicitly available and slab.h is done away with as it is no longer needed.

---
v3: change headers included.

 drivers/misc/eeprom/eeprom.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/misc/eeprom/eeprom.c +6 -17
index 33f8673..b432873 100644
@@ -18,7 +18,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/slab.h>
+#include <linux/device.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/mutex.h>
@@ -159,12 +159,11 @@ static int eeprom_probe(struct i2c_client *client,
 {
 	struct i2c_adapter *adapter = client->adapter;
 	struct eeprom_data *data;
-	int err;
 
-	if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
-		err = -ENOMEM;
-		goto exit;
-	}
+	data = devm_kzalloc(&client->dev, sizeof(struct eeprom_data),
+			    GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
 
 	memset(data->data, 0xff, EEPROM_SIZE);
 	i2c_set_clientdata(client, data);
@@ -190,22 +189,12 @@ static int eeprom_probe(struct i2c_client *client,
 	}
 
 	/* create the sysfs eeprom file */
-	err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
-	if (err)
-		goto exit_kfree;
-
-	return 0;
-
-exit_kfree:
-	kfree(data);
-exit:
-	return err;
+	return sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
 }
 
 static int eeprom_remove(struct i2c_client *client)
 {
 	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
-	kfree(i2c_get_clientdata(client));
 
 	return 0;
 }
Signature · 1 line
1.9.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 57 lines · Himangi Saraogi

This patch introduces the use of devm_kzalloc and does away with the kfrees in the probe and remove functions. Also, a label and the err variable are removed. The header device.h is included to make the devm_ function explicitly available and slab.h is done away with as it is no longer needed.

---
v3: change headers included.

 drivers/misc/eeprom/eeprom.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/misc/eeprom/eeprom.c +5 -16
index 33f8673..b432873 100644
@@ -18,7 +18,7 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/slab.h>
+#include <linux/device.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/mutex.h>
@@ -159,12 +159,11 @@ static int eeprom_probe(struct i2c_client *client,
 {
 	struct i2c_adapter *adapter = client->adapter;
 	struct eeprom_data *data;
-	int err;
 
-	if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
-		err = -ENOMEM;
-		goto exit;
-	}
+	data = devm_kzalloc(&client->dev, sizeof(struct eeprom_data),
+			    GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
 
 	memset(data->data, 0xff, EEPROM_SIZE);
 	i2c_set_clientdata(client, data);
@@ -190,22 +189,12 @@ static int eeprom_probe(struct i2c_client *client,
 	}
 
 	/* create the sysfs eeprom file */
-	err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
-	if (err)
-		goto exit_kfree;
-
-	return 0;
-
-exit_kfree:
-	kfree(data);
-exit:
-	return err;

drivers/misc/eeprom/eeprom.c static int eeprom_probe(struct i2c_client *client, · line 200

Quoted 10 lines
drivers/misc/eeprom/eeprom.c +1 -1
+	return sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
 }
 
 static int eeprom_remove(struct i2c_client *client)
 {
 	sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
-	kfree(i2c_get_clientdata(client));
 
 	return 0;
 }

Thanks Himangi.

Signature · 2 lines
Jean Delvare
SUSE L3 Support