[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <zjk3vnydp2yip343khmkq7v5vqbib6d6eyee6tx6h5nph4blzn@c26yrw2cqrt7>
Date: Fri, 12 Apr 2024 19:47:43 +0200
From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Raag Jadav <raag.jadav@...el.com>, linux-kernel@...r.kernel.org, kernel@...gutronix.de,
"Rafael J. Wysocki" <rafael@...nel.org>
Subject: Re: [PATCH] driver core: Make dev_err_probe() silent for -ENOMEM
Hello,
On Fri, Apr 12, 2024 at 08:07:29PM +0300, Andy Shevchenko wrote:
> On Fri, Apr 12, 2024 at 07:03:01PM +0200, Uwe Kleine-König wrote:
> > On Fri, Apr 12, 2024 at 07:51:48PM +0300, Andy Shevchenko wrote:
> > > On Fri, Apr 12, 2024 at 06:44:05PM +0200, Uwe Kleine-König wrote:
> > > > For an out-of-memory error there should be no additional output. Adapt
> > > > dev_err_probe() to not emit the error message when err is -ENOMEM.
> > > > This simplifies handling errors that might among others be -ENOMEM.
>
> > > ...
> > >
> > > BUILD_BUG_ON(err == -ENOMEM);
> > >
> > > Done!
> >
> > Well no, that doesn't do the trick. Consider for example device_add().
> > That function can return (at least) -EINVAL and -ENOMEM. To properly
> > ensure that the error handling is silent with the current
> > dev_err_probe(), we'd need to do:
> >
> > ret = device_add(...);
> > if (ret) {
> > if (ret != -ENOMEM)
> > return dev_err_probe(...);
> > else
> > return ret;
> > }
> >
> > With my suggested patch this can be reduced to:
> >
> > ret = device_add(...);
> > if (ret)
> > return dev_err_probe(...);
>
> Fair enough, but these two should be combined.
> Mine is for the rejecting a dead code on the phase of the submission.
So something like the following on top of my change (only compile
tested):
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 0bc04dcf31d5..02b6ec9a26c1 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -5033,7 +5033,7 @@ define_dev_printk_level(_dev_info, KERN_INFO);
*
* Returns @err.
*/
-int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
+int __dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
@@ -5064,7 +5064,7 @@ int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
return err;
}
-EXPORT_SYMBOL_GPL(dev_err_probe);
+EXPORT_SYMBOL_GPL(__dev_err_probe);
static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
{
diff --git a/include/linux/dev_printk.h b/include/linux/dev_printk.h
index 6bfe70decc9f..a7573355ff90 100644
--- a/include/linux/dev_printk.h
+++ b/include/linux/dev_printk.h
@@ -14,6 +14,7 @@
#include <linux/compiler.h>
#include <linux/types.h>
#include <linux/ratelimit.h>
+#include <linux/build_bug.h>
#ifndef dev_fmt
#define dev_fmt(fmt) fmt
@@ -274,6 +275,7 @@ do { \
WARN_ONCE(condition, "%s %s: " format, \
dev_driver_string(dev), dev_name(dev), ## arg)
-__printf(3, 4) int dev_err_probe(const struct device *dev, int err, const char *fmt, ...);
+__printf(3, 4) int __dev_err_probe(const struct device *dev, int err, const char *fmt, ...);
+#define dev_err_probe(dev, err, ...) ( { BUILD_BUG_ON(__builtin_constant_p(err) && err == -ENOMEM); __dev_err_probe((dev), (err), __VA_ARGS__); })
#endif /* _DEVICE_PRINTK_H_ */
I don't know if the kernel doc for dev_err_probe() should move to
include/linux/dev_printk.h then?!
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists