From patchwork Wed Oct 17 08:58:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10645127 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 DA37A13A4 for ; Wed, 17 Oct 2018 09:03:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9D602A7E6 for ; Wed, 17 Oct 2018 09:03:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDF892A806; Wed, 17 Oct 2018 09:03:42 +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 AC35C2A7E6 for ; Wed, 17 Oct 2018 09:03:41 +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=bsBhqEwLAXFm4pxjuW7IMsW4HTRoMhCgNnK9byU2z3U=; b=l2I9U631VjSjwuQbJBQVeGoo+x aGen3FuIM++K7io0JuRHO5sAa0PNKTyZHFNQAUmbT65WjsGjdEBEodcKmkv5J6FB5hYiQ4TvdYfzD bObgMORZbJmn8ZBSUeIOZlpMXb/KCK2HuTBNxawOYUNT57mAKSL4CzEre3OFQqXi+Hqj7+VPKTMbs UiKMVD9KdL+3wt6a3MwZCkwrMObapRD2nRLLFqo6PdXZiew+xeGVDSmWH5JfQNrFQd7LXkigXcdo7 Zt7ycK3nUEvId+ySbq3G7jSeoTieV90fV2Ip87j0iQL1ArbAD1qIqlHb6dBnx1LxRwLGF9TJX8fZO cbn8lQNg==; 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 1gChjm-0005h6-KO; Wed, 17 Oct 2018 09:03:30 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gChjj-0005ZT-Qi for linux-arm-kernel@bombadil.infradead.org; Wed, 17 Oct 2018 09:03:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-reply-to:Message-id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KZ/e2xySQS+OE+AFMvIGc6tBNmknZ1uPpkiJ7OxGnvg=; b=pDiTpo3Pwizr9s7RAjqkz9zzQ 74jN9pGqFX3K7T33g5VMeMqLbJPzMxsP9bBOaNy4e52svLpm2IJD3FBv+kLdzuxCHsmDf1Xc5B/VS uDsOgG04rj+4K5HPxMPHgwxyKASkG+GPKK2dpuZU7sCGRiY20wWy7gvP9RmD+RDc1hSKf1pQfhvQv zifuL3n8KLMt3HTW4jc8mrFbzG9mSlF0q2Ug1AUJlv1wqIPJiI6Lr1UIZ338S00L0coupJ0HMtQaZ efQjr+uAaADDTQJ9gEkd7SaC0ecRsSCCH9MidKTILKpcHbGrUTcueR36Yic6QB+LTUk8s27vDv80S GBnaZyqSA==; Received: from mailout2.w1.samsung.com ([210.118.77.12]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gChfH-0008LG-Et for linux-arm-kernel@lists.infradead.org; Wed, 17 Oct 2018 08:58:56 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181017085834euoutp028baae7162b3e2e3a480f5b44889bf589~eWasogqg21870518705euoutp021; Wed, 17 Oct 2018 08:58:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181017085834euoutp028baae7162b3e2e3a480f5b44889bf589~eWasogqg21870518705euoutp021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539766714; bh=KZ/e2xySQS+OE+AFMvIGc6tBNmknZ1uPpkiJ7OxGnvg=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=NZpJ2o2Ox2Y+es08qKpIVPY0XCkHjDeIa7NuOpewB8TJA/PYTX0t0ETyhY0Fuxdmd gNSSBgL+YzYJOns5zhTR5F6IiSIFtnjgyBu38bvJh1YHylFGOuQr04/E8LwvkM1NLE Br3jJqSRIl4e3s7ktclgxbxNZyoSzLirYPHtaLtA= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181017085833eucas1p285833f4f82de46a976d7d673518a7b35~eWasIwXnZ0823608236eucas1p2T; Wed, 17 Oct 2018 08:58:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 99.43.04441.9B9F6CB5; Wed, 17 Oct 2018 09:58:33 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181017085832eucas1p23dbb86230149a13634b8a091c3b1301f~eWarb_6p90824808248eucas1p2C; Wed, 17 Oct 2018 08:58:32 +0000 (GMT) X-AuditID: cbfec7f2-5c9ff70000001159-8e-5bc6f9b958e7 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E6.C8.04128.8B9F6CB5; Wed, 17 Oct 2018 09:58:32 +0100 (BST) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PGQ00HKSJLJEQ40@eusync4.samsung.com>; Wed, 17 Oct 2018 09:58:32 +0100 (BST) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v2 1/3] driver core: add probe_err log helper Date: Wed, 17 Oct 2018 10:58:24 +0200 Message-id: <20181017085824.30806-1-a.hajda@samsung.com> X-Mailer: git-send-email 2.18.0 In-reply-to: X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsWy7djP87o7fx6LNrj0Stri1rpzrBYvJxxm tNg4Yz2rxdSHT9gsmhevZ7NYOG05o8Wmx9dYLS7vmsNmsfbIXXaLuV+mMjtweeycdZfdY9Oq TjaP/XPXsHtsXlLv8X7fVTaPvi2rGD0+b5ILYI/isklJzcksSy3St0vgyrjw+wprwSPRiuf/ nrI0MJ4V7GLk5JAQMJHYsLOdrYuRi0NIYAWjxJtdh6Gcz4wSlyf0scFUvf/8mhEisYxR4tTq b1DOf0aJvjVnGUGq2AQ0Jf5uvgnWISJgLNF/dhY7SBGzwBsmiScPpjCBJIQFbCV+9c8FK2IR UJVYvX0jK4jNK2AhMf1cHwvEOnmJh8fbwYZyCgRL9C6YBxVfwSbRuVKpi5EDyHaROLCCCyIs LPHq+BZ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F+Ma2p3HPWRqb4v1P2v3c6MU9DzPDa4bwnlys+rejQSWs2em0WcFBup3/G3qXl5xI5 kp0M1GNO/mU6sOpX+ayABVsZX6zLaNlw29m7q2jm/Qu1Hx4UJ/Xej27yvGSwxShvbYOJktCj 6qeTDxsqsRRnJBpqMRcVJwIA999RMTICAAA= X-CMS-MailID: 20181017085832eucas1p23dbb86230149a13634b8a091c3b1301f X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181017085832eucas1p23dbb86230149a13634b8a091c3b1301f References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181017_095851_703654_2BC018E9 X-CRM114-Status: GOOD ( 17.38 ) 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 , 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: Andy Shevchenko --- 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 | 37 +++++++++++++++++++++++++++++++++++++ include/linux/device.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 04bbcd779e11..aa6f3229d066 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3067,6 +3067,43 @@ 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, not ended with newline + * @...: 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, "%pV, %d\n", &vaf, err); + 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..06c2c797d132 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1577,6 +1577,8 @@ do { \ WARN_ONCE(condition, "%s %s: " format, \ dev_driver_string(dev), dev_name(dev), ## arg) +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))