From patchwork Tue Oct 16 07:22:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10643175 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 391BB1057 for ; Tue, 16 Oct 2018 07:24:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B61326E47 for ; Tue, 16 Oct 2018 07:24:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F56827F60; Tue, 16 Oct 2018 07:24:41 +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 1F82726E47 for ; Tue, 16 Oct 2018 07:24: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=nOyM+lUFmYdVOk88NXoCpbFJpgbrLP14d/oMaqxYvP4=; b=eTGmH40jp/tuiUSRz3EicS8ri2 HF5qokvXa3L0ZC08tAkOA31u8WP2E7l4WGPARNQvYz9nlhSn1fZMPIfyxrbApZdd3u3XbYfQHyDbx XOiH0dEx5QskVv+9e7SszaQ2LBxRuHu5WRXgPD5Vtt762kmZxDr77Rkhpgza7Lst9Dav4U1rFq+er Sx5OoIsE0/5Iehr06chG7SyKuxe9ffit7ueTNxvhJK44cExkHh4Kq6ddUiJN1ku/bwJsJBMr9LtKx tDVdnu77G/ztzw2/9VrwQF8RjH7S3GgFj7VDU6N6qaIwuyrkpfYUm7HRowQyi4Ay4motwHnAA4dtv 60FPF3yQ==; 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 1gCJiR-0000mG-VT; Tue, 16 Oct 2018 07:24:32 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCJh4-00006U-DR for linux-arm-kernel@lists.infradead.org; Tue, 16 Oct 2018 07:23:10 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181016072250euoutp017313bb9e2a877cf8f3acd7b03e5df45a~eBd1DaPzD1696916969euoutp01H; Tue, 16 Oct 2018 07:22:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181016072250euoutp017313bb9e2a877cf8f3acd7b03e5df45a~eBd1DaPzD1696916969euoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539674570; bh=cZrZMaFu0XT+cQVHdRGBcBuXnsgaiFRRuci107vDojI=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=a7SvGwMwpz3clX2US2fHlrniQNOlUWjLg6JtfqOKvF4s4wnYjjJ6DUDqZaPFRpdp0 nBNu2INE8oJc4HWAPg+AS3p2vIj5kLIpPuGq3Ph658tJrPRuGcCSRWxExc8DC0jycw H/x0nL2HaPeBnBJfvxb2DE5Xt5f9HdC00czAvYjM= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181016072250eucas1p164e60452bcdab760f51403ac619e00e6~eBd0nN_C11943519435eucas1p1i; Tue, 16 Oct 2018 07:22:50 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 00.CB.04441.9C195CB5; Tue, 16 Oct 2018 08:22:49 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181016072249eucas1p2303b8c06a9f7c839a971fe065b0c752e~eBdz2Wwii1940019400eucas1p2o; Tue, 16 Oct 2018 07:22:49 +0000 (GMT) X-AuditID: cbfec7f2-a1ae89c000001159-74-5bc591c930bb Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 2D.F5.04284.9C195CB5; Tue, 16 Oct 2018 08:22:49 +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 <0PGO0048DKHZVR70@eusync1.samsung.com>; Tue, 16 Oct 2018 08:22:49 +0100 (BST) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH 1/3] driver core: add probe_err log helper Date: Tue, 16 Oct 2018 09:22:42 +0200 Message-id: <20181016072244.1216-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.18.0 In-reply-to: <20181016072244.1216-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRmVeSWpSXmKPExsWy7djPc7onJx6NNjjTpWVxa905VouXEw4z WmycsZ7VYurDJ2wWzYvXs1ksnLac0WLT42usFpd3zWGzWHvkLrvF3C9TmR24PHbOusvusWl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g1ngHZPErCcvGEESwgJWEvfXTmcBsVkEVCXezZ7KBGLzCphLnPv0iQVinbzEw+Pt YPWcAhYS1zdsZgaxhYBqbl9oY5/AyLOAkWEVo0hqaXFuem6xoV5xYm5xaV66XnJ+7iZGYLBt O/Zz8w7GSxuDDzEKcDAq8fD+uH4kWog1say4MvcQowQHs5IIr2zl0Wgh3pTEyqrUovz4otKc 1OJDjNIcLErivOcNKqOEBNITS1KzU1MLUotgskwcnFINjPoCl0OvbbCqEb/Aw8vqfGwd138W vy1XVVf1qN3vd5dTSj9lsN5Sx0huRdbnB5+Tp8icUNm285b0tV3ztmUaFetMPvniEG/HvBtv TKsPphjuNa37vuby9zsfY59Ev7Kd8vxTzFmu8K0vplw/uf7ZGpfKaPezlcWRgtwFj3a92hQa xj7XXD72WJwSS3FGoqEWc1FxIgCwJR4AMgIAAA== X-CMS-MailID: 20181016072249eucas1p2303b8c06a9f7c839a971fe065b0c752e X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181016072249eucas1p2303b8c06a9f7c839a971fe065b0c752e References: <20181016072244.1216-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181016_002306_636523_4262BF66 X-CRM114-Status: GOOD ( 15.95 ) 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 seqences 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 --- 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..23fabefb217a 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 + * @...: 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) { + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; + + __dev_printk(KERN_ERR, dev, &vaf); + va_end(args); + } + + return 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))