From patchwork Mon Jul 13 14:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 11659977 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 E1E35722 for ; Mon, 13 Jul 2020 14:45:20 +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 BA40C2072D for ; Mon, 13 Jul 2020 14:45:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W9l9HDJu"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Khv7GQHx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA40C2072D 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=W9l9HDJuDRnniafkcvoTRtWjeM 8Dafx8z+TxpgvK4rv2H7sijnS+0pE5VTGInVw/kDofMPXralg8qNBfoIuiG+rhatFjrOnP6GkZp0l +Cc257L2ero8pdBIJlE66xM/b/LF4MTME8Zc+ZjZEsMfxLN0qREkrN/QIrkKWAPZzAfVBTUCP3wie jXt4b5Ow/TMXI5nnc3we44La8YWBKAaf6aKeKuIvXmwB26G4sjclSK3ieCP+YLzxHM2QH1Uyzw0/4 I8di8W9i7aBqFgp/KOAynwCpSmFFjsx3aXWUcbOU2DgHj3zzaG0iJJohHYYbW16l62hAhi/NJyX+Y 2oyXbNKQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1juzgC-0005BP-QT; Mon, 13 Jul 2020 14:43:40 +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 1juzg6-000585-I2 for linux-arm-kernel@lists.infradead.org; Mon, 13 Jul 2020 14:43:36 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200713144332euoutp0285d5ca75c76857d3c21e1514af2cfe8e~hVwLMoYhS2796527965euoutp02E for ; Mon, 13 Jul 2020 14:43:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200713144332euoutp0285d5ca75c76857d3c21e1514af2cfe8e~hVwLMoYhS2796527965euoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1594651412; bh=l2lxSqoqhRbb4X9ynL2i6rkNRlCJlfLxzfEp8Lhp6UE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Khv7GQHxGcl1oNaYb80IKm+Iq2S9vWfliopuPMKNnkTCdyxa+MMzxIeUrv0Hz4O23 ohUn88mudgrw1inCZ6nY5iot35nZOtPZo6YnYkxRcKmbn2GWOInb6egNNAqhbLQz/S JL3DaRKTvZ2XIYR9gTPqaT+NEDvZ9uCUGbvTR+lU= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20200713144332eucas1p10094fde0732d18b7b6d4037c81020c76~hVwKyo-Hy1041510415eucas1p1v; Mon, 13 Jul 2020 14:43:32 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id F4.22.05997.4137C0F5; Mon, 13 Jul 2020 15:43:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200713144331eucas1p24107a30783dacc92887b80cf082be9fb~hVwKWZbq20910209102eucas1p2k; Mon, 13 Jul 2020 14:43:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20200713144331eusmtrp21fa81494749fc5dfc3a964686afaec07~hVwKVj3bD1147711477eusmtrp2w; Mon, 13 Jul 2020 14:43:31 +0000 (GMT) X-AuditID: cbfec7f4-65dff7000000176d-11-5f0c7314b2b1 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 05.2A.06314.3137C0F5; Mon, 13 Jul 2020 15:43:31 +0100 (BST) Received: from AMDC3748.digital.local (unknown [106.120.51.74]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200713144330eusmtip1ebe4f1fbd587ac6c7a4eaf92371da882~hVwJpKMJY1706817068eusmtip1Y; Mon, 13 Jul 2020 14:43:30 +0000 (GMT) From: Andrzej Hajda To: Greg Kroah-Hartman Subject: [PATCH v9 1/4] driver core: add device probe log helper Date: Mon, 13 Jul 2020 16:43:21 +0200 Message-Id: <20200713144324.23654-2-a.hajda@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200713144324.23654-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0WSe0hTURzHObuP3S0nt7n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BvNXq1jcWneO1eLlhMOM FhtnrGe1mPrwCZvF/20TmS2ufH3PZtG8eD2bxdXvL5ktTr65ymLROXEJu8Wmx9dYLS7vmsNm cWjqXkaLtUfuslsc6ou2mPtlKrODgMflaxeZPd7faGX32PttAYvHzll32T1md8xk9di0qpPN 48SES0we++euYfe4332cyWPzknqPvi2rGD0O9E5m8fi8SS6AN0rPpii/tCRVISO/uMRWKdrQ wkjP0NJCz8jEUs/Q2DzWyshUSd/OJiU1J7MstUjfLkEvY//6DqaCXWIVfxbsY2lg3C3UxcjJ ISFgInHp0jPWLkYuDiGBpYwSHw5dZYNIiEvsnv+WGcIWlvhzrYsNougTo8Tsk2vYQRJsApoS fzffBGsQETCW6D87ix2kiFmgjVVi7vknYEXCAg4SG9qvgBWxCKhKTPy+Gmwqr4CFxINDs1gg NshLrN5wACjOwcEpYCkxvy8cxBQCKjnx1nMCI98CRoZVjCKppcW56bnFhnrFibnFpXnpesn5 uZsYgZG17djPzTsYL20MPsQowMGoxMMr4c8TL8SaWFZcmXuIUYKDWUmE1+ns6Tgh3pTEyqrU ovz4otKc1OJDjKZAJ01klhJNzgdGfV5JvKGpobmFpaG5sbmxmYWSOG+HwMEYIYH0xJLU7NTU gtQimD4mDk6pBsbMW6GftLkONjmathxTS4ual39tg77Gnefl9ZX7bDiZbvifebZ45f/So54J K+6uS/l4KOLq34WCRcvKZ31IXmCWXbVPrtdB77vH7Hiri95ua492tO4WbFhw9ZTtdxnHhJV9 Bz8eX7ZoBtvvs9M6Pn5NC2ta+i2pLYvV4lvj3Td/vxw9PV1ovr2iEktxRqKhFnNRcSIAvpDW 98ICAAA= X-CMS-MailID: 20200713144331eucas1p24107a30783dacc92887b80cf082be9fb X-Msg-Generator: CA X-RootMTR: 20200713144331eucas1p24107a30783dacc92887b80cf082be9fb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200713144331eucas1p24107a30783dacc92887b80cf082be9fb References: <20200713144324.23654-1-a.hajda@samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200713_104334_847028_02FEABA5 X-CRM114-Status: GOOD ( 19.51 ) 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_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.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.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 Reviewed-by: Andy Shevchenko --- 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))