[4/6] bus: fsl-mc: fsl-mc-allocator: Improve error reporting

Message ID 20230310224128.2638078-5-u.kleine-koenig@pengutronix.de
State New
Headers
Series bus: fsl-mc: Make remove function return void |

Commit Message

Uwe Kleine-König March 10, 2023, 10:41 p.m. UTC
  Instead of silently returning an error in the remove callback (which yields
a generic and little informing error message), annotate each error path of
fsl_mc_resource_pool_remove_device() with an error message and return zero
in the remove callback to suppress the error message.

Note that changing the return value has no other effect than suppressing
the error message by the fsl_mc bus driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
  

Comments

Nathan Chancellor June 1, 2023, 3:41 p.m. UTC | #1
Hi Uwe,

On Fri, Mar 10, 2023 at 11:41:26PM +0100, Uwe Kleine-König wrote:
> Instead of silently returning an error in the remove callback (which yields
> a generic and little informing error message), annotate each error path of
> fsl_mc_resource_pool_remove_device() with an error message and return zero
> in the remove callback to suppress the error message.
> 
> Note that changing the return value has no other effect than suppressing
> the error message by the fsl_mc bus driver.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

I apologize if this has already been reported or fixed somewhere, I did
a search of lore.kernel.org and did not find anything. This change as
commit b3134039c5b3 ("bus: fsl-mc: fsl-mc-allocator: Improve error
reporting") causes the following warning/error with clang:

  drivers/bus/fsl-mc/fsl-mc-allocator.c:108:12: error: variable 'mc_bus_dev' is uninitialized when used here [-Werror,-Wuninitialized]
    108 |                 dev_err(&mc_bus_dev->dev, "resource mismatch\n");
        |                          ^~~~~~~~~~
  include/linux/dev_printk.h:144:44: note: expanded from macro 'dev_err'
    144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
        |                                                   ^~~
  include/linux/dev_printk.h:110:11: note: expanded from macro 'dev_printk_index_wrap'
    110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
        |                         ^~~
  drivers/bus/fsl-mc/fsl-mc-allocator.c:100:34: note: initialize the variable 'mc_bus_dev' to silence this warning
    100 |         struct fsl_mc_device *mc_bus_dev;
        |                                         ^
        |                                          = NULL
  1 error generated.

Should this be using mc_dev->dev or is there a different fix?

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index 0ad68099684e..867ac3bbeae6 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -105,7 +105,7 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
 
 	resource = mc_dev->resource;
 	if (!resource || resource->data != mc_dev) {
-		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
+		dev_err(&mc_dev->dev, "resource mismatch\n");
 		goto out;
 	}
 

Cheers,
Nathan

> ---
>  drivers/bus/fsl-mc/fsl-mc-allocator.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> index e60faf8edaa1..36f70e5e418b 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> @@ -104,22 +104,30 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
>  	int error = -EINVAL;
>  
>  	resource = mc_dev->resource;
> -	if (!resource || resource->data != mc_dev)
> +	if (!resource || resource->data != mc_dev) {
> +		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
>  		goto out;
> +	}
>  
>  	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
>  	mc_bus = to_fsl_mc_bus(mc_bus_dev);
>  	res_pool = resource->parent_pool;
> -	if (res_pool != &mc_bus->resource_pools[resource->type])
> +	if (res_pool != &mc_bus->resource_pools[resource->type]) {
> +		dev_err(&mc_bus_dev->dev, "pool mismatch\n");
>  		goto out;
> +	}
>  
>  	mutex_lock(&res_pool->mutex);
>  
> -	if (res_pool->max_count <= 0)
> +	if (res_pool->max_count <= 0) {
> +		dev_err(&mc_bus_dev->dev, "max_count underflow\n");
>  		goto out_unlock;
> +	}
>  	if (res_pool->free_count <= 0 ||
> -	    res_pool->free_count > res_pool->max_count)
> +	    res_pool->free_count > res_pool->max_count) {
> +		dev_err(&mc_bus_dev->dev, "free_count mismatch\n");
>  		goto out_unlock;
> +	}
>  
>  	/*
>  	 * If the device is currently allocated, its resource is not
> @@ -613,7 +621,7 @@ static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
>  	if (mc_dev->resource) {
>  		error = fsl_mc_resource_pool_remove_device(mc_dev);
>  		if (error < 0)
> -			return error;
> +			return 0;
>  	}
>  
>  	dev_dbg(&mc_dev->dev,
> -- 
> 2.39.1
>
  
Uwe Kleine-König June 1, 2023, 4:59 p.m. UTC | #2
Hello,

On Thu, Jun 01, 2023 at 08:41:01AM -0700, Nathan Chancellor wrote:
> On Fri, Mar 10, 2023 at 11:41:26PM +0100, Uwe Kleine-König wrote:
> > Instead of silently returning an error in the remove callback (which yields
> > a generic and little informing error message), annotate each error path of
> > fsl_mc_resource_pool_remove_device() with an error message and return zero
> > in the remove callback to suppress the error message.
> > 
> > Note that changing the return value has no other effect than suppressing
> > the error message by the fsl_mc bus driver.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> I apologize if this has already been reported or fixed somewhere, I did
> a search of lore.kernel.org and did not find anything. This change as
> commit b3134039c5b3 ("bus: fsl-mc: fsl-mc-allocator: Improve error
> reporting") causes the following warning/error with clang:
> 
>   drivers/bus/fsl-mc/fsl-mc-allocator.c:108:12: error: variable 'mc_bus_dev' is uninitialized when used here [-Werror,-Wuninitialized]
>     108 |                 dev_err(&mc_bus_dev->dev, "resource mismatch\n");
>         |                          ^~~~~~~~~~
>   include/linux/dev_printk.h:144:44: note: expanded from macro 'dev_err'
>     144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
>         |                                                   ^~~
>   include/linux/dev_printk.h:110:11: note: expanded from macro 'dev_printk_index_wrap'
>     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
>         |                         ^~~
>   drivers/bus/fsl-mc/fsl-mc-allocator.c:100:34: note: initialize the variable 'mc_bus_dev' to silence this warning
>     100 |         struct fsl_mc_device *mc_bus_dev;
>         |                                         ^
>         |                                          = NULL
>   1 error generated.
> 
> Should this be using mc_dev->dev or is there a different fix?
> 
> diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> index 0ad68099684e..867ac3bbeae6 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> @@ -105,7 +105,7 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
>  
>  	resource = mc_dev->resource;
>  	if (!resource || resource->data != mc_dev) {
> -		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
> +		dev_err(&mc_dev->dev, "resource mismatch\n");
>  		goto out;
>  	}

Hmm, clang seems to be right, and I just confirmed that gcc
(arm-linux-gnueabihf-gcc (Debian 12.2.0-14) 12.2.0) doesn't emit a
warning. :-\

My approach would be:

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index 0ad68099684e..991273f956ce 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -103,14 +103,15 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
 	struct fsl_mc_resource *resource;
 	int error = -EINVAL;
 
+	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
+	mc_bus = to_fsl_mc_bus(mc_bus_dev);
+
 	resource = mc_dev->resource;
 	if (!resource || resource->data != mc_dev) {
 		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
 		goto out;
 	}
 
-	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
-	mc_bus = to_fsl_mc_bus(mc_bus_dev);
 	res_pool = resource->parent_pool;
 	if (res_pool != &mc_bus->resource_pools[resource->type]) {
 		dev_err(&mc_bus_dev->dev, "pool mismatch\n");


Should I prepare a proper patch, or is it possible to squash this change
into b3134039c5b3cf879841e3ec84c8cbf7675554ec?

@Li Yang: Please advice.

Best regards
Uwe
  
Li Yang June 8, 2023, 10 p.m. UTC | #3
> -----Original Message-----
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Sent: Thursday, June 1, 2023 12:00 PM
> To: Nathan Chancellor <nathan@kernel.org>; Leo Li <leoyang.li@nxp.com>
> Cc: Stuart Yoder <stuyoder@gmail.com>; llvm@lists.linux.dev; linux-
> kernel@vger.kernel.org; kernel@pengutronix.de; Laurentiu Tudor
> <laurentiu.tudor@nxp.com>
> Subject: Re: [PATCH 4/6] bus: fsl-mc: fsl-mc-allocator: Improve error
> reporting
> 
> Hello,
> 
> On Thu, Jun 01, 2023 at 08:41:01AM -0700, Nathan Chancellor wrote:
> > On Fri, Mar 10, 2023 at 11:41:26PM +0100, Uwe Kleine-König wrote:
> > > Instead of silently returning an error in the remove callback (which
> > > yields a generic and little informing error message), annotate each
> > > error path of
> > > fsl_mc_resource_pool_remove_device() with an error message and
> > > return zero in the remove callback to suppress the error message.
> > >
> > > Note that changing the return value has no other effect than
> > > suppressing the error message by the fsl_mc bus driver.
> > >
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> >
> > I apologize if this has already been reported or fixed somewhere, I
> > did a search of lore.kernel.org and did not find anything. This change
> > as commit b3134039c5b3 ("bus: fsl-mc: fsl-mc-allocator: Improve error
> > reporting") causes the following warning/error with clang:
> >
> >   drivers/bus/fsl-mc/fsl-mc-allocator.c:108:12: error: variable 'mc_bus_dev'
> is uninitialized when used here [-Werror,-Wuninitialized]
> >     108 |                 dev_err(&mc_bus_dev->dev, "resource mismatch\n");
> >         |                          ^~~~~~~~~~
> >   include/linux/dev_printk.h:144:44: note: expanded from macro 'dev_err'
> >     144 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev,
> dev_fmt(fmt), ##__VA_ARGS__)
> >         |                                                   ^~~
> >   include/linux/dev_printk.h:110:11: note: expanded from macro
> 'dev_printk_index_wrap'
> >     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
> >         |                         ^~~
> >   drivers/bus/fsl-mc/fsl-mc-allocator.c:100:34: note: initialize the variable
> 'mc_bus_dev' to silence this warning
> >     100 |         struct fsl_mc_device *mc_bus_dev;
> >         |                                         ^
> >         |                                          = NULL
> >   1 error generated.
> >
> > Should this be using mc_dev->dev or is there a different fix?
> >
> > diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > index 0ad68099684e..867ac3bbeae6 100644
> > --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > @@ -105,7 +105,7 @@ static int __must_check
> > fsl_mc_resource_pool_remove_device(struct fsl_mc_device
> >
> >  	resource = mc_dev->resource;
> >  	if (!resource || resource->data != mc_dev) {
> > -		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
> > +		dev_err(&mc_dev->dev, "resource mismatch\n");
> >  		goto out;
> >  	}
> 
> Hmm, clang seems to be right, and I just confirmed that gcc (arm-linux-
> gnueabihf-gcc (Debian 12.2.0-14) 12.2.0) doesn't emit a warning. :-\
> 
> My approach would be:
> 
> diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-
> allocator.c
> index 0ad68099684e..991273f956ce 100644
> --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> @@ -103,14 +103,15 @@ static int __must_check
> fsl_mc_resource_pool_remove_device(struct fsl_mc_device
>  	struct fsl_mc_resource *resource;
>  	int error = -EINVAL;
> 
> +	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> +	mc_bus = to_fsl_mc_bus(mc_bus_dev);
> +
>  	resource = mc_dev->resource;
>  	if (!resource || resource->data != mc_dev) {
>  		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
>  		goto out;
>  	}
> 
> -	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> -	mc_bus = to_fsl_mc_bus(mc_bus_dev);
>  	res_pool = resource->parent_pool;
>  	if (res_pool != &mc_bus->resource_pools[resource->type]) {
>  		dev_err(&mc_bus_dev->dev, "pool mismatch\n");
> 
> 
> Should I prepare a proper patch, or is it possible to squash this change into
> b3134039c5b3cf879841e3ec84c8cbf7675554ec?
> 
> @Li Yang: Please advice.

This looks fine.  Please send a new patch and I can squash it to the original commit.

Regards,
Leo
  
Uwe Kleine-König June 8, 2023, 10:53 p.m. UTC | #4
Hello,

On Thu, Jun 08, 2023 at 10:00:13PM +0000, Leo Li wrote:
> > Hmm, clang seems to be right, and I just confirmed that gcc (arm-linux-
> > gnueabihf-gcc (Debian 12.2.0-14) 12.2.0) doesn't emit a warning. :-\
> > 
> > My approach would be:
> > 
> > diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-
> > allocator.c
> > index 0ad68099684e..991273f956ce 100644
> > --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > @@ -103,14 +103,15 @@ static int __must_check
> > fsl_mc_resource_pool_remove_device(struct fsl_mc_device
> >  	struct fsl_mc_resource *resource;
> >  	int error = -EINVAL;
> > 
> > +	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> > +	mc_bus = to_fsl_mc_bus(mc_bus_dev);
> > +
> >  	resource = mc_dev->resource;
> >  	if (!resource || resource->data != mc_dev) {
> >  		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
> >  		goto out;
> >  	}
> > 
> > -	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> > -	mc_bus = to_fsl_mc_bus(mc_bus_dev);
> >  	res_pool = resource->parent_pool;
> >  	if (res_pool != &mc_bus->resource_pools[resource->type]) {
> >  		dev_err(&mc_bus_dev->dev, "pool mismatch\n");
> > 
> > 
> > Should I prepare a proper patch, or is it possible to squash this change into
> > b3134039c5b3cf879841e3ec84c8cbf7675554ec?
> > 
> > @Li Yang: Please advice.
> 
> This looks fine.  Please send a new patch and I can squash it to the original commit.

I did send a proper patch already, see 

	https://lore.kernel.org/all/20230605112025.80061-1-u.kleine-koenig@pengutronix.de

You can apply that on top of the broken commit, or if you prefer also
squash it into the offending commit. Note that in the above thread there
is another fix for an older commit.

Best regards
Uwe
  
Li Yang June 8, 2023, 11:10 p.m. UTC | #5
> -----Original Message-----
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Sent: Thursday, June 8, 2023 5:54 PM
> To: Leo Li <leoyang.li@nxp.com>
> Cc: Nathan Chancellor <nathan@kernel.org>; kernel@pengutronix.de;
> llvm@lists.linux.dev; linux-kernel@vger.kernel.org; Stuart Yoder
> <stuyoder@gmail.com>; Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Subject: Re: [PATCH 4/6] bus: fsl-mc: fsl-mc-allocator: Improve error
> reporting
> 
> Hello,
> 
> On Thu, Jun 08, 2023 at 10:00:13PM +0000, Leo Li wrote:
> > > Hmm, clang seems to be right, and I just confirmed that gcc
> > > (arm-linux- gnueabihf-gcc (Debian 12.2.0-14) 12.2.0) doesn't emit a
> > > warning. :-\
> > >
> > > My approach would be:
> > >
> > > diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > > b/drivers/bus/fsl-mc/fsl-mc- allocator.c index
> > > 0ad68099684e..991273f956ce 100644
> > > --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > > +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
> > > @@ -103,14 +103,15 @@ static int __must_check
> > > fsl_mc_resource_pool_remove_device(struct fsl_mc_device
> > >  	struct fsl_mc_resource *resource;
> > >  	int error = -EINVAL;
> > >
> > > +	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> > > +	mc_bus = to_fsl_mc_bus(mc_bus_dev);
> > > +
> > >  	resource = mc_dev->resource;
> > >  	if (!resource || resource->data != mc_dev) {
> > >  		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
> > >  		goto out;
> > >  	}
> > >
> > > -	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
> > > -	mc_bus = to_fsl_mc_bus(mc_bus_dev);
> > >  	res_pool = resource->parent_pool;
> > >  	if (res_pool != &mc_bus->resource_pools[resource->type]) {
> > >  		dev_err(&mc_bus_dev->dev, "pool mismatch\n");
> > >
> > >
> > > Should I prepare a proper patch, or is it possible to squash this
> > > change into b3134039c5b3cf879841e3ec84c8cbf7675554ec?
> > >
> > > @Li Yang: Please advice.
> >
> > This looks fine.  Please send a new patch and I can squash it to the original
> commit.
> 
> I did send a proper patch already, see
> 
> 	https://lore.kernel.org/all/20230605112025.80061-1-u.kleine-
> koenig@pengutronix.de
> 
> You can apply that on top of the broken commit, or if you prefer also squash
> it into the offending commit. Note that in the above thread there is another
> fix for an older commit.

Thanks.  Both look good.  Applied for next.

Regards,
Leo
  

Patch

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index e60faf8edaa1..36f70e5e418b 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -104,22 +104,30 @@  static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
 	int error = -EINVAL;
 
 	resource = mc_dev->resource;
-	if (!resource || resource->data != mc_dev)
+	if (!resource || resource->data != mc_dev) {
+		dev_err(&mc_bus_dev->dev, "resource mismatch\n");
 		goto out;
+	}
 
 	mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
 	mc_bus = to_fsl_mc_bus(mc_bus_dev);
 	res_pool = resource->parent_pool;
-	if (res_pool != &mc_bus->resource_pools[resource->type])
+	if (res_pool != &mc_bus->resource_pools[resource->type]) {
+		dev_err(&mc_bus_dev->dev, "pool mismatch\n");
 		goto out;
+	}
 
 	mutex_lock(&res_pool->mutex);
 
-	if (res_pool->max_count <= 0)
+	if (res_pool->max_count <= 0) {
+		dev_err(&mc_bus_dev->dev, "max_count underflow\n");
 		goto out_unlock;
+	}
 	if (res_pool->free_count <= 0 ||
-	    res_pool->free_count > res_pool->max_count)
+	    res_pool->free_count > res_pool->max_count) {
+		dev_err(&mc_bus_dev->dev, "free_count mismatch\n");
 		goto out_unlock;
+	}
 
 	/*
 	 * If the device is currently allocated, its resource is not
@@ -613,7 +621,7 @@  static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
 	if (mc_dev->resource) {
 		error = fsl_mc_resource_pool_remove_device(mc_dev);
 		if (error < 0)
-			return error;
+			return 0;
 	}
 
 	dev_dbg(&mc_dev->dev,