All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
@ 2022-03-22  8:38 Fabio M. De Francesco
  2022-03-22  8:47 ` Greg Kroah-Hartman
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Fabio M. De Francesco @ 2022-03-22  8:38 UTC (permalink / raw)
  To: David Kershner, Greg Kroah-Hartman, sparmaintainer,
	linux-staging, linux-kernel
  Cc: Fabio M. De Francesco

debugfs_create_dir() returns a pointers to a dentry objects. On failures
it returns errors. Currently the values returned to visornic_probe()
seem to be tested for being equal to NULL in case of failures.

Properly test with "if (IS_ERR())" and then assign the correct error 
value to the "err" variable.

Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
index 643432458105..58d03f3d3173 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
 	/* create debug/sysfs directories */
 	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
 						      visornic_debugfs_dir);
-	if (!devdata->eth_debugfs_dir) {
+	if (IS_ERR(devdata->eth_debugfs_dir)) {
 		dev_err(&dev->device,
 			"%s debugfs_create_dir %s failed\n",
 			__func__, netdev->name);
-		err = -ENOMEM;
+		err = PTR_ERR(devdata->eth_debugfs_dir);
 		goto cleanup_register_netdev;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:38 [PATCH] staging: unisys: Properly test debugfs_create_dir() return values Fabio M. De Francesco
@ 2022-03-22  8:47 ` Greg Kroah-Hartman
  2022-03-24  9:20   ` Fabio M. De Francesco
  2022-03-22  8:48 ` Greg Kroah-Hartman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2022-03-22  8:47 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: David Kershner, sparmaintainer, linux-staging, linux-kernel

On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> debugfs_create_dir() returns a pointers to a dentry objects. On failures
> it returns errors. Currently the values returned to visornic_probe()
> seem to be tested for being equal to NULL in case of failures.
> 
> Properly test with "if (IS_ERR())" and then assign the correct error 
> value to the "err" variable.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> index 643432458105..58d03f3d3173 100644
> --- a/drivers/staging/unisys/visornic/visornic_main.c
> +++ b/drivers/staging/unisys/visornic/visornic_main.c
> @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
>  	/* create debug/sysfs directories */
>  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
>  						      visornic_debugfs_dir);
> -	if (!devdata->eth_debugfs_dir) {
> +	if (IS_ERR(devdata->eth_debugfs_dir)) {

We really shouldn't be checking this value at all.  There's no reason to
check the return value of a debugfs_* call.  Can you fix up the code to
do that instead?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:38 [PATCH] staging: unisys: Properly test debugfs_create_dir() return values Fabio M. De Francesco
  2022-03-22  8:47 ` Greg Kroah-Hartman
@ 2022-03-22  8:48 ` Greg Kroah-Hartman
  2022-03-22  8:49 ` Dan Carpenter
  2022-03-29 17:00 ` Fabio M. De Francesco
  3 siblings, 0 replies; 9+ messages in thread
From: Greg Kroah-Hartman @ 2022-03-22  8:48 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: David Kershner, sparmaintainer, linux-staging, linux-kernel

On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> debugfs_create_dir() returns a pointers to a dentry objects. On failures
> it returns errors. Currently the values returned to visornic_probe()
> seem to be tested for being equal to NULL in case of failures.
> 
> Properly test with "if (IS_ERR())" and then assign the correct error 
> value to the "err" variable.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> index 643432458105..58d03f3d3173 100644
> --- a/drivers/staging/unisys/visornic/visornic_main.c
> +++ b/drivers/staging/unisys/visornic/visornic_main.c
> @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
>  	/* create debug/sysfs directories */
>  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
>  						      visornic_debugfs_dir);
> -	if (!devdata->eth_debugfs_dir) {
> +	if (IS_ERR(devdata->eth_debugfs_dir)) {
>  		dev_err(&dev->device,
>  			"%s debugfs_create_dir %s failed\n",
>  			__func__, netdev->name);
> -		err = -ENOMEM;
> +		err = PTR_ERR(devdata->eth_debugfs_dir);
>  		goto cleanup_register_netdev;
>  	}

Also, why does this variable have to be saved off at all?  It should
only be used later when removing the directory, and we can just look it
up at that point in time, right?

Also, what happens if the network device name changes?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:38 [PATCH] staging: unisys: Properly test debugfs_create_dir() return values Fabio M. De Francesco
  2022-03-22  8:47 ` Greg Kroah-Hartman
  2022-03-22  8:48 ` Greg Kroah-Hartman
@ 2022-03-22  8:49 ` Dan Carpenter
  2022-03-22  8:55   ` Dan Carpenter
  2022-03-22  9:09   ` Fabio M. De Francesco
  2022-03-29 17:00 ` Fabio M. De Francesco
  3 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-03-22  8:49 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: David Kershner, Greg Kroah-Hartman, sparmaintainer,
	linux-staging, linux-kernel

On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> debugfs_create_dir() returns a pointers to a dentry objects. On failures
> it returns errors. Currently the values returned to visornic_probe()
> seem to be tested for being equal to NULL in case of failures.
> 
> Properly test with "if (IS_ERR())" and then assign the correct error 
> value to the "err" variable.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> index 643432458105..58d03f3d3173 100644
> --- a/drivers/staging/unisys/visornic/visornic_main.c
> +++ b/drivers/staging/unisys/visornic/visornic_main.c
> @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
>  	/* create debug/sysfs directories */
>  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
>  						      visornic_debugfs_dir);
> -	if (!devdata->eth_debugfs_dir) {
> +	if (IS_ERR(devdata->eth_debugfs_dir)) {

Normally I would say to just delete the error handling.  But in this
case you can delete the whole devdata->eth_debugfs_dir and the related
code.  It's not used at all.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:49 ` Dan Carpenter
@ 2022-03-22  8:55   ` Dan Carpenter
  2022-03-22  9:09   ` Fabio M. De Francesco
  1 sibling, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-03-22  8:55 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: David Kershner, Greg Kroah-Hartman, sparmaintainer,
	linux-staging, linux-kernel

On Tue, Mar 22, 2022 at 11:49:28AM +0300, Dan Carpenter wrote:
> On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> > debugfs_create_dir() returns a pointers to a dentry objects. On failures
> > it returns errors. Currently the values returned to visornic_probe()
> > seem to be tested for being equal to NULL in case of failures.
> > 
> > Properly test with "if (IS_ERR())" and then assign the correct error 
> > value to the "err" variable.
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> > index 643432458105..58d03f3d3173 100644
> > --- a/drivers/staging/unisys/visornic/visornic_main.c
> > +++ b/drivers/staging/unisys/visornic/visornic_main.c
> > @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
> >  	/* create debug/sysfs directories */
> >  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
> >  						      visornic_debugfs_dir);
> > -	if (!devdata->eth_debugfs_dir) {
> > +	if (IS_ERR(devdata->eth_debugfs_dir)) {
> 
> Normally I would say to just delete the error handling.

In the normal case checking debugfs functions for errors is not
required.  The users all have checks built in.  The exception is when
the driver dereferences devdata->eth_debugfs_dir itself.  So when you
make these kinds of changes do a grep for eth_debugfs_dir to make sure
it's not dereferenced, but normally it is not.

But again, here, delete everything.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:49 ` Dan Carpenter
  2022-03-22  8:55   ` Dan Carpenter
@ 2022-03-22  9:09   ` Fabio M. De Francesco
  1 sibling, 0 replies; 9+ messages in thread
From: Fabio M. De Francesco @ 2022-03-22  9:09 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Kershner, Greg Kroah-Hartman, sparmaintainer,
	linux-staging, linux-kernel

On marted? 22 marzo 2022 09:49:28 CET Dan Carpenter wrote:
> On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> > debugfs_create_dir() returns a pointers to a dentry objects. On failures
> > it returns errors. Currently the values returned to visornic_probe()
> > seem to be tested for being equal to NULL in case of failures.
> > 
> > Properly test with "if (IS_ERR())" and then assign the correct error 
> > value to the "err" variable.
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> > index 643432458105..58d03f3d3173 100644
> > --- a/drivers/staging/unisys/visornic/visornic_main.c
> > +++ b/drivers/staging/unisys/visornic/visornic_main.c
> > @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
> >  	/* create debug/sysfs directories */
> >  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
> >  						      visornic_debugfs_dir);
> > -	if (!devdata->eth_debugfs_dir) {
> > +	if (IS_ERR(devdata->eth_debugfs_dir)) {
> 
> Normally I would say to just delete the error handling.  But in this
> case you can delete the whole devdata->eth_debugfs_dir and the related
> code.  It's not used at all.
> 
> regards,
> dan carpenter
> 
Dear Dan,

I think that you are right and the whole thing should be deleted. There are 
a couple more of these kinds of bad error handling in the Unisys driver.

However, soon after sending this patch I noticed that David Kershner email
account at unisys.com is not working anymore. Furthermore, I am recalling
that in 2021 I made a conversion from IDA to XArray for the whole visorhba
driver and nobody at Unisys replied. After one month in queue, Greg decided
to apply my patches while noticing that nobody from Unisys cares.

In summation, probably I'll follow your suggestion for this case and the
other bugs that I was about to fix but I'm not sure at all at the moment.

What I mean is: if people at Unisys don't care, why should I?

Thanks for your review, Dan.

Regards,

Fabio M. De Francesco

P.S.: I found this and the other bugs in this Unisys driver with the help
of Smatch. Thank you for this precious tool :)




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:47 ` Greg Kroah-Hartman
@ 2022-03-24  9:20   ` Fabio M. De Francesco
  0 siblings, 0 replies; 9+ messages in thread
From: Fabio M. De Francesco @ 2022-03-24  9:20 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: David Kershner, sparmaintainer, linux-staging, linux-kernel

On marted? 22 marzo 2022 09:47:29 CET Greg Kroah-Hartman wrote:
> On Tue, Mar 22, 2022 at 09:38:58AM +0100, Fabio M. De Francesco wrote:
> > debugfs_create_dir() returns a pointers to a dentry objects. On failures
> > it returns errors. Currently the values returned to visornic_probe()
> > seem to be tested for being equal to NULL in case of failures.
> > 
> > Properly test with "if (IS_ERR())" and then assign the correct error 
> > value to the "err" variable.
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> > index 643432458105..58d03f3d3173 100644
> > --- a/drivers/staging/unisys/visornic/visornic_main.c
> > +++ b/drivers/staging/unisys/visornic/visornic_main.c
> > @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
> >  	/* create debug/sysfs directories */
> >  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
> >  						      visornic_debugfs_dir);
> > -	if (!devdata->eth_debugfs_dir) {
> > +	if (IS_ERR(devdata->eth_debugfs_dir)) {
> 
> We really shouldn't be checking this value at all.  There's no reason to
> check the return value of a debugfs_* call.  Can you fix up the code to
> do that instead?
> 
> thanks,
> 
> greg k-h
> 

Yes I'll do the work that you requested by this weekend, notwithstanding 
what I replied to Dan. 

While I reiterate all my considerations, it seems that, if not the people 
from Unisys, someone else still cares about this driver :)

Thanks,

Fabio




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-22  8:38 [PATCH] staging: unisys: Properly test debugfs_create_dir() return values Fabio M. De Francesco
                   ` (2 preceding siblings ...)
  2022-03-22  8:49 ` Dan Carpenter
@ 2022-03-29 17:00 ` Fabio M. De Francesco
  2022-03-29 17:46   ` Dan Carpenter
  3 siblings, 1 reply; 9+ messages in thread
From: Fabio M. De Francesco @ 2022-03-29 17:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman, dan.carpenter
  Cc: David Kershner, sparmaintainer, linux-staging, linux-kernel

On martedì 22 marzo 2022 09:38:58 CEST Fabio M. De Francesco wrote:
> debugfs_create_dir() returns a pointers to a dentry objects. On failures
> it returns errors. Currently the values returned to visornic_probe()
> seem to be tested for being equal to NULL in case of failures.
> 
> Properly test with "if (IS_ERR())" and then assign the correct error 
> value to the "err" variable.
> 
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> index 643432458105..58d03f3d3173 100644
> --- a/drivers/staging/unisys/visornic/visornic_main.c
> +++ b/drivers/staging/unisys/visornic/visornic_main.c
> @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
>  	/* create debug/sysfs directories */
>  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
>  						      visornic_debugfs_dir);
> -	if (!devdata->eth_debugfs_dir) {
> +	if (IS_ERR(devdata->eth_debugfs_dir)) {
>  		dev_err(&dev->device,
>  			"%s debugfs_create_dir %s failed\n",
>  			__func__, netdev->name);
> -		err = -ENOMEM;
> +		err = PTR_ERR(devdata->eth_debugfs_dir);
>  		goto cleanup_register_netdev;
>  	}
>  
> -- 
> 2.34.1
> 
Hi Greg, Dan,

Now I have time to rework this patch but, if I'm not misunderstanding, you 
asked for two contrasting works to do here...

Dan wrote that "[in] this case you can delete the whole devdata->eth_debugfs_dir 
and the related code.".

Greg wrote that "We really shouldn't be checking this value at all.  There's 
no reason to check the return value of a debugfs_* call. Can you fix up the code to
do that instead?".

I'm confused because they look like two incompatible requests. What should I do?

Thanks,

Fabio M. De Francesco



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] staging: unisys: Properly test debugfs_create_dir() return values
  2022-03-29 17:00 ` Fabio M. De Francesco
@ 2022-03-29 17:46   ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-03-29 17:46 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Greg Kroah-Hartman, David Kershner, sparmaintainer,
	linux-staging, linux-kernel

On Tue, Mar 29, 2022 at 07:00:49PM +0200, Fabio M. De Francesco wrote:
> On martedì 22 marzo 2022 09:38:58 CEST Fabio M. De Francesco wrote:
> > debugfs_create_dir() returns a pointers to a dentry objects. On failures
> > it returns errors. Currently the values returned to visornic_probe()
> > seem to be tested for being equal to NULL in case of failures.
> > 
> > Properly test with "if (IS_ERR())" and then assign the correct error 
> > value to the "err" variable.
> > 
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> > ---
> >  drivers/staging/unisys/visornic/visornic_main.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
> > index 643432458105..58d03f3d3173 100644
> > --- a/drivers/staging/unisys/visornic/visornic_main.c
> > +++ b/drivers/staging/unisys/visornic/visornic_main.c
> > @@ -1922,11 +1922,11 @@ static int visornic_probe(struct visor_device *dev)
> >  	/* create debug/sysfs directories */
> >  	devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
> >  						      visornic_debugfs_dir);
> > -	if (!devdata->eth_debugfs_dir) {
> > +	if (IS_ERR(devdata->eth_debugfs_dir)) {
> >  		dev_err(&dev->device,
> >  			"%s debugfs_create_dir %s failed\n",
> >  			__func__, netdev->name);
> > -		err = -ENOMEM;
> > +		err = PTR_ERR(devdata->eth_debugfs_dir);
> >  		goto cleanup_register_netdev;
> >  	}
> >  
> > -- 
> > 2.34.1
> > 
> Hi Greg, Dan,
> 
> Now I have time to rework this patch but, if I'm not misunderstanding, you 
> asked for two contrasting works to do here...
> 
> Dan wrote that "[in] this case you can delete the whole devdata->eth_debugfs_dir 
> and the related code.".
> 
> Greg wrote that "We really shouldn't be checking this value at all.  There's 
> no reason to check the return value of a debugfs_* call. Can you fix up the code to
> do that instead?".
> 
> I'm confused because they look like two incompatible requests. What should I do?

Greg is saying delete the tests and the error handling.  But I am
saying delete the tests, the error handling, the devdata->eth_debugfs_dir
related code and the call to debugfs_create_dir().

There is no conflict.  Delete it all.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-03-29 17:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-22  8:38 [PATCH] staging: unisys: Properly test debugfs_create_dir() return values Fabio M. De Francesco
2022-03-22  8:47 ` Greg Kroah-Hartman
2022-03-24  9:20   ` Fabio M. De Francesco
2022-03-22  8:48 ` Greg Kroah-Hartman
2022-03-22  8:49 ` Dan Carpenter
2022-03-22  8:55   ` Dan Carpenter
2022-03-22  9:09   ` Fabio M. De Francesco
2022-03-29 17:00 ` Fabio M. De Francesco
2022-03-29 17:46   ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.