mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH v7 1/4] driver core: add device probe log helper
@ 2020-06-29 16:38 Andy Shevchenko
       [not found] ` <CGME20200702134434eucas1p233a3f66f5bdb4b97f4f49d2d43d45297@eucas1p2.samsung.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2020-06-29 16:38 UTC (permalink / raw)
  To: Andrzej Hajda
  Cc: Greg Kroah-Hartman, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
	Rafael J. Wysocki, Linux Kernel Mailing List,
	linux-arm Mailing List, Mark Brown, Russell King - ARM Linux,
	Neil Armstrong, Laurent Pinchart, Jonas Karlman, Jernej Skrabec,
	Daniel Vetter, open list:DRM DRIVERS

On Mon, Jun 29, 2020 at 2:22 PM Andrzej Hajda <a.hajda@samsung.com> wrote:
>
> 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 omitted or implemented only
> partially.
> dev_err_probe helps to replace such code sequences with simple call,
> so code:
>         if (err != -EPROBE_DEFER)
>                 dev_err(dev, ...);
>         return err;
> becomes:
>         return dev_err_probe(dev, err, ...);

FWIW,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

(I'm fine with current code, though, consider below comments)

> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
> Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
> ---
>  drivers/base/core.c    | 42 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/device.h |  3 +++
>  2 files changed, 45 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 67d39a90b45c..3a827c82933f 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3953,6 +3953,48 @@ define_dev_printk_level(_dev_info, KERN_INFO);
>
>  #endif
>
> +/**
> + * dev_err_probe - 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 debug or error message depending if the error value is
> + * -EPROBE_DEFER and propagate error upwards.
> + * It replaces code sequence:
> + *     if (err != -EPROBE_DEFER)
> + *             dev_err(dev, ...);
> + *     else
> + *             dev_dbg(dev, ...);
> + *     return err;
> + * with
> + *     return dev_err_probe(dev, err, ...);
> + *
> + * Returns @err.
> + *
> + */
> +int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
> +{
> +       struct va_format vaf;
> +       va_list args;
> +
> +       va_start(args, fmt);
> +       vaf.fmt = fmt;
> +       vaf.va = &args;
> +
> +       if (err != -EPROBE_DEFER)

Perhaps positive conditional.

> +               dev_err(dev, "error %d: %pV", err, &vaf);
> +       else
> +               dev_dbg(dev, "error %d: %pV", err, &vaf);

Perhaps {} to be added here.

> +
> +       va_end(args);
> +
> +       return err;
> +}
> +EXPORT_SYMBOL_GPL(dev_err_probe);
> +
>  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 15460a5ac024..6b2272ae9af8 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -964,6 +964,9 @@ void device_link_remove(void *consumer, struct device *supplier);
>  void device_links_supplier_sync_state_pause(void);
>  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, ...);
> +
>  /* Create alias, so I can be autoloaded. */
>  #define MODULE_ALIAS_CHARDEV(major,minor) \
>         MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
> --
> 2.17.1
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-07-10 17:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200710153023eucas1p152c48e4208bff8c0ae9b8c734be45db2@eucas1p1.samsung.com>
2020-07-10 15:30 ` [PATCH v8 0/5] driver core: add probe error check helper Andrzej Hajda
     [not found]   ` <CGME20200710153023eucas1p1564ece8b49581616a5bfed978a5164f0@eucas1p1.samsung.com>
2020-07-10 15:30     ` [PATCH v8 1/5] driver core: add device probe log helper Andrzej Hajda
     [not found]   ` <CGME20200710153024eucas1p1b0686b4acce78838db93fddb3c23939c@eucas1p1.samsung.com>
2020-07-10 15:30     ` [PATCH v8 2/5] driver core: add deferring probe reason to devices_deferred property Andrzej Hajda
2020-07-10 17:15       ` Ruhl, Michael J
     [not found]   ` <CGME20200710153025eucas1p141ae47938b5f41c835759e7345f0e625@eucas1p1.samsung.com>
2020-07-10 15:30     ` [PATCH v8 3/5] drm/bridge/sii8620: fix resource acquisition error handling Andrzej Hajda
     [not found]   ` <CGME20200710153026eucas1p208e5850ddd9e7f376c4d56f892b05233@eucas1p2.samsung.com>
2020-07-10 15:30     ` [PATCH v8 4/5] drm/bridge: lvds-codec: simplify " Andrzej Hajda
     [not found]   ` <CGME20200710153027eucas1p1c893327b918e99a9b0cbd7b0a00af96b@eucas1p1.samsung.com>
2020-07-10 15:30     ` [PATCH v8 5/5] coccinelle: add script looking for cases where probe__err can be used Andrzej Hajda
2020-06-29 16:38 [PATCH v7 1/4] driver core: add device probe log helper Andy Shevchenko
     [not found] ` <CGME20200702134434eucas1p233a3f66f5bdb4b97f4f49d2d43d45297@eucas1p2.samsung.com>
2020-07-02 13:44   ` [PATCH v8 2/5] driver core: add deferring probe reason to devices_deferred property Andrzej Hajda
2020-07-10 13:31     ` Greg Kroah-Hartman
2020-07-10 15:25       ` Andrzej Hajda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®