From patchwork Wed Jun 24 11:41:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 11622989 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8EB67913 for ; Wed, 24 Jun 2020 11:43:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6414620706 for ; Wed, 24 Jun 2020 11:43:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AK+Os9J5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="BmsA0fzn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6414620706 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=CtXiRccdy01dVPz5eJxtUiZPzteY3Ta5gqnTvV4pego=; b=AK+Os9J5kLZoIhHtDBcdFx3/vF pkV749C4iqpQYopw4D2DYAcScoF5NLf7WoUxByevcTlsq/hBBmGDrCNaVOdy+CqOSSsBnZlg0DbNF HWN3uRXKLVKTKqRZl+p8ra1ESK24j3WxXIAe8fIOioHyOlb4O3xWO2ixtDHIZzfJnJoV0eUpBkd/3 yH/WkRkPHyN5JKqW3d24QTuJbKILcIJtmyyMT0sngQNcogsFML2KdetradEJXszanicTa/+hko4Wx drg0iuxRpAkzxvZqE9bUOz3u/6iwi0P1np3OlYNsnVJltY/4Np1tTg5zsoMzFZhD8aZjjzLTVlpCX oShKZ2Qw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jo3mi-0006Tz-8n; Wed, 24 Jun 2020 11:41:44 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jo3md-0006RW-Eg for linux-arm-kernel@lists.infradead.org; Wed, 24 Jun 2020 11:41:40 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200624114136euoutp01c57aa1f2ee189edcf41437c7747bc999~beA5lMV-U2526325263euoutp01e for ; Wed, 24 Jun 2020 11:41:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200624114136euoutp01c57aa1f2ee189edcf41437c7747bc999~beA5lMV-U2526325263euoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1592998896; bh=HhEMsisY02ZOuY2/gjpIMi/WSmd5AdgRdcQapho3Kl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BmsA0fznDtVTqN7hyIBo1SznJi5uPjqavYxDu/DcdIPMu99H72KddvRGVn68Pc4cX NJoyGwQaOv8T4/uVZZsXr1kZ1AQ7uRRKocaH8Erf9tWwKRMzS0ARLEC9GL4LYAaw14 7eewpaRDBsRRx+i4QD5TIO2g465ed9zMlFI6Plro= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200624114136eucas1p113aa4f8987e7c1092a5bfec32e859dfa~beA5MkD490804208042eucas1p1K; Wed, 24 Jun 2020 11:41:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 21.1F.05997.FEB33FE5; Wed, 24 Jun 2020 12:41:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200624114135eucas1p26e2e4683d60cebdce7acd55177013992~beA4xUzId0286002860eucas1p2T; Wed, 24 Jun 2020 11:41:35 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200624114135eusmtrp122a25f28c380107d069f8d7c313f9d2f~beA4worMw0702007020eusmtrp1H; Wed, 24 Jun 2020 11:41:35 +0000 (GMT) X-AuditID: cbfec7f4-65dff7000000176d-04-5ef33befd65a Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 23.53.06017.FEB33FE5; Wed, 24 Jun 2020 12:41:35 +0100 (BST) Received: from AMDC3748.digital.local (unknown [106.120.51.74]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200624114134eusmtip296b918e1532d3a32de342cba443a9e63~beA4F74i82682326823eusmtip2-; Wed, 24 Jun 2020 11:41:34 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [RESEND PATCH v5 1/5] driver core: add probe_err log helper Date: Wed, 24 Jun 2020 13:41:23 +0200 Message-Id: <20200624114127.3016-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624114127.3016-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSeUiTYRjn3Xcqrb6W4ZtF4qg/ktJSqxcsKxH66CIKjLLM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7VYurDJ2wW/7dNZLa48vU9m0Xz4vVsFle/v2S2OPnmKotF58Ql7BabHl9jtbi8aw6b xaGpexkt1h65y25xqC/aYu6XqcwOAh6Xr11k9nh/o5XdY++3BSweO2fdZfeY3TGT1WPTqk42 jxMTLjF57J+7ht3jfvdxJo/NS+o9+rasYvQ40DuZxePzJrkA3ig9m6L80pJUhYz84hJbpWhD CyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TUnMyy1CJ9uwS9jMsNm5kLnolW/Nh2i7WB8Z9gFyMn h4SAicTX/zfYuhi5OIQEljJKTNq1iBkiIS6xe/5bKFtY4s+1LjYQW0jgE6NE84QkEJtNQFPi 7+abYHERAWOJ/rOz2EEGMQu0sUrMPf+EHSQhLOAiMev8Y7BBLAKqEkuWrWXtYuTg4BUwl1j8 1AhivrzE6g0HwEo4BSwkJrVcZITYZS5x6Ppi1gmMfAsYGVYxiqSWFuem5xYb6RUn5haX5qXr JefnbmIERta2Yz+37GDsehd8iFGAg1GJh3fDg49xQqyJZcWVuYcYJTiYlUR4nc6ejhPiTUms rEotyo8vKs1JLT7EaAp000RmKdHkfGDU55XEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnN Tk0tSC2C6WPi4JRqYJzhGvJJQW1FlefM7J4lH6u0s9aEXGYw6bvO6yAxf6Hbuuij87PM5+0z dzdhYZnhtsqvlNtProXpZO5G+wSXzIaPNnkvjFo8OhrPXli65/VBzcAs92nXZovrTWPewdsp 8Kb7iQRHXa9ZfJ9kZPGD+yF5xucO/ej4fLjgxfwqsQyNW2xejNdzlViKMxINtZiLihMBkdVG U8ICAAA= X-CMS-MailID: 20200624114135eucas1p26e2e4683d60cebdce7acd55177013992 X-Msg-Generator: CA X-RootMTR: 20200624114135eucas1p26e2e4683d60cebdce7acd55177013992 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200624114135eucas1p26e2e4683d60cebdce7acd55177013992 References: <20200624114127.3016-1-a.hajda@samsung.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -5.2 (-----) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-5.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [210.118.77.11 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.11 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jernej Skrabec , "Rafael J. Wysocki" , Jonas Karlman , Bartlomiej Zolnierkiewicz , linux-kernel@vger.kernel.org, "open list:DRM DRIVERS" , Russell King - ARM Linux , Neil Armstrong , Andrzej Hajda , andy.shevchenko@gmail.com, Mark Brown , Laurent Pinchart , Daniel Vetter , 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 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 --- 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 67d39a90b45c..ee9da66bff1b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3953,6 +3953,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 15460a5ac024..40a90d9bf799 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -964,6 +964,9 @@ void device_link_remove(void *consumer, struct device *supplier); void device_links_supplier_sync_state_pause(void); void device_links_supplier_sync_state_resume(void); +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))