* [PATCH v3] EEPROM: Introduce the use of devm_kzalloc
@ 2014-08-01 19:04 Himangi Saraogi
2014-08-03 12:54 ` Jean Delvare
0 siblings, 1 reply; 2+ messages in thread
From: Himangi Saraogi @ 2014-08-01 19:04 UTC (permalink / raw)
To: Jean Delvare, Paul Gortmaker, Greg Kroah-Hartman, linux-kernel
Cc: Julia Lawall
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.
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
---
v3: change headers included.
drivers/misc/eeprom/eeprom.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
index 33f8673..b432873 100644
--- a/drivers/misc/eeprom/eeprom.c
+++ b/drivers/misc/eeprom/eeprom.c
@@ -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;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] EEPROM: Introduce the use of devm_kzalloc
2014-08-01 19:04 [PATCH v3] EEPROM: Introduce the use of devm_kzalloc Himangi Saraogi
@ 2014-08-03 12:54 ` Jean Delvare
0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2014-08-03 12:54 UTC (permalink / raw)
To: Himangi Saraogi
Cc: Paul Gortmaker, Greg Kroah-Hartman, linux-kernel, Julia Lawall
On Sat, 2 Aug 2014 00:34:23 +0530, Himangi Saraogi wrote:
> 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.
>
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
> ---
> v3: change headers included.
> drivers/misc/eeprom/eeprom.c | 23 ++++++-----------------
> 1 file changed, 6 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
> index 33f8673..b432873 100644
> --- a/drivers/misc/eeprom/eeprom.c
> +++ b/drivers/misc/eeprom/eeprom.c
> @@ -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;
> }
Thanks Himangi.
Reviewed-by: Jean Delvare <jdelvare@suse.de>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-03 12:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-01 19:04 [PATCH v3] EEPROM: Introduce the use of devm_kzalloc Himangi Saraogi
2014-08-03 12:54 ` Jean Delvare
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).