From patchwork Wed Oct 17 13:22:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10645615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E5CA15E2 for ; Wed, 17 Oct 2018 13:22:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF45F2B031 for ; Wed, 17 Oct 2018 13:22:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E19382B051; Wed, 17 Oct 2018 13:22:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 08AC42B031 for ; Wed, 17 Oct 2018 13:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-reply-to:Message-id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=171s1m5KSwHMRifqQh6se5u5GcXeep0KiBnSEy41ONA=; b=lpB/RXj+rjbDzS+uVnNnnTTwpT Kza5HVwmxNQx1EiUUkuRUjndc9pcsXAysn+A1NI2kmeZggnFonqeIEQNy3JyYvM/JBUXm0PM7q4Uk 5kOoMIM/hjBCZVUW/Qaxjtm1GcJndtCl844K+lDsGa35hwQHNIolJYpsELcKKfoN9/RJPNZAIzqGr AYcqsHE44rGBkBYYSYqGAjaNxgcbndXP3Pf/nHR/rLbI6ulHq0D0+hPRaLw8YjwNiyq86l8v48eYS UqiQXW2sfVzfiSusInaJ48Vrb4Vqh5DZCbqu8lHPQ3PztHiirsxFmFaqseKXNLMvi4Kx5AlXNUplv VEIgL9vg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gClmP-00056J-TR; Wed, 17 Oct 2018 13:22:29 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gClmL-00055H-8d for linux-arm-kernel@lists.infradead.org; Wed, 17 Oct 2018 13:22:27 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181017132211euoutp0298c7166dd56b4e3e370dc351bc453f37~eaA3Ow7L33232132321euoutp02W; Wed, 17 Oct 2018 13:22:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181017132211euoutp0298c7166dd56b4e3e370dc351bc453f37~eaA3Ow7L33232132321euoutp02W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539782531; bh=AEQgS7jJhpFlYZlbHO3kE7SSEZ4yh2WZch0IlMydKtc=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=nGx4ELd8eNNVFdd1Pup1/bpPoCa2JbyIwqYrBLAi8s5TbyBi+8rDhWTQXEMQ1WGLb pQrIYOor7/Gs+RC0FnyzQCMn7eAyWneQ3jRfjJ3rUwUckalv+b0A2U/F53IuUbniuA 0coZuRpIW5T1qRMBes9qkNMKvlQtsPbVcUcEUjI4= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181017132210eucas1p230ed694bb3524d672975e67d21652f00~eaA2rHiIT0677706777eucas1p2u; Wed, 17 Oct 2018 13:22:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.0B.04441.28737CB5; Wed, 17 Oct 2018 14:22:10 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181017132209eucas1p1d23615adc15663caaffb3c117dc61151~eaA13oOkA2705227052eucas1p16; Wed, 17 Oct 2018 13:22:09 +0000 (GMT) X-AuditID: cbfec7f2-5c9ff70000001159-02-5bc737826228 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 87.FE.04284.18737CB5; Wed, 17 Oct 2018 14:22:09 +0100 (BST) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PGQ00409VSWEA00@eusync1.samsung.com>; Wed, 17 Oct 2018 14:22:09 +0100 (BST) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v3 1/4] driver core: add probe_err log helper Date: Wed, 17 Oct 2018 15:22:05 +0200 Message-id: <20181017132205.5204-1-a.hajda@samsung.com> X-Mailer: git-send-email 2.18.0 In-reply-to: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRmVeSWpSXmKPExsWy7djPc7pN5sejDTZd5rG4te4cq8XLCYcZ LTbOWM9qMfXhEzaL5sXr2SwWTlvOaLHp8TVWi8u75rBZHJq6l9Fi7ZG77BZzv0xlduD2uHzt IrPHzll32T02repk89g/dw27x+Yl9R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q7bxwqSEBawlTg6ZzcjiM0ioCrxq/88mM0rYC7x +NYcJoh18hIPj7eDxTkFgiU+3pvNDmILCQRI/Fx8m20CI88CRoZVjCKppcW56bnFhnrFibnF pXnpesn5uZsYgQG47djPzTsYL20MPsQowMGoxMO7Q+xYtBBrYllxZe4hRgkOZiUR3irF49FC vCmJlVWpRfnxRaU5qcWHGKU5WJTEec8bVEYJCaQnlqRmp6YWpBbBZJk4OKUaGNtPT9d53//p yZIvE+oMa5nfS1/Q2WIe+frK1K2T5TxXaxQefXxHNSTr9OU5aQY/b36ZJcHbH3Mw0t7+Qfrh 4+pneAQX/nimmLYsZ+VJbTszi+7n35YmvGMtSatf5nLJcr5Ahk1wrVqZX3WPEsdudbeyScqn 585zjuqwmL1d8+OZ+w/izwvNNlNiKc5INNRiLipOBAAeL7woPAIAAA== X-CMS-MailID: 20181017132209eucas1p1d23615adc15663caaffb3c117dc61151 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181017132209eucas1p1d23615adc15663caaffb3c117dc61151 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181017_062225_449545_6555FC9E X-CRM114-Status: GOOD ( 17.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , Bartlomiej Zolnierkiewicz , linux-kernel@vger.kernel.org, Javier Martinez Canillas , Andrzej Hajda , andy.shevchenko@gmail.com, Mark Brown , Russell King - ARM Linux , linux-arm-kernel@lists.infradead.org, Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 04bbcd779e11..1f3e99c2ef03 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3067,6 +3067,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 90224e75ade4..6831677d5278 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1577,6 +1577,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))