From patchwork Mon Jun 29 11:22:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 11630759 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 C4BAF739 for ; Mon, 29 Jun 2020 11:24:50 +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 9E3F123A01 for ; Mon, 29 Jun 2020 11:24:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nXNCgA98"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="OP7uzmLK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E3F123A01 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=dWXNFAFDhNXzAnm4WTmkrc92GuirzVBhFPNbXJ7MvSM=; b=nXNCgA9853D2IHyRZpWRqe5Wyw 3QYvhOdi7wqp7ja/eDqZMHEbHpPvDHxTVGF5CSZIuIUKPkEXyrVRAsZAdDLEIhg+2nLd65Pws5FQb eMNGLEXY+B++zSiqH7JFwjO0YE9M1I6FYJV8SgmyAcNq+nwFk2UYdg1tEDZK/dq5z0n4PMckz90EC 5SQQvm2uCGP/XCY66LcMyj/i2EaAZp5+6aqSaPZ93MZejOFjtF8O/FXs+sh9xXFBVbmBcghcOEE/e WgV2/msbNAW749A/lvvAyLIZPUfcv5uiL+j6fMwjal4iPTZ33R+I6kOFEIbmRKhQAE/BbFipQblq9 GBc6IDrA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jprsh-0007Xk-5V; Mon, 29 Jun 2020 11:23:23 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jprsB-0007Mo-Qx for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 11:22:56 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200629112249euoutp02fcff03b9fbe532f1057b4df28abc7d18~c-_7PNLTj1877518775euoutp02W for ; Mon, 29 Jun 2020 11:22:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200629112249euoutp02fcff03b9fbe532f1057b4df28abc7d18~c-_7PNLTj1877518775euoutp02W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1593429769; bh=wssmSSMaPF7CImaevv1vsgWSyL4FhXmVP1cwotetOaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OP7uzmLKmDoWUpOXcxFCcZPP+3izi1IaDsNnlTYOpyV7Vt8jcXLvKVUX62U7tZLqr 8/5ogTTZyMKhLi7IXTupVO/jc5byWpH+m3fwGgX2hPv/JbEJOb5l1Mm4z/erFcTzW4 JCAiSniFH44G0WCMTGxPs0JzNOaUabR2o9Pyqe5Y= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200629112248eucas1p1e955f3406a049db1026fd70bf7b7cf37~c-_6su_Ni1033510335eucas1p1l; Mon, 29 Jun 2020 11:22:48 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.A7.06456.80FC9FE5; Mon, 29 Jun 2020 12:22:48 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200629112248eucas1p187e5dac2f4f6120aacbc86e48ad0fff9~c-_6SUG4N1890518905eucas1p1T; Mon, 29 Jun 2020 11:22:48 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200629112248eusmtrp2595e9175d804508d8e50c56bf97ec1bf~c-_6Rjh9M1939019390eusmtrp2b; Mon, 29 Jun 2020 11:22:48 +0000 (GMT) X-AuditID: cbfec7f2-7efff70000001938-c1-5ef9cf08013f Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DA.EC.06017.80FC9FE5; Mon, 29 Jun 2020 12:22:48 +0100 (BST) Received: from AMDC3748.digital.local (unknown [106.120.51.74]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200629112247eusmtip109ae075f9a8cb05d25252e50db7e5a84~c-_5f8y2e2177921779eusmtip13; Mon, 29 Jun 2020 11:22:47 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v7 1/4] driver core: add device probe log helper Date: Mon, 29 Jun 2020 13:22:39 +0200 Message-Id: <20200629112242.18380-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200629112242.18380-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSWUxT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FlrPIsWRmVeSWpSXmKPExsVy+t/xu7oc53/GGTQ18VjcWneO1eLlhMOM FhtnrGe1mPrwCZvF/20TmS2ufH3PZtG8eD2bxdXvL5ktTr65ymLROXEJu8Wmx9dYLS7vmsNm cWjqXkaLtUfuslsc6ou2mPtlKrODgMflaxeZPd7faGX32PttAYvHzll32T1md8xk9di0qpPN 48SES0we++euYfe4332cyWPzknqPvi2rGD0O9E5m8fi8SS6AN0rPpii/tCRVISO/uMRWKdrQ wkjP0NJCz8jEUs/Q2DzWyshUSd/OJiU1J7MstUjfLkEv49SlV6wFPWIVHY9uMjcwThLqYmTn kBAwkdgQ1cXIxSEksJRRYtXu26xdjJxAYXGJ3fPfMkPYwhJ/rnWxQRR9YpToXH4KrIhNQFPi 7+abbCC2iICxRP/ZWewgRcwCbawSc88/YQdJCAs4ADXcBZvEIqAqMXntRLA4r4CFxNMPr6G2 yUus3nAArIZTwFLi8oWZjCC2EFDNhaOd7BMY+RYwMqxiFEktLc5Nzy020itOzC0uzUvXS87P 3cQIjKxtx35u2cHY9S74EKMAB6MSD2/CuZ9xQqyJZcWVuYcYJTiYlUR4nc6ejhPiTUmsrEot yo8vKs1JLT7EaAp01ERmKdHkfGDU55XEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnNTk0t SC2C6WPi4JRqYEzp2lpw5MyN/f8zTk8OlVp4d9rjVWYxlWw/P68UDhbomxn/P3Hxi68G0Qoh JqF5ulxpYlWBR69cE2FQllGUPXE/VOzigaVWS89eiHn0syfmFVOke6PD1X+f3t06GGslqKVZ p2ZZtKd/mcvZqFshESXa3bpdtxya3XMDLq+K7XnROOG9iYhdoBJLcUaioRZzUXEiAFiu5E7C AgAA X-CMS-MailID: 20200629112248eucas1p187e5dac2f4f6120aacbc86e48ad0fff9 X-Msg-Generator: CA X-RootMTR: 20200629112248eucas1p187e5dac2f4f6120aacbc86e48ad0fff9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200629112248eucas1p187e5dac2f4f6120aacbc86e48ad0fff9 References: <20200629112242.18380-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.12 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.12 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 omitted or implemented only partially. dev_err_probe helps to replace such code sequences with simple call, so code: if (err != -EPROBE_DEFER) dev_err(dev, ...); return err; becomes: return dev_err_probe(dev, err, ...); Signed-off-by: Andrzej Hajda Reviewed-by: Rafael J. Wysocki Reviewed-by: Andy Shevchenko Reviewed-by: Mark Brown --- drivers/base/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 67d39a90b45c..3a827c82933f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3953,6 +3953,48 @@ define_dev_printk_level(_dev_info, KERN_INFO); #endif +/** + * dev_err_probe - 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 debug or error message depending if the error value is + * -EPROBE_DEFER and propagate error upwards. + * It replaces code sequence: + * if (err != -EPROBE_DEFER) + * dev_err(dev, ...); + * else + * dev_dbg(dev, ...); + * return err; + * with + * return dev_err_probe(dev, err, ...); + * + * Returns @err. + * + */ +int dev_err_probe(const struct device *dev, int err, const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + + if (err != -EPROBE_DEFER) + dev_err(dev, "error %d: %pV", err, &vaf); + else + dev_dbg(dev, "error %d: %pV", err, &vaf); + + va_end(args); + + return err; +} +EXPORT_SYMBOL_GPL(dev_err_probe); + 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..6b2272ae9af8 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 dev_err_probe(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))