Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5048440imm; Tue, 16 Oct 2018 04:30:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV62DhLqywDByfHWjuyJ756eW/oNU0rr4Df0Np3n5qE9iyev0egymd+Dev+5cFk2Nfly7Omzt X-Received: by 2002:a17:902:b492:: with SMTP id y18-v6mr21343012plr.254.1539689433463; Tue, 16 Oct 2018 04:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539689433; cv=none; d=google.com; s=arc-20160816; b=ewu2NkZ6AlLDpca7tZrm4ii7AHtBLO7EVZlNHDNGQuTTf5FZbV+PzK/GVCNiBe5Yv8 qvllXH2e3RCbQF6s77bbCPA3AM3qTYJv/rUqw8ccN4ftHRaDMzhEHapuil8WbltOlWec 1VqSf/yfbYsh2P7y5kYQcvOyg4ZBiJK0dj//eKEYAvqLrZSCWkk0bMjKmPrv/MH2PPd4 7WwQc9lE1a1R5rSiLaVgGnDxJPypIvnsqbJAmag1NlDHkeyQH1whT41oC4uC5Bc8S5E+ QA/wfMBwypLvGOU8/+1cjkdWxl199yNW4xrylb0LqTpYbt06SQzx7xCzWBULT6PoF9Bl R31g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id :content-language:content-transfer-encoding:in-reply-to:mime-version :user-agent:date:from:cc:to:subject:dkim-signature:dkim-filter; bh=NdHPdm903Q9ZUXzQzTAuwBJKyToZ48XV+3MquRdpFLU=; b=skn5sSuG23PjL35dZ56b/Im92lOCVKv9/2eeRJAXRgj1y5YlTmTclfQCUwTySXjXnY DWjwtlqooLhoTnAcCpHItCMbwzirRe1vM8H6mGJZ0sclLyfpqmStcLiDqXDsRn8izkJe F1UYq4YZn5HMMU7+H2NGrxT5DclmlVUaHXnFroofCmuTGL5Xp56wKPTgE4ZMoOi2Yn6U 7PFe/EgU1v9iOPVNYi2QysX2HVPMEIBhBZPVWUFzeenZenNo/J1/jKtbP/C39PvF0wW4 jluBCZO+fEB3x9TxYVAQ2x0klZ9xA31KlzmYksZ/fvsIt4PdCNAxn/FnvC0bH0s4UmM+ nqbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mbsQX7y5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17-v6si11812437pgv.54.2018.10.16.04.30.16; Tue, 16 Oct 2018 04:30:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mbsQX7y5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727105AbeJPTTy (ORCPT + 99 others); Tue, 16 Oct 2018 15:19:54 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:44321 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbeJPTTy (ORCPT ); Tue, 16 Oct 2018 15:19:54 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181016112952euoutp02a741a32c24f09add28a1ec5aae629a65~eE1gsGKaI2128821288euoutp02X for ; Tue, 16 Oct 2018 11:29:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181016112952euoutp02a741a32c24f09add28a1ec5aae629a65~eE1gsGKaI2128821288euoutp02X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539689392; bh=NdHPdm903Q9ZUXzQzTAuwBJKyToZ48XV+3MquRdpFLU=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=mbsQX7y5ug8G5ETu6qv1K+UsXQ6bHbdhvdther30CPZ+ym0lzPO5JABTFIyerJbb3 RMXiaR9PWJVt88GPC7stjKdCiAKY+zYR2UWdFmwZvgcNXRj4/IYk+B7mivzFV+fNex /jyvRWAC4ThE8iSSs1NkQuSQuw+lRWupcgGOIIT4= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181016112951eucas1p19c1a4a9cb8094b3f4327679556414fed~eE1f7ABzl0931409314eucas1p1X; Tue, 16 Oct 2018 11:29:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 60.30.04294.EABC5CB5; Tue, 16 Oct 2018 12:29:50 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20181016112950eucas1p1a1d804f56c40ac01e5ef84c067c29d1a~eE1fNuopO0937209372eucas1p1O; Tue, 16 Oct 2018 11:29:50 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20181016112950eusmtrp22bb43eca59535f98914034fdede60d19~eE1e_0tyD1038510385eusmtrp2G; Tue, 16 Oct 2018 11:29:50 +0000 (GMT) X-AuditID: cbfec7f4-835ff700000010c6-2c-5bc5cbae7027 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 4C.EB.04128.EABC5CB5; Tue, 16 Oct 2018 12:29:50 +0100 (BST) Received: from [106.120.43.17] (unknown [106.120.43.17]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20181016112949eusmtip20ed88d3027e5d420e6d79a18244f004d~eE1em74js0540005400eusmtip2a; Tue, 16 Oct 2018 11:29:49 +0000 (GMT) Subject: Re: [PATCH 1/3] driver core: add probe_err log helper To: Andy Shevchenko Cc: Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz , Marek Szyprowski , "Rafael J. Wysocki" , Linux Kernel Mailing List , Javier Martinez Canillas , linux-arm Mailing List , Mark Brown From: Andrzej Hajda Date: Tue, 16 Oct 2018 13:29:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Transfer-Encoding: 8bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDKsWRmVeSWpSXmKPExsWy7djPc7rrTh+NNrh+19Li5YTDjBYbZ6xn tZj68AmbRfPi9WwWC6ctZ7TY9Pgaq8XlXXPYLNYeuctuMffLVGYHTo+ds+6ye2xa1cnmsX/u GnaPzUvqPd7vu8rm0bdlFaPH501yAexRXDYpqTmZZalF+nYJXBmHV7xnLrgpWzF/wlP2Bsbf ol2MnBwSAiYS679PZO5i5OIQEljBKLH8xERGCOcLo8SzaS9YIJzPjBJz9k9gg2npntoI1bKc UWJl52wo5y2jxOGNF9hBqoQF7CQ+bzgK1M7OISKgL7G/DKSEWWASs8TeC/fABrEJaEr83XwT zGYRUJVY8Ww2C4gtKhAhceTBQkYQm1dAUOLkzCdgcU6BQIlJJ76C2cwC8hLNW0H2gtjiEree zGeCOO4Uu8SDSSYQvWUSs58uYoaIu0jsfHAayhaWeHV8CzuELSPxfydMb71E08wrYL9ICHQw SpxYvBzqY2uJw8cvsnYxcgAt05RYv0sfIuwosW/9XmaQsIQAn8SNt4IQ5/BJTNo2HSrMK9HR JgRRrShx/+xWqAvEJZZe+Mo2gVFpFpInZyF5bBaSx2Yh7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0tSC2C6WPi4JRqYDR6cPKhroCxoe2nTL8D 9mbCMbvWzp56uH5z0LaSG935tbskG7n/vdxez19QELtr9zPTPgGhB/+/VZ6OOnxZa9PWuBUH F1doti6aay6Tq7ijoEoqTcssWkvrqOGypXnyC8RmrVCZkfTi8yOXwzlb++9If+r6HKFyfLN9 z80lb2KuX5QWC5uovkaJpTgj0VCLuag4EQANYsaW4gIAAA== Message-Id: <20181016112950eucas1p1a1d804f56c40ac01e5ef84c067c29d1a~eE1fNuopO0937209372eucas1p1O@eucas1p1.samsung.com> X-CMS-MailID: 20181016112950eucas1p1a1d804f56c40ac01e5ef84c067c29d1a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181016072249eucas1p2303b8c06a9f7c839a971fe065b0c752e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181016072249eucas1p2303b8c06a9f7c839a971fe065b0c752e References: <20181016072244.1216-1-a.hajda@samsung.com> <20181016072244.1216-2-a.hajda@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.10.2018 13:01, Andy Shevchenko wrote: > On Tue, Oct 16, 2018 at 10:22 AM Andrzej Hajda wrote: >> 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 seqences 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 >> --- >> drivers/base/core.c | 37 +++++++++++++++++++++++++++++++++++++ >> include/linux/device.h | 2 ++ >> 2 files changed, 39 insertions(+) >> >> diff --git a/drivers/base/core.c b/drivers/base/core.c >> index 04bbcd779e11..23fabefb217a 100644 >> --- a/drivers/base/core.c >> +++ b/drivers/base/core.c >> @@ -3067,6 +3067,43 @@ 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) { > Why not > > if (err == ...) > return err; > > ... > return err; > > ? > > Better to read, better to maintain. No? Yes, anyway next patch will re-factor it anyway. > >> + va_start(args, fmt); >> + >> + vaf.fmt = fmt; >> + vaf.va = &args; >> + >> + __dev_printk(KERN_ERR, dev, &vaf); > It would be nice to print an error code as well, wouldn't it? Hmm, on probe fail error is printed anyway (with exception of EPROBE_DEFER, ENODEV and ENXIO):     "probe of %s failed with error %d\n" On the other side currently some drivers prints the error code anyway via dev_err or similar, so I guess during conversion to probe_err it should be removed then. If we add error code to probe_err is it OK to report it this way?     dev_err(dev, "%V, %d\n", &vaf, err); Regards Andrzej > >> + va_end(args); >> + } >> + >> + return 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 90224e75ade4..06c2c797d132 100644 >> --- a/include/linux/device.h >> +++ b/include/linux/device.h >> @@ -1577,6 +1577,8 @@ do { \ >> WARN_ONCE(condition, "%s %s: " format, \ >> dev_driver_string(dev), dev_name(dev), ## arg) >> >> +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)) >> -- >> 2.18.0 >> >