* [PATCH v2] i7core_edac: release resources on error in i7core_create_sysfs_devices
@ 2015-02-03 2:40 Junjie Mao
2015-02-03 4:15 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Junjie Mao @ 2015-02-03 2:40 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Doug Thompson, Borislav Petkov, linux-edac, linux-kernel, Junjie Mao
v2: do not call kfree on allocated devs after device_initialize is called
Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
---
drivers/edac/i7core_edac.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 9cd0b301f81b..f6a7b676d69c 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1167,17 +1167,17 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
return rc;
rc = device_create_file(&mci->dev, &dev_attr_inject_type);
if (rc < 0)
- return rc;
+ goto fail_remove_inject_section;
rc = device_create_file(&mci->dev, &dev_attr_inject_eccmask);
if (rc < 0)
- return rc;
+ goto fail_remove_inject_type;
rc = device_create_file(&mci->dev, &dev_attr_inject_enable);
if (rc < 0)
- return rc;
+ goto fail_remove_inject_eccmask;
pvt->addrmatch_dev = kzalloc(sizeof(*pvt->addrmatch_dev), GFP_KERNEL);
if (!pvt->addrmatch_dev)
- return rc;
+ goto fail_remove_inject_enable;
pvt->addrmatch_dev->type = &addrmatch_type;
pvt->addrmatch_dev->bus = mci->dev.bus;
@@ -1190,16 +1190,13 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
rc = device_add(pvt->addrmatch_dev);
if (rc < 0)
- return rc;
+ goto fail_free_addrmatch_dev;
if (!pvt->is_registered) {
pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
GFP_KERNEL);
- if (!pvt->chancounts_dev) {
- put_device(pvt->addrmatch_dev);
- device_del(pvt->addrmatch_dev);
- return rc;
- }
+ if (!pvt->chancounts_dev)
+ goto fail_del_addrmatch_dev;
pvt->chancounts_dev->type = &all_channel_counts_type;
pvt->chancounts_dev->bus = mci->dev.bus;
@@ -1211,10 +1208,26 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
edac_dbg(1, "creating %s\n", dev_name(pvt->chancounts_dev));
rc = device_add(pvt->chancounts_dev);
- if (rc < 0)
- return rc;
+ if (rc < 0) {
+ put_device(pvt->chancounts_dev);
+ goto fail_del_addrmatch_dev;
+ }
}
return 0;
+
+fail_del_addrmatch_dev:
+ device_del(pvt->addrmatch_dev);
+fail_free_addrmatch_dev:
+ put_device(pvt->addrmatch_dev);
+fail_remove_inject_enable:
+ device_create_file(&mci->dev, &dev_attr_inject_enable);
+fail_remove_inject_eccmask:
+ device_create_file(&mci->dev, &dev_attr_inject_eccmask);
+fail_remove_inject_type:
+ device_create_file(&mci->dev, &dev_attr_inject_type);
+fail_remove_inject_section:
+ device_create_file(&mci->dev, &dev_attr_inject_section);
+ return rc;
}
static void i7core_delete_sysfs_devices(struct mem_ctl_info *mci)
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] i7core_edac: release resources on error in i7core_create_sysfs_devices
2015-02-03 2:40 [PATCH v2] i7core_edac: release resources on error in i7core_create_sysfs_devices Junjie Mao
@ 2015-02-03 4:15 ` Guenter Roeck
2015-02-03 5:56 ` Junjie Mao
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2015-02-03 4:15 UTC (permalink / raw)
To: Junjie Mao
Cc: Mauro Carvalho Chehab, Doug Thompson, Borislav Petkov,
linux-edac, linux-kernel
On Tue, Feb 03, 2015 at 10:40:14AM +0800, Junjie Mao wrote:
> v2: do not call kfree on allocated devs after device_initialize is called
>
> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
> ---
> drivers/edac/i7core_edac.c | 37 +++++++++++++++++++++++++------------
> 1 file changed, 25 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
> index 9cd0b301f81b..f6a7b676d69c 100644
> --- a/drivers/edac/i7core_edac.c
> +++ b/drivers/edac/i7core_edac.c
> @@ -1167,17 +1167,17 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
> return rc;
> rc = device_create_file(&mci->dev, &dev_attr_inject_type);
> if (rc < 0)
> - return rc;
> + goto fail_remove_inject_section;
> rc = device_create_file(&mci->dev, &dev_attr_inject_eccmask);
> if (rc < 0)
> - return rc;
> + goto fail_remove_inject_type;
> rc = device_create_file(&mci->dev, &dev_attr_inject_enable);
> if (rc < 0)
> - return rc;
> + goto fail_remove_inject_eccmask;
>
> pvt->addrmatch_dev = kzalloc(sizeof(*pvt->addrmatch_dev), GFP_KERNEL);
> if (!pvt->addrmatch_dev)
> - return rc;
> + goto fail_remove_inject_enable;
>
> pvt->addrmatch_dev->type = &addrmatch_type;
> pvt->addrmatch_dev->bus = mci->dev.bus;
> @@ -1190,16 +1190,13 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
>
> rc = device_add(pvt->addrmatch_dev);
> if (rc < 0)
> - return rc;
> + goto fail_free_addrmatch_dev;
>
> if (!pvt->is_registered) {
> pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
> GFP_KERNEL);
> - if (!pvt->chancounts_dev) {
> - put_device(pvt->addrmatch_dev);
> - device_del(pvt->addrmatch_dev);
> - return rc;
> - }
> + if (!pvt->chancounts_dev)
> + goto fail_del_addrmatch_dev;
>
> pvt->chancounts_dev->type = &all_channel_counts_type;
> pvt->chancounts_dev->bus = mci->dev.bus;
> @@ -1211,10 +1208,26 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
> edac_dbg(1, "creating %s\n", dev_name(pvt->chancounts_dev));
>
> rc = device_add(pvt->chancounts_dev);
> - if (rc < 0)
> - return rc;
> + if (rc < 0) {
> + put_device(pvt->chancounts_dev);
> + goto fail_del_addrmatch_dev;
> + }
> }
> return 0;
> +
> +fail_del_addrmatch_dev:
> + device_del(pvt->addrmatch_dev);
> +fail_free_addrmatch_dev:
> + put_device(pvt->addrmatch_dev);
> +fail_remove_inject_enable:
> + device_create_file(&mci->dev, &dev_attr_inject_enable);
> +fail_remove_inject_eccmask:
> + device_create_file(&mci->dev, &dev_attr_inject_eccmask);
> +fail_remove_inject_type:
> + device_create_file(&mci->dev, &dev_attr_inject_type);
> +fail_remove_inject_section:
> + device_create_file(&mci->dev, &dev_attr_inject_section);
I don't know the code, but calling device_create_file() on failures
is quite unusual. Are you sure this is correct ?
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] i7core_edac: release resources on error in i7core_create_sysfs_devices
2015-02-03 4:15 ` Guenter Roeck
@ 2015-02-03 5:56 ` Junjie Mao
0 siblings, 0 replies; 3+ messages in thread
From: Junjie Mao @ 2015-02-03 5:56 UTC (permalink / raw)
To: Guenter Roeck
Cc: Mauro Carvalho Chehab, Doug Thompson, Borislav Petkov,
linux-edac, linux-kernel
Guenter Roeck <linux@roeck-us.net> writes:
> On Tue, Feb 03, 2015 at 10:40:14AM +0800, Junjie Mao wrote:
>> v2: do not call kfree on allocated devs after device_initialize is called
>>
>> Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
>> ---
>> drivers/edac/i7core_edac.c | 37 +++++++++++++++++++++++++------------
>> 1 file changed, 25 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
>> index 9cd0b301f81b..f6a7b676d69c 100644
>> --- a/drivers/edac/i7core_edac.c
>> +++ b/drivers/edac/i7core_edac.c
>> @@ -1167,17 +1167,17 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
>> return rc;
>> rc = device_create_file(&mci->dev, &dev_attr_inject_type);
>> if (rc < 0)
>> - return rc;
>> + goto fail_remove_inject_section;
>> rc = device_create_file(&mci->dev, &dev_attr_inject_eccmask);
>> if (rc < 0)
>> - return rc;
>> + goto fail_remove_inject_type;
>> rc = device_create_file(&mci->dev, &dev_attr_inject_enable);
>> if (rc < 0)
>> - return rc;
>> + goto fail_remove_inject_eccmask;
>>
>> pvt->addrmatch_dev = kzalloc(sizeof(*pvt->addrmatch_dev), GFP_KERNEL);
>> if (!pvt->addrmatch_dev)
>> - return rc;
>> + goto fail_remove_inject_enable;
>>
>> pvt->addrmatch_dev->type = &addrmatch_type;
>> pvt->addrmatch_dev->bus = mci->dev.bus;
>> @@ -1190,16 +1190,13 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
>>
>> rc = device_add(pvt->addrmatch_dev);
>> if (rc < 0)
>> - return rc;
>> + goto fail_free_addrmatch_dev;
>>
>> if (!pvt->is_registered) {
>> pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
>> GFP_KERNEL);
>> - if (!pvt->chancounts_dev) {
>> - put_device(pvt->addrmatch_dev);
>> - device_del(pvt->addrmatch_dev);
>> - return rc;
>> - }
>> + if (!pvt->chancounts_dev)
>> + goto fail_del_addrmatch_dev;
>>
>> pvt->chancounts_dev->type = &all_channel_counts_type;
>> pvt->chancounts_dev->bus = mci->dev.bus;
>> @@ -1211,10 +1208,26 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
>> edac_dbg(1, "creating %s\n", dev_name(pvt->chancounts_dev));
>>
>> rc = device_add(pvt->chancounts_dev);
>> - if (rc < 0)
>> - return rc;
>> + if (rc < 0) {
>> + put_device(pvt->chancounts_dev);
>> + goto fail_del_addrmatch_dev;
>> + }
>> }
>> return 0;
>> +
>> +fail_del_addrmatch_dev:
>> + device_del(pvt->addrmatch_dev);
>> +fail_free_addrmatch_dev:
>> + put_device(pvt->addrmatch_dev);
>> +fail_remove_inject_enable:
>> + device_create_file(&mci->dev, &dev_attr_inject_enable);
>> +fail_remove_inject_eccmask:
>> + device_create_file(&mci->dev, &dev_attr_inject_eccmask);
>> +fail_remove_inject_type:
>> + device_create_file(&mci->dev, &dev_attr_inject_type);
>> +fail_remove_inject_section:
>> + device_create_file(&mci->dev, &dev_attr_inject_section);
>
> I don't know the code, but calling device_create_file() on failures
> is quite unusual. Are you sure this is correct ?
>
> Guenter
I should call device_remove_file here. Terribly sorry for the
carelessness.
Best Regards
Junjie Mao
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-02-03 6:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03 2:40 [PATCH v2] i7core_edac: release resources on error in i7core_create_sysfs_devices Junjie Mao
2015-02-03 4:15 ` Guenter Roeck
2015-02-03 5:56 ` Junjie Mao
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).