diff mbox series

[v1,1/2] driver core: add a wrapper to device probe log helper to return pointer

Message ID 20220214143248.502-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v1,1/2] driver core: add a wrapper to device probe log helper to return pointer | expand

Commit Message

Andy Shevchenko Feb. 14, 2022, 2:32 p.m. UTC
Sometimes the ->probe() function can be split to the core and actual probe
parts. In such cases the core one may return a pointer to the allocated
resource, or error pointer in unsuccessful scenario. Allow that kind of
core function to use dev_err_probe_ptr(), so the following excerpt

	ret = bar(...);
	if (ret) {
		dev_err_probe(dev, ret, ...);
		return ERR_PTR(ret);
	}

can be replaced with

	ret = bar(...);
	if (ret)
		return dev_err_probe_ptr(dev, ret, ...);

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/device.h | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Geert Uytterhoeven Feb. 14, 2022, 2:57 p.m. UTC | #1
Hi Andy,

On Mon, Feb 14, 2022 at 3:33 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Instead of
>         return ERR_PTR(dev_err_probe(...));
> call
>         return dev_err_probe_ptr(...);
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks for your patch!

> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -3199,8 +3199,7 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev,
>
>         rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
>         if (IS_ERR(rstc))
> -               return ERR_PTR(dev_err_probe(&pdev->dev, PTR_ERR(rstc),
> -                                            "failed to get reset ctrl\n"));
> +               return dev_err_probe_ptr(&pdev->dev, PTR_ERR(rstc), "failed to get reset ctrl\n");

I think the joined line is too long, so please keep it split.

drivers/tty/serial/sh-sci.c:3824:10: error: too few arguments to
function ‘dev_err_probe_ptr’

Indeed, dev_err_probe_ptr() is not a varargs function.
BTW, I do like the general idea.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox series

Patch

diff --git a/include/linux/device.h b/include/linux/device.h
index 93459724dcde..8650d3afbe7c 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -14,6 +14,7 @@ 
 
 #include <linux/dev_printk.h>
 #include <linux/energy_model.h>
+#include <linux/err.h>
 #include <linux/ioport.h>
 #include <linux/kobject.h>
 #include <linux/klist.h>
@@ -982,6 +983,13 @@  void device_links_supplier_sync_state_resume(void);
 extern __printf(3, 4)
 int dev_err_probe(const struct device *dev, int err, const char *fmt, ...);
 
+/* As above, but returns error pointer */
+static inline __printf(3, 0)
+void *dev_err_probe_ptr(const struct device *dev, int err, const char *fmt, va_list args)
+{
+	return ERR_PTR(dev_err_probe(dev, err, fmt, args));
+}
+
 /* Create alias, so I can be autoloaded. */
 #define MODULE_ALIAS_CHARDEV(major,minor) \
 	MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))