Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1142177imu; Thu, 20 Dec 2018 10:50:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/WgyCmnGZADw0LBJKLMRrxpzdPe+d+mANhdcrPdGt0/2rprJyvt0TDsa8tJvGIpZNmk80Ha X-Received: by 2002:a17:902:1101:: with SMTP id d1mr24850153pla.136.1545331825744; Thu, 20 Dec 2018 10:50:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545331825; cv=none; d=google.com; s=arc-20160816; b=TwKmckn/wKKb3osqATpLJj/XBO1UwmGHefoFX9ddznsdbmx04+SkswIizT7r6Bb+Lx tHad2WcP5+ipMGKqbD1c/LzN9KQ8b4KoLGwxvBY5FZspRrDFVoIsLw+fobRea9IxLY1W QZuLK4kY3NVAF+h5TQuB8l9CyKMudgg3VDOuoD/XrA1Seh0dl82Pz/m2Q6sPFyMdB94s PFpWRTqUwKnvedoSE7uoRiF8tLk00Zce9KeLXS+9E3Wv9JEf7mfzydVXsHg2Zz0WYjMT m1FUoe3lEtVi0zkIhIAXTITbL/J2S0Uw8sPhifCVeLeT+y0ThWSsQ6AL6vL8EsENIu5a 5d2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=eLCDsw0Ehg/InjXwwxdbQFCOnNOo69hsIb55rOLFQHM=; b=Bia5zNA6wMqJVGylYrh04GnTFvbVSIncz/CBWZcRaVnHQhre3DyCh2vI23+iSy+FTb mX5DH9YYkEnZ1jXN8WHbHNC4NIgw9dt65RU3/+ziPEqYIpu5IZ5cmkSCAmns7aRQffYw /2YlaxXQCWjdFm0w3AEcH9RD7rZA3GNi5jrBJJ4oX3+kK08UojqIJLSoq5bgLoWRdrlF AEsapF25sMSdi8qWu8mqB544VDXg9HBuQ4vXOcThK79J9tFFpZgP5lO0dmioaof1Lc3s CCUFJrsNTkTWlIGk/6ukprF3sR91Jjo5eOxoOqmwDp4RCyp2xj7WaCHnmVgOQ6otHKmh ddtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si18469355pgh.469.2018.12.20.10.50.10; Thu, 20 Dec 2018 10:50:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730940AbeLTKfj (ORCPT + 99 others); Thu, 20 Dec 2018 05:35:39 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:38013 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbeLTKfj (ORCPT ); Thu, 20 Dec 2018 05:35:39 -0500 Received: by mail-ot1-f66.google.com with SMTP id e12so1140500otl.5 for ; Thu, 20 Dec 2018 02:35:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eLCDsw0Ehg/InjXwwxdbQFCOnNOo69hsIb55rOLFQHM=; b=NxLTuiO/Z/97+H0otLLEiL7eFhmTG6K72tGNFqD1VGYOp+GH9vplfDrmgaW0iWQN6W XF3t5gwQxoj0XsWsZlBcXrQOuMAeVcEuzYqFWp64i5+aTsgYUgdh6WQfEkGuMd24uj+n sVhE8BRhIorwlwUU9TNq6DjFrz34Xc+2ETp/KXWqcBNRfd7EOOg8H3icNw/Lx+YKqeex A4kWU7uKnOzSLqLYt6dD48RCsFYtkbtrq3buljp1x/NPJyO1LkpdLj0SvmQsTTZ/PZC+ CJyAbSO3X9q//U90LkEwpJPvdXqcFjH88EvhKh8kDZupaiO8Oby1XbjxPyMuzZTSIxTV Jo7A== X-Gm-Message-State: AA+aEWamBOB9frcAtx8PFJwNfUXNmVjTpGEM0W40qRozVxB33wl0POS9 8UeYf/pnhJirI3TfK52rc6yi9SttA3r3zyd63Mc= X-Received: by 2002:a9d:588c:: with SMTP id x12mr18120855otg.139.1545302137597; Thu, 20 Dec 2018 02:35:37 -0800 (PST) MIME-Version: 1.0 References: <20181220102247.4911-1-a.hajda@samsung.com> <20181220102247.4911-2-a.hajda@samsung.com> In-Reply-To: <20181220102247.4911-2-a.hajda@samsung.com> From: "Rafael J. Wysocki" Date: Thu, 20 Dec 2018 11:35:26 +0100 Message-ID: Subject: Re: [PATCH v4 1/3] driver core: add probe_err log helper To: Andrzej Hajda Cc: Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz , Marek Szyprowski , "Rafael J. Wysocki" , Linux Kernel Mailing List , javierm@redhat.com, Linux ARM , Andy Shevchenko , Mark Brown , Russell King - ARM Linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 20, 2018 at 11:23 AM Andrzej Hajda 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 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 > Reviewed-by: Javier Martinez Canillas > Reviewed-by: Mark Brown > Reviewed-by: Andy Shevchenko I'm not entirely convinced that the dev_err() log level is adequate for this purpose, but anyway it looks like this may reduce code duplication quite a bit, so Reviewed-by: Rafael J. Wysocki > --- > 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 >