From patchwork Fri Jun 26 10:01:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 11627039 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 65D1A912 for ; Fri, 26 Jun 2020 10:09:57 +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 3961F206C0 for ; Fri, 26 Jun 2020 10:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kzG52qff"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DbzVcdiV"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="ipgG6TEg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3961F206C0 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=4gZIAFMozoF271p2p8GPMkxXLAQ2H+mF4d9BMIOWtWQ=; b=kzG52qffqTVzX4ZR6FpFgpcEsm vdMs6r87gi06936iS36AdULhd+3k3QoUmfQSFVg7lTCmvPJYVJpGnqRyxVzLD8OuEykLdssNRizi4 gldTSdxVH0SMqxK1DVmGKPo1ukCYzjrUPG/wn5BslC27fyTl/5++ETeCj6roNXIumlnKpO4PVMjnZ tCl0ZIxtlz4vHxXssqXSLneXyV/ksK1a4fQV0hJyemY/I17ncmrq9BTK+PE2xe0gU4W6EBTVYWJxP orc1gn2Q/81fFC0d4DXU0Bte2C3BHZxoixrjtt/WSSBnLa//oxhQ+Al8MDA8LuI0KmUwf/601gYzS XhxL+ZOA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jolH2-0002K3-4q; Fri, 26 Jun 2020 10:07:56 +0000 Received: from casper.infradead.org ([90.155.50.34]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jolDZ-0000bm-HY for linux-arm-kernel@merlin.infradead.org; Fri, 26 Jun 2020 10:04:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:Content-Type:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3407dn9k5QQedWzfTAmf5rXvTScGYVbjSfdZVMHdevA=; b=DbzVcdiVzs+ob93Xl+RzCEVeuC qYPwVI+feDAMUvpugRBwe1+j4hsPy33aTAvYixmhVZFk9ygWZGZTQGvpf/fKxSFoDnft265GVrtSu KEPsKDyJQUUYC7YXBHyjInoqgbCYN79U1bIWdha1FPbo4Q6cPHUFwagQAVuTeDFGJDKKT5OvmciY3 Dn02WIO4OX6vdyDhGiTrBHhP6QR7jfHBxxInw+5iyclQy9wwr4FvkW7ku4er+C5Djh3Iu5Erfdg8N ssuEUNaVw5B15BGCYIEJ+sKF5FFwx0g5W0fSoujfv0wY39Og7G3E10aCACR09e3Y7xsTvqWDpgjrB RL5P9THg==; Received: from mailout1.w1.samsung.com ([210.118.77.11]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jolAX-0003aZ-Ou for linux-arm-kernel@lists.infradead.org; Fri, 26 Jun 2020 10:01:36 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200626100110euoutp013a9a13445cabf8a99a008c6df9ff7a55~cD7x2PAva0658406584euoutp015 for ; Fri, 26 Jun 2020 10:01:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200626100110euoutp013a9a13445cabf8a99a008c6df9ff7a55~cD7x2PAva0658406584euoutp015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1593165670; bh=3407dn9k5QQedWzfTAmf5rXvTScGYVbjSfdZVMHdevA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ipgG6TEgxzP9cYzYOb0Fndx683NMic+WzY/grLfqk/jPI6vOe+z7GbIhKVmvspETy Klq/d+ujqIVCWw/jC424z2oaLvrImL9CQZW0fre/CJs+0KZPM7hL16/CMCZfA8CwxI krNjesUyHcwoCq8JMxh65RdmmaILqAEIVU62KO4k= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200626100109eucas1p212f8a933788e87aeb64f79be106a9eec~cD7xcRLb81867418674eucas1p20; Fri, 26 Jun 2020 10:01:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 0F.DB.06456.567C5FE5; Fri, 26 Jun 2020 11:01:09 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200626100109eucas1p25331652d017cd17d21c0ae60541d1f73~cD7w3_ign0244402444eucas1p2t; Fri, 26 Jun 2020 10:01:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200626100109eusmtrp24ba8dd0378ed8a726946b16ba1a4d1d6~cD7w2We7Q1306813068eusmtrp2_; Fri, 26 Jun 2020 10:01:09 +0000 (GMT) X-AuditID: cbfec7f2-809ff70000001938-2f-5ef5c7658a64 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 22.86.06017.567C5FE5; Fri, 26 Jun 2020 11:01:09 +0100 (BST) Received: from AMDC3748.digital.local (unknown [106.120.51.74]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200626100108eusmtip17696631433fc09b000d8dedeaaeada88~cD7wImxm_2131121311eusmtip1_; Fri, 26 Jun 2020 10:01:08 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v6 1/4] driver core: add device probe log helper Date: Fri, 26 Jun 2020 12:01:00 +0200 Message-Id: <20200626100103.18879-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626100103.18879-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSa0iTURjHOXsvezUXb1PxYJI5EFTIC0qcqMRC4v0SXaAkRWvmy6ycyl7n 7YujctnyWonlhTTNxJWXpdbstpY4wzZMnahoJhliJIZulYKa2zvr2+85z/N//v9zOBQmNhO+ 1KX0LFaRLk2TkO54T/+qZR9rsieFr46Fo8k2C4EWyt8D1HmvnUCVs3Mk2uypwNCofYlE1xrb SWT9vYChDz+sOLpZ0SREuq9jBBrprSWRsfI1QE/7poXIWJqA6myVWAzNjIx9wpil8UIh8/pX Pc7oq6eFTE3RfYLRtd4kmYHyYQHztu6JkJm5ZRIwz5oKmNKuVsAYSu7gzIpuz0lRvPuhFDbt UjarCIu+4J5qL5wkMke9cxstSSrwZZcGuFGQjoJzmnlSA9wpM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CTYBTYm/ m2+ygdgiAsYS/WdnsYMUMQu0sUrMPf8EbJKwgIPE23tzmEBsFgFVid0n3oM18ApYSPxcv4cN YoO8xOoNB8C2cQpYSky/1cvaxcgBtM1ConNJ5ARGvgWMDKsYRVJLi3PTc4uN9IoTc4tL89L1 kvNzNzECI2vbsZ9bdjB2vQs+xCjAwajEw3tg4pc4IdbEsuLK3EOMEhzMSiK8TmdPxwnxpiRW VqUW5ccXleakFh9iNAW6aSKzlGhyPjDq80riDU0NzS0sDc2NzY3NLJTEeTsEDsYICaQnlqRm p6YWpBbB9DFxcEo1MObaTxD9IbqzIa1f8LXOg6rJR8P1+bqSvmYyenRtbir7+d9w+b1vv23f M4ZNa1miK71PNd5t66NeKWEPhpKjM128EmXmHTh5+FvsjP/avolmmfvT9t9apHbjVZixkunG 2KU/vi/2SYg+urI1ivPHG5eOjFjO1q7Zbjfnno7cFqF+b1PDa6niOCWW4oxEQy3mouJEAJrA gH3CAgAA X-CMS-MailID: 20200626100109eucas1p25331652d017cd17d21c0ae60541d1f73 X-Msg-Generator: CA X-RootMTR: 20200626100109eucas1p25331652d017cd17d21c0ae60541d1f73 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200626100109eucas1p25331652d017cd17d21c0ae60541d1f73 References: <20200626100103.18879-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200626_110114_711137_E3A42458 X-CRM114-Status: GOOD ( 19.22 ) X-Spam-Score: -7.1 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-7.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.11 listed in wl.mailspike.net] -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] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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_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.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 probe_err(dev, err, ...); Signed-off-by: Andrzej Hajda Reviewed-by: Rafael J. Wysocki Reviewed-by: Grygorii Strashko --- 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))