From patchwork Fri Jul 10 15:30:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 11656873 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 CCFE613B6 for ; Fri, 10 Jul 2020 15:32:17 +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 A456E2065D for ; Fri, 10 Jul 2020 15:32:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="3Zp/+X03"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="lOZpDe31" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A456E2065D 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=rqXuyyAj9olmZTvLwJYNIDmKqtHK3eg7hFXV6gVdAAU=; b=3Zp/+X03uYhI9YehgFnvRN8pJq Hil78M6lSymV7DuCE16DOyEDxQT5emunf/oBe+rUz/9GTpRQqFK0dtLn2L36BSfSRlYarHmZmuweX DZ4QoeFM1g10MzZ0AzXEPba1J3fYEOXZmS9xbIaUMENEiQrIndGZHMboOf2ksDiCiqC9eYSln5FN5 w9DZWC5cXISYuAQBGCSh8c98KH4JvDjMeff+otYyGEfSUra51Zmyw77n7ggBnc0Wd0HKNrFjGi752 dMCLeFliUWhWe9BqzoG9OWVvHg1eTkgM0Bq3tUCWc5h45MZBlyNV1YfnvwxM1aAI/sn0xmtU/eGR9 xSPN/eWA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtuz2-0000zQ-97; Fri, 10 Jul 2020 15:30:40 +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 1jtuyo-0000u2-LA for linux-arm-kernel@lists.infradead.org; Fri, 10 Jul 2020 15:30:28 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20200710153024euoutp019143efeebf8c3b3569742e266959f012~gbdPl763P2103621036euoutp01C for ; Fri, 10 Jul 2020 15:30:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20200710153024euoutp019143efeebf8c3b3569742e266959f012~gbdPl763P2103621036euoutp01C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1594395024; bh=l2lxSqoqhRbb4X9ynL2i6rkNRlCJlfLxzfEp8Lhp6UE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lOZpDe31bwa7jADfvG7anCVHVgjcVJ15O7IOR3txNwDUKBBmQWU6GDu9jvQfPSuWb cKEUBxd/P4JQ7eJ2ceMgG2xuXyJ0+6giE9pwHLdS6hkHBLb7AytLmDx1YeOGkXrJ08 eoPtECmGCjJsZskqwCtKTepq7kjM77bc3R3rfLBA= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200710153024eucas1p2400dd1dde4c0ab042dd6c1ccb4710ac4~gbdPHE2I52487224872eucas1p24; Fri, 10 Jul 2020 15:30:24 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 29.64.06456.099880F5; Fri, 10 Jul 2020 16:30:24 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200710153023eucas1p1564ece8b49581616a5bfed978a5164f0~gbdOmfAr-1062710627eucas1p1T; Fri, 10 Jul 2020 15:30:23 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200710153023eusmtrp1e1f685ab06673404ac89b20505dc379f~gbdOluId52243522435eusmtrp1q; Fri, 10 Jul 2020 15:30:23 +0000 (GMT) X-AuditID: cbfec7f2-809ff70000001938-dd-5f088990be0b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6C.38.06017.F89880F5; Fri, 10 Jul 2020 16:30:23 +0100 (BST) Received: from AMDC3748.digital.local (unknown [106.120.51.74]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200710153023eusmtip1b455300e49a61e0ba238580d832232ea~gbdN1dLdH0686906869eusmtip1M; Fri, 10 Jul 2020 15:30:23 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v8 1/5] driver core: add device probe log helper Date: Fri, 10 Jul 2020 17:30:14 +0200 Message-Id: <20200710153018.12226-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200710153018.12226-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSWUwTURTN60ynA1oyFiJPUYk1xGhkS/l4BELQqJkYjSZKNBqWKh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mPrwCZvF/20TmS2ufH3PZtG8eD2bxdXvL5ktTr65ymLROXEJu8Wmx9dYLS7vmsNm cWjqXkaLtUfuslsc6ou2mPtlKrODgMflaxeZPd7faGX32PttAYvHzll32T1md8xk9di0qpPN 48SES0we++euYfe4332cyWPzknqPvi2rGD0O9E5m8fi8SS6AN0rPpii/tCRVISO/uMRWKdrQ wkjP0NJCz8jEUs/Q2DzWyshUSd/OJiU1J7MstUjfLkEvY//6DqaCXWIVfxbsY2lg3C3UxcjJ ISFgInFqw0HmLkYuDiGBpYwSt6/PZIRIiEvsnv+WGcIWlvhzrYsNougTo8SO7xPBEmwCmhJ/ N99kA7FFBIwl+s/OYgcpYhZoY5WYe/4JkMPBISzgINFz2gakhkVAVeLnw/1g9bwCFhIne59C LZCXWL3hAJjNKWAp8W5qN1iNEFDN7WXfWScw8i1gZFjFKJJaWpybnltspFecmFtcmpeul5yf u4kRGFvbjv3csoOx613wIUYBDkYlHt4FiRzxQqyJZcWVuYcYJTiYlUR4nc6ejhPiTUmsrEot yo8vKs1JLT7EaAp01ERmKdHkfGDc55XEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnNTk0t SC2C6WPi4JRqYDzJE8xYzVlwLvityIFn7ZPyXG89O/pvd3aQkubk89JMitnvJxwxnVn++4Xz jcIU1+k3XHmcvS9PvbZ4umH7oXN3P3UELE1W0Jbd9sH81POep7uMyzTX6zfNX7zn3LaHb13S 7vw9ctHaMGjekjsHcv6U1V7z+2G8j1nvvMOb9DvHfe9cmmL3vZ1TiaU4I9FQi7moOBEA4Jmr XMMCAAA= X-CMS-MailID: 20200710153023eucas1p1564ece8b49581616a5bfed978a5164f0 X-Msg-Generator: CA X-RootMTR: 20200710153023eucas1p1564ece8b49581616a5bfed978a5164f0 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200710153023eucas1p1564ece8b49581616a5bfed978a5164f0 References: <20200710153018.12226-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200710_113026_808839_6F77710B X-CRM114-Status: GOOD ( 19.13 ) 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_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_SIGNED Message has a DKIM or DK signature, not necessarily valid -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.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: 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))