2014-07-23 14:43:32

by Himangi Saraogi

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Himangi Saraogi <[email protected]>
Acked-by: Julia Lawall <[email protected]>
---
drivers/misc/eeprom/eeprom.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
index 33f8673..6d75fcf 100644
--- a/drivers/misc/eeprom/eeprom.c
+++ b/drivers/misc/eeprom/eeprom.c
@@ -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


2014-07-23 16:01:36

by Jean Delvare

[permalink] [raw]
Subject: Re: [PATCH] EEPROM: Introduce the use of devm_kzalloc

Hi Himangi,

On Wed, 23 Jul 2014 20:13:18 +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.
>
> Signed-off-by: Himangi Saraogi <[email protected]>
> Acked-by: Julia Lawall <[email protected]>
> ---
> drivers/misc/eeprom/eeprom.c | 21 +++++----------------
> 1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
> index 33f8673..6d75fcf 100644
> --- a/drivers/misc/eeprom/eeprom.c
> +++ b/drivers/misc/eeprom/eeprom.c
> @@ -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)

That does not even build:

drivers/misc/eeprom/eeprom.c: In function ‘eeprom_probe’:
drivers/misc/eeprom/eeprom.c:165:2: error: expected ‘;’ before ‘if’
if (!data)
^

Please test-build patches before you send them. That's a minimum,
ideally you should also do basic run-time testing if possible.

Please also note my new e-mail address and use that when you resubmit.

> + 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;
> }


--
Jean Delvare
SUSE L3 Support