From: Andrzej Hajda <a.hajda@samsung.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrzej Hajda <a.hajda@samsung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
linux-kernel@vger.kernel.org,
Javier Martinez Canillas <javierm@redhat.com>,
linux-arm-kernel@lists.infradead.org, andy.shevchenko@gmail.com,
Mark Brown <broonie@kernel.org>,
Russell King - ARM Linux <linux@armlinux.org.uk>
Subject: [PATCH v4 1/3] driver core: add probe_err log helper
Date: Thu, 20 Dec 2018 11:22:45 +0100 [thread overview]
Message-ID: <20181220102247.4911-2-a.hajda@samsung.com> (raw)
In-Reply-To: <20181220102247.4911-1-a.hajda@samsung.com>
During probe every time driver gets resource it should usually check for error
printk some message if it is not -EPROBE_DEFER and return the error. This
pattern is simple but requires adding few lines after any resource acquisition
code, as a result it is often omited or implemented only partially.
probe_err helps to replace such code sequences with simple call, so code:
if (err != -EPROBE_DEFER)
dev_err(dev, ...);
return err;
becomes:
return probe_err(dev, err, ...);
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
v3:
- added 'extern __printf(3, 4)' decorators to probe_err,
- changed error logging format - newline at the end,
- added empty lines in probe_err around dev_err,
- added R-b by Mark and Andy.
v2:
- added error value to log message,
- fixed code style,
- added EXPORT_SYMBOL_GPL,
- Added R-B by Javier (I hope the changes did not invalidate it).
---
drivers/base/core.c | 39 +++++++++++++++++++++++++++++++++++++++
include/linux/device.h | 3 +++
2 files changed, 42 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 0073b09bb99f..7f644f3c41d3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3099,6 +3099,45 @@ define_dev_printk_level(_dev_info, KERN_INFO);
#endif
+/**
+ * probe_err - probe error check and log helper
+ * @dev: the pointer to the struct device
+ * @err: error value to test
+ * @fmt: printf-style format string
+ * @...: arguments as specified in the format string
+ *
+ * This helper implements common pattern present in probe functions for error
+ * checking: print message if the error is not -EPROBE_DEFER and propagate it.
+ * It replaces code sequence:
+ * if (err != -EPROBE_DEFER)
+ * dev_err(dev, ...);
+ * return err;
+ * with
+ * return probe_err(dev, err, ...);
+ *
+ * Returns @err.
+ *
+ */
+int probe_err(const struct device *dev, int err, const char *fmt, ...)
+{
+ struct va_format vaf;
+ va_list args;
+
+ if (err == -EPROBE_DEFER)
+ return err;
+
+ va_start(args, fmt);
+ vaf.fmt = fmt;
+ vaf.va = &args;
+
+ dev_err(dev, "error %d: %pV", err, &vaf);
+
+ va_end(args);
+
+ return err;
+}
+EXPORT_SYMBOL_GPL(probe_err);
+
static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
{
return fwnode && !IS_ERR(fwnode->secondary);
diff --git a/include/linux/device.h b/include/linux/device.h
index 6cb4640b6160..2d3a1cc6f5da 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1591,6 +1591,9 @@ do { \
WARN_ONCE(condition, "%s %s: " format, \
dev_driver_string(dev), dev_name(dev), ## arg)
+extern __printf(3, 4)
+int probe_err(const struct device *dev, int err, const char *fmt, ...);
+
/* Create alias, so I can be autoloaded. */
#define MODULE_ALIAS_CHARDEV(major,minor) \
MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
--
2.17.1
next prev parent reply other threads:[~2018-12-20 10:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20181220102258eucas1p1ca5abb0b48d1f13d9234a4a7702a13da@eucas1p1.samsung.com>
2018-12-20 10:22 ` [PATCH v4 0/3] driver core: add probe error check helper Andrzej Hajda
[not found] ` <CGME20181220102259eucas1p2f748c68e01cd4e09a266da879722e218@eucas1p2.samsung.com>
2018-12-20 10:22 ` Andrzej Hajda [this message]
2018-12-20 10:35 ` [PATCH v4 1/3] driver core: add probe_err log helper Rafael J. Wysocki
2018-12-20 11:14 ` Greg Kroah-Hartman
2018-12-20 11:37 ` Andrzej Hajda
2018-12-21 22:47 ` Rob Herring
2018-12-22 7:24 ` [PATCH] driver core: platform: Add an error message to platform_get_irq*() Stephen Boyd
2018-12-22 10:33 ` Russell King - ARM Linux
2018-12-28 21:53 ` Stephen Boyd
2018-12-24 9:29 ` [PATCH v4 1/3] driver core: add probe_err log helper Andrzej Hajda
2018-12-28 21:56 ` [PATCH v2] driver core: platform: Add an error message to platform_get_irq*() Stephen Boyd
2018-12-30 10:42 ` Andy Shevchenko
2019-01-02 18:17 ` Stephen Boyd
2019-01-02 18:51 ` [PATCH v3] " Stephen Boyd
2019-01-03 9:40 ` Rafael J. Wysocki
2019-01-03 16:11 ` Stephen Boyd
2019-01-03 17:22 ` Rafael J. Wysocki
2019-01-03 17:25 ` Stephen Boyd
2019-01-03 17:38 ` Rafael J. Wysocki
2019-01-03 17:51 ` Andy Shevchenko
[not found] ` <CGME20181220102259eucas1p1884a0b68ce342239c2a43a74cc50725a@eucas1p1.samsung.com>
2018-12-20 10:22 ` [PATCH v4 2/3] driver core: add deferring probe reason to devices_deferred property Andrzej Hajda
2018-12-20 11:04 ` Rafael J. Wysocki
2018-12-20 12:27 ` Andrzej Hajda
2018-12-20 11:12 ` Greg Kroah-Hartman
2018-12-20 11:51 ` Andrzej Hajda
[not found] ` <CGME20181220102300eucas1p210735c7753688a52a73ccf026884dd11@eucas1p2.samsung.com>
2018-12-20 10:22 ` [PATCH v4 3/3] driver core: add probe_err_ptr helper Andrzej Hajda
2018-12-20 11:05 ` Rafael J. Wysocki
2018-12-20 11:14 ` Greg Kroah-Hartman
[not found] ` <CGME20181221083246eucas1p22cade911a455344d351db6060d39ddce@eucas1p2.samsung.com>
2018-12-21 8:32 ` [PATCH] PCI: pcie-rockchip: use probe_err helpers instead of open coding Andrzej Hajda
2018-12-22 5:42 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181220102247.4911-2-a.hajda@samsung.com \
--to=a.hajda@samsung.com \
--cc=andy.shevchenko@gmail.com \
--cc=b.zolnierkie@samsung.com \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=javierm@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome