2016-06-23 12:36:57

by Luis de Bethencourt

[permalink] [raw]
Subject: [PATCH v2 1/2] staging: wilc1000: fix error handling in wilc_debugfs_init()

The common format to check if a function returned an error pointer is to
use PTR_ERR(). Instead of ERR_PTR() which is used to return said errors.

Signed-off-by: Luis de Bethencourt <[email protected]>
Reviewed-by: Julian Calaby <[email protected]>
---
drivers/staging/wilc1000/wilc_debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index fcbc95d..48797dc 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -107,7 +107,7 @@ static int __init wilc_debugfs_init(void)
struct wilc_debugfs_info_t *info;

wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
- if (wilc_dir == ERR_PTR(-ENODEV)) {
+ if (PTR_ERR(wilc_dir) == -ENODEV) {
/* it's not error. the debugfs is just not being enabled. */
printk("ERR, kernel has built without debugfs support\n");
return 0;
--
2.6.4



2016-06-25 21:43:40

by Luis de Bethencourt

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] staging: wilc1000: fix error handling in wilc_debugfs_init()

On 25/06/16 22:36, Greg KH wrote:
> On Thu, Jun 23, 2016 at 01:36:17PM +0100, Luis de Bethencourt wrote:
>> The common format to check if a function returned an error pointer is to
>> use PTR_ERR(). Instead of ERR_PTR() which is used to return said errors.
>>
>> Signed-off-by: Luis de Bethencourt <[email protected]>
>> Reviewed-by: Julian Calaby <[email protected]>
>> ---
>> drivers/staging/wilc1000/wilc_debugfs.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
>> index fcbc95d..48797dc 100644
>> --- a/drivers/staging/wilc1000/wilc_debugfs.c
>> +++ b/drivers/staging/wilc1000/wilc_debugfs.c
>> @@ -107,7 +107,7 @@ static int __init wilc_debugfs_init(void)
>> struct wilc_debugfs_info_t *info;
>>
>> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
>> - if (wilc_dir == ERR_PTR(-ENODEV)) {
>> + if (PTR_ERR(wilc_dir) == -ENODEV) {
>> /* it's not error. the debugfs is just not being enabled. */
>> printk("ERR, kernel has built without debugfs support\n");
>> return 0;
>
> No, the best way to do this is to just ignore the return value, you
> don't care about it. It can be passed back into any debugfs calls just
> fine.
>
> So don't check the value and all is good, debugfs was written in a way
> to make it _easy_ to use, no need for fancy error checking at all with
> it.
>
> thanks,
>
> greg k-h
>

Thanks for the review Greg.

Just to make sure. You are proposing I just drop the 3 if checks? [0]

If that's what you mean I will send a patch as soon as you confirm :)

Happy hacking,
Luis



[0] Making the function look like this:
static int __init wilc_debugfs_init(void)
{
int i;

struct dentry *debugfs_files;
struct wilc_debugfs_info_t *info;

wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
info = &debugfs_info[i];
debugfs_files = debugfs_create_file(info->name,
info->perm,
wilc_dir,
&info->data,
&info->fops);
}
return 0;
}


2016-06-23 12:37:00

by Luis de Bethencourt

[permalink] [raw]
Subject: [PATCH v2 2/2] staging: wilc1000: fix error values in wilc_debugfs_init()

If there was an error, returning -EINVAL is more appropriate than -1.

Signed-off-by: Luis de Bethencourt <[email protected]>
Reviewed-by: Julian Calaby <[email protected]>
---
drivers/staging/wilc1000/wilc_debugfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index 48797dc..6252931 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -115,7 +115,7 @@ static int __init wilc_debugfs_init(void)

if (!wilc_dir) {
printk("ERR, debugfs create dir\n");
- return -1;
+ return -EINVAL;
}

for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
@@ -129,7 +129,7 @@ static int __init wilc_debugfs_init(void)
if (!debugfs_files) {
printk("ERR fail to create the debugfs file, %s\n", info->name);
debugfs_remove_recursive(wilc_dir);
- return -1;
+ return -EINVAL;
}
}
return 0;
--
2.6.4


2016-06-25 21:36:31

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] staging: wilc1000: fix error values in wilc_debugfs_init()

On Thu, Jun 23, 2016 at 01:36:18PM +0100, Luis de Bethencourt wrote:
> If there was an error, returning -EINVAL is more appropriate than -1.
>
> Signed-off-by: Luis de Bethencourt <[email protected]>
> Reviewed-by: Julian Calaby <[email protected]>
> ---
> drivers/staging/wilc1000/wilc_debugfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
> index 48797dc..6252931 100644
> --- a/drivers/staging/wilc1000/wilc_debugfs.c
> +++ b/drivers/staging/wilc1000/wilc_debugfs.c
> @@ -115,7 +115,7 @@ static int __init wilc_debugfs_init(void)
>
> if (!wilc_dir) {
> printk("ERR, debugfs create dir\n");
> - return -1;
> + return -EINVAL;
> }

Same here, don't check.

>
> for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
> @@ -129,7 +129,7 @@ static int __init wilc_debugfs_init(void)
> if (!debugfs_files) {
> printk("ERR fail to create the debugfs file, %s\n", info->name);
> debugfs_remove_recursive(wilc_dir);
> - return -1;
> + return -EINVAL;

And here.


2016-06-25 21:36:05

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] staging: wilc1000: fix error handling in wilc_debugfs_init()

On Thu, Jun 23, 2016 at 01:36:17PM +0100, Luis de Bethencourt wrote:
> The common format to check if a function returned an error pointer is to
> use PTR_ERR(). Instead of ERR_PTR() which is used to return said errors.
>
> Signed-off-by: Luis de Bethencourt <[email protected]>
> Reviewed-by: Julian Calaby <[email protected]>
> ---
> drivers/staging/wilc1000/wilc_debugfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
> index fcbc95d..48797dc 100644
> --- a/drivers/staging/wilc1000/wilc_debugfs.c
> +++ b/drivers/staging/wilc1000/wilc_debugfs.c
> @@ -107,7 +107,7 @@ static int __init wilc_debugfs_init(void)
> struct wilc_debugfs_info_t *info;
>
> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
> - if (wilc_dir == ERR_PTR(-ENODEV)) {
> + if (PTR_ERR(wilc_dir) == -ENODEV) {
> /* it's not error. the debugfs is just not being enabled. */
> printk("ERR, kernel has built without debugfs support\n");
> return 0;

No, the best way to do this is to just ignore the return value, you
don't care about it. It can be passed back into any debugfs calls just
fine.

So don't check the value and all is good, debugfs was written in a way
to make it _easy_ to use, no need for fancy error checking at all with
it.

thanks,

greg k-h

2016-06-27 13:02:40

by Luis de Bethencourt

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] staging: wilc1000: fix error handling in wilc_debugfs_init()

On 25/06/16 23:16, Greg KH wrote:
> On Sat, Jun 25, 2016 at 10:43:33PM +0100, Luis de Bethencourt wrote:
>> On 25/06/16 22:36, Greg KH wrote:
>>> On Thu, Jun 23, 2016 at 01:36:17PM +0100, Luis de Bethencourt wrote:
>>>> The common format to check if a function returned an error pointer is to
>>>> use PTR_ERR(). Instead of ERR_PTR() which is used to return said errors.
>>>>
>>>> Signed-off-by: Luis de Bethencourt <[email protected]>
>>>> Reviewed-by: Julian Calaby <[email protected]>
>>>> ---
>>>> drivers/staging/wilc1000/wilc_debugfs.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
>>>> index fcbc95d..48797dc 100644
>>>> --- a/drivers/staging/wilc1000/wilc_debugfs.c
>>>> +++ b/drivers/staging/wilc1000/wilc_debugfs.c
>>>> @@ -107,7 +107,7 @@ static int __init wilc_debugfs_init(void)
>>>> struct wilc_debugfs_info_t *info;
>>>>
>>>> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
>>>> - if (wilc_dir == ERR_PTR(-ENODEV)) {
>>>> + if (PTR_ERR(wilc_dir) == -ENODEV) {
>>>> /* it's not error. the debugfs is just not being enabled. */
>>>> printk("ERR, kernel has built without debugfs support\n");
>>>> return 0;
>>>
>>> No, the best way to do this is to just ignore the return value, you
>>> don't care about it. It can be passed back into any debugfs calls just
>>> fine.
>>>
>>> So don't check the value and all is good, debugfs was written in a way
>>> to make it _easy_ to use, no need for fancy error checking at all with
>>> it.
>>>
>>> thanks,
>>>
>>> greg k-h
>>>
>>
>> Thanks for the review Greg.
>>
>> Just to make sure. You are proposing I just drop the 3 if checks? [0]
>>
>> If that's what you mean I will send a patch as soon as you confirm :)
>>
>> Happy hacking,
>> Luis
>>
>>
>>
>> [0] Making the function look like this:
>> static int __init wilc_debugfs_init(void)
>> {
>> int i;
>>
>> struct dentry *debugfs_files;
>> struct wilc_debugfs_info_t *info;
>>
>> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
>> for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
>> info = &debugfs_info[i];
>> debugfs_files = debugfs_create_file(info->name,
>> info->perm,
>> wilc_dir,
>> &info->data,
>> &info->fops);
>
> Why even assign anything to debugfs_files?
>

Sorry Greg.

I was just confirming I understood your suggestion, and pasted that
without cleaning the code.

Thanks for review and idea!
Luis

2016-06-26 14:43:39

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] staging: wilc1000: fix error handling in wilc_debugfs_init()

On Sat, Jun 25, 2016 at 10:43:33PM +0100, Luis de Bethencourt wrote:
> On 25/06/16 22:36, Greg KH wrote:
> > On Thu, Jun 23, 2016 at 01:36:17PM +0100, Luis de Bethencourt wrote:
> >> The common format to check if a function returned an error pointer is to
> >> use PTR_ERR(). Instead of ERR_PTR() which is used to return said errors.
> >>
> >> Signed-off-by: Luis de Bethencourt <[email protected]>
> >> Reviewed-by: Julian Calaby <[email protected]>
> >> ---
> >> drivers/staging/wilc1000/wilc_debugfs.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
> >> index fcbc95d..48797dc 100644
> >> --- a/drivers/staging/wilc1000/wilc_debugfs.c
> >> +++ b/drivers/staging/wilc1000/wilc_debugfs.c
> >> @@ -107,7 +107,7 @@ static int __init wilc_debugfs_init(void)
> >> struct wilc_debugfs_info_t *info;
> >>
> >> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
> >> - if (wilc_dir == ERR_PTR(-ENODEV)) {
> >> + if (PTR_ERR(wilc_dir) == -ENODEV) {
> >> /* it's not error. the debugfs is just not being enabled. */
> >> printk("ERR, kernel has built without debugfs support\n");
> >> return 0;
> >
> > No, the best way to do this is to just ignore the return value, you
> > don't care about it. It can be passed back into any debugfs calls just
> > fine.
> >
> > So don't check the value and all is good, debugfs was written in a way
> > to make it _easy_ to use, no need for fancy error checking at all with
> > it.
> >
> > thanks,
> >
> > greg k-h
> >
>
> Thanks for the review Greg.
>
> Just to make sure. You are proposing I just drop the 3 if checks? [0]
>
> If that's what you mean I will send a patch as soon as you confirm :)
>
> Happy hacking,
> Luis
>
>
>
> [0] Making the function look like this:
> static int __init wilc_debugfs_init(void)
> {
> int i;
>
> struct dentry *debugfs_files;
> struct wilc_debugfs_info_t *info;
>
> wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
> for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
> info = &debugfs_info[i];
> debugfs_files = debugfs_create_file(info->name,
> info->perm,
> wilc_dir,
> &info->data,
> &info->fops);

Why even assign anything to debugfs_files?