From patchwork Thu Dec 20 10:22:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10738745 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 70F07161F for ; Thu, 20 Dec 2018 10:23:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EC5B28744 for ; Thu, 20 Dec 2018 10:23:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F5BD2874A; Thu, 20 Dec 2018 10:23:34 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 D001128744 for ; Thu, 20 Dec 2018 10:23:33 +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=AWBftXW4iyskwQC+1pamVb++/Ym0XAK+vYtttE8xe10=; b=RGuSHSdwkbRYdoFOjv4qrsCqS1 JROQ3gQDUD45DQfY3HSEOSbdNdCbS50/23HBPCrEDlRO86gk/hU9anTmIbIsXna5euUUNX7im8Sj5 werEddE9bzFaGyNZ3CDCyaWjBfuJltEJK8ESGRPNLpKp7rOSYBkBVdRf+Q8QVuynyL7kdDefm5LiM voYeA3NO49MoMCmYeRbZWejNv/fq597lCM+GJrn6Gbx9J1OIC/pEoqZ5OBErFqqEFSAJtxDZ++ow0 gQfhj2wcMStbh6mSlBlFQ3PsUBmgZ8Uz9xcN5M6ism+kuJuY/yFBJxyEpg/1H7s82Aqhiuxu+nIqO 57s2GH+A==; 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 1gZvUE-0000ZL-NI; Thu, 20 Dec 2018 10:23:26 +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 1gZvU2-0000Nb-MQ for linux-arm-kernel@lists.infradead.org; Thu, 20 Dec 2018 10:23:16 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181220102300euoutp02bd13ef2129f8493fe8c117a4d537d63a~yA2sYwgAG2917329173euoutp02P; Thu, 20 Dec 2018 10:23:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181220102300euoutp02bd13ef2129f8493fe8c117a4d537d63a~yA2sYwgAG2917329173euoutp02P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1545301380; bh=l9d5HR9T6mV0e4nZXjL57B2jHBVvBxDzB99xvEwtm8c=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=ruB6XXfXRZAcjz+C8TFurXYD4itDHEySfiRmamCWZuY0zGAWJaaEaEC4Wa+ozGoJD gQ2VmVEvL+1n1rDmZVlejb0GMFj84iLCWMHphjgZR1q2HCT960Lr1qwbOb0xrCMz+h CoOpzjdQcq3HoHR8M6axJ/+U0GZrUr929sLWCfMo= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181220102300eucas1p12b22c221d4489e7e5f6bd4bc22bd95ca~yA2r_CL9T1463714637eucas1p1K; Thu, 20 Dec 2018 10:23:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 53.BC.04441.38D6B1C5; Thu, 20 Dec 2018 10:22:59 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181220102259eucas1p2f748c68e01cd4e09a266da879722e218~yA2rN1C_n0445704457eucas1p25; Thu, 20 Dec 2018 10:22:59 +0000 (GMT) X-AuditID: cbfec7f2-5e3ff70000001159-c0-5c1b6d83f23a Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B2.49.04284.38D6B1C5; Thu, 20 Dec 2018 10:22:59 +0000 (GMT) Received: from AMDC3748.DIGITAL.local ([106.120.43.17]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PK100480669SP10@eusync3.samsung.com>; Thu, 20 Dec 2018 10:22:59 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v4 1/3] driver core: add probe_err log helper Date: Thu, 20 Dec 2018 11:22:45 +0100 Message-id: <20181220102247.4911-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-reply-to: <20181220102247.4911-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsWy7djP87rNudIxBldmmFncWneO1eLlhMOM FhtnrGe1mPrwCZtF8+L1bBYLpy1ntNj0+BqrxeVdc9gsDk3dy2ix9shddou5X6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YEljBJbDl9jBUkICTQySRw7WQNi swloSvzdfJMNxBYRMJboPzuLHaSBWWARs8TedfuAGjg4hAVsJQ7dVgKpYRFQlWib9R5sDq+A ucTxo52sEMvkJVZvOMAMUs4pYCHxcyU7xCpziT93prNNYORZwMiwilEktbQ4Nz232FCvODG3 uDQvXS85P3cTIzD4th37uXkH46WNwYcYBTgYlXh4Z0RJxQixJpYVV+YeYpTgYFYS4X2cJR0j xJuSWFmVWpQfX1Sak1p8iFGag0VJnPe8QWWUkEB6YklqdmpqQWoRTJaJg1OqgXFmYvPJCx1L WDZePq3zoNoyc5Gqz7KgzssZnn1LL81cderUlfvXi1T0dsv9Xn/r4s5XQYbTxZjCHzJ+u2m8 6i0f/3UDT1F+Q02xqWvWz0w1C/0by7FuSs3naK+o26qnDeyXW62YM2PqNSOzRI/Qzjtmq/IV Gv0CIj/4XjfjVNmadCOupH2S+D0lluKMREMt5qLiRAA0/KqdOgIAAA== X-CMS-MailID: 20181220102259eucas1p2f748c68e01cd4e09a266da879722e218 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181220102259eucas1p2f748c68e01cd4e09a266da879722e218 References: <20181220102247.4911-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181220_022314_922840_5846CADF X-CRM114-Status: GOOD ( 16.94 ) 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 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))