diff mbox series

[v1,1/4] driver core: Ignore 0 in dev_err_probe()

Message ID 20240821122233.3761645-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State Changes Requested, archived
Headers show
Series platform/x86: int3472: A few cleanups | expand

Commit Message

Andy Shevchenko Aug. 21, 2024, 12:20 p.m. UTC
In the similar way, ignore 0 error code (AKA "success") in
dev_err_probe(). This helps to simplify a code such as

  if (ret < 0)
    return dev_err_probe(int3472->dev, ret, err_msg);

  return ret;

to

  return dev_err_probe(int3472->dev, ret, err_msg);

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/base/core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Ilpo Järvinen Aug. 21, 2024, 12:38 p.m. UTC | #1
On Wed, 21 Aug 2024, Andy Shevchenko wrote:

> In the similar way, ignore 0 error code (AKA "success") in
> dev_err_probe(). This helps to simplify a code such as
> 
>   if (ret < 0)
>     return dev_err_probe(int3472->dev, ret, err_msg);
> 
>   return ret;
> 
> to
> 
>   return dev_err_probe(int3472->dev, ret, err_msg);
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/base/core.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 6d3897492285..144cb8c201fb 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -5046,6 +5046,10 @@ int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
>  		 */
>  		break;
>  
> +	case 0:
> +		/* Success, no need to issue an error message */
> +		break;
> +
>  	default:
>  		dev_err(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
>  		break;
> 

This seems generally useful,

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

A nit, the code sequence that dev_err_probe() is documented to replace is 
no longer matches with the behavior (the else would need if (err < 0) 
added).
Andy Shevchenko Aug. 21, 2024, 1:12 p.m. UTC | #2
On Wed, Aug 21, 2024 at 03:38:15PM +0300, Ilpo Järvinen wrote:
> On Wed, 21 Aug 2024, Andy Shevchenko wrote:
> 
> > In the similar way, ignore 0 error code (AKA "success") in
> > dev_err_probe(). This helps to simplify a code such as
> > 
> >   if (ret < 0)
> >     return dev_err_probe(int3472->dev, ret, err_msg);
> > 
> >   return ret;
> > 
> > to
> > 
> >   return dev_err_probe(int3472->dev, ret, err_msg);

...

> This seems generally useful,
> 
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

Thanks!

> A nit, the code sequence that dev_err_probe() is documented to replace is 
> no longer matches with the behavior (the else would need if (err < 0) 
> added).

Okay, let's wait what Greg says about it, if he is okay with the proposal,
I'll amend documentation as well in v2.
Greg KH Aug. 21, 2024, 11:32 p.m. UTC | #3
On Wed, Aug 21, 2024 at 04:12:22PM +0300, Andy Shevchenko wrote:
> On Wed, Aug 21, 2024 at 03:38:15PM +0300, Ilpo Järvinen wrote:
> > On Wed, 21 Aug 2024, Andy Shevchenko wrote:
> > 
> > > In the similar way, ignore 0 error code (AKA "success") in
> > > dev_err_probe(). This helps to simplify a code such as
> > > 
> > >   if (ret < 0)
> > >     return dev_err_probe(int3472->dev, ret, err_msg);
> > > 
> > >   return ret;
> > > 
> > > to
> > > 
> > >   return dev_err_probe(int3472->dev, ret, err_msg);
> 
> ...
> 
> > This seems generally useful,
> > 
> > Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> Thanks!
> 
> > A nit, the code sequence that dev_err_probe() is documented to replace is 
> > no longer matches with the behavior (the else would need if (err < 0) 
> > added).
> 
> Okay, let's wait what Greg says about it, if he is okay with the proposal,
> I'll amend documentation as well in v2.

I like it, and will be glad to take it if you update the documentation :)

thanks,

greg k-h
Andy Shevchenko Aug. 22, 2024, 12:45 p.m. UTC | #4
On Thu, Aug 22, 2024 at 07:32:33AM +0800, Greg Kroah-Hartman wrote:
> On Wed, Aug 21, 2024 at 04:12:22PM +0300, Andy Shevchenko wrote:

...

> I like it, and will be glad to take it if you update the documentation :)

Consider it done.

Thanks!
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6d3897492285..144cb8c201fb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -5046,6 +5046,10 @@  int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
 		 */
 		break;
 
+	case 0:
+		/* Success, no need to issue an error message */
+		break;
+
 	default:
 		dev_err(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
 		break;