Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp543698ybt; Wed, 24 Jun 2020 05:38:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx41ZsJvl0HfrJWyrLEcv9XU37FYcGUfw6whd92n/Nd+8wDAA4crH/njmW2sT2J3v8WgLx9 X-Received: by 2002:a17:906:7c07:: with SMTP id t7mr19582733ejo.487.1593002324946; Wed, 24 Jun 2020 05:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593002324; cv=none; d=google.com; s=arc-20160816; b=xK95cVORj+IRyn7Z+iny7v3ANXA6VxIkNOmBnRi43Ak1NoXcbOSvSPua2qWOdFVIFv i8Rr/4QfCIIqUDGZhnFdAfmHfI64x3orqDW49rUnBi81HPoWmSytXl8d3yl9EJZ0Wh82 UK8mVU9Cwg5uGIllGTQNaGBKGWcbAsxC2CuWkdriNG3wFJKmvIK6u560BHSROmoj4njg Sdki8TaUlDtq5OK93Vi2Dv+kw8MlY3kD1RHNw8vgwt9XaEZmNBSR3plSK8L2NAZtf3eZ 3ONPZ1gYPBF1bXFxuzlTTKUlaQyWNoSdRNoQlEJUxhfDD5sqJYD73q0dSyTbVd/y43M6 OCnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=+oQ0cUsunidignbQL/wJvVCd3XK60hQrGaaT5lFqFmQ=; b=y9+xN+l9F5saDcXCTsIq7m2x9dGltzvbZAtVHzELXKFSnV0o237QtO9jxZPPCykZ++ fSDwKixte4FwPgOxIKrHoEEdwVHqP2xKt5k1FSa573FqYh3jGe+ShtfKKlb3IDHfdT8X a76s5pe9XX29SMoXWrkV1DFhIz5WELb5rhREeZsOHl09KCqprRTMSpDTM4vu/dDcKIba LrcYkVQr78Uzvcm7E6PaR5neqK1ESew2sedVDVtvDYjjjsYN2IQQ/AFez4FyVCOCWCng ZK3rQgp2/uD5cyMvlTPCSPp5ts3kv13yWuhlS97gVRHuO4+bpaY75D7DY1GMLR6YU8HG 6taQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si13417240eju.428.2020.06.24.05.38.21; Wed, 24 Jun 2020 05:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390586AbgFXMh5 (ORCPT + 99 others); Wed, 24 Jun 2020 08:37:57 -0400 Received: from foss.arm.com ([217.140.110.172]:44190 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388942AbgFXMh4 (ORCPT ); Wed, 24 Jun 2020 08:37:56 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D8941F1; Wed, 24 Jun 2020 05:37:56 -0700 (PDT) Received: from [10.57.9.128] (unknown [10.57.9.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A71433F6CF; Wed, 24 Jun 2020 05:37:53 -0700 (PDT) Subject: Re: [RESEND PATCH v5 3/5] drivers core: allow probe_err accept integer and pointer types To: Andrzej Hajda , Greg Kroah-Hartman 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 , andy.shevchenko@gmail.com, Mark Brown , Laurent Pinchart , Daniel Vetter , linux-arm-kernel@lists.infradead.org, Marek Szyprowski References: <20200624114127.3016-1-a.hajda@samsung.com> <20200624114127.3016-4-a.hajda@samsung.com> From: Robin Murphy Message-ID: <2203e0c2-016b-4dbe-452d-63c857f06dd1@arm.com> Date: Wed, 24 Jun 2020 13:37:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200624114127.3016-4-a.hajda@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-24 12:41, Andrzej Hajda wrote: > Many resource acquisition functions return error value encapsulated in > pointer instead of integer value. To simplify coding we can use macro > which will accept both types of error. > With this patch user can use: > probe_err(dev, ptr, ...) > instead of: > probe_err(dev, PTR_ERR(ptr), ...) > Without loosing old functionality: > probe_err(dev, err, ...) Personally I'm not convinced that simplification has much value, and I'd say it *does* have a significant downside. This: if (IS_ERR(x)) do_something_with(PTR_ERR(x)); is a familiar and expected pattern when reading/reviewing code, and at a glance is almost certainly doing the right thing. If I see this, on the other hand: if (IS_ERR(x)) do_something_with(x); my immediate instinct is to be suspicious, and now I've got to go off and double-check that if do_something_with() really expects a pointer it's also robust against PTR_ERR values. Off-hand I can't think of any APIs that work that way in the areas with which I'm familiar, so it would be a pretty unusual and non-obvious thing. Furthermore, an error helper that explicitly claims to accept "pointer type" values seems like it could easily lead to misunderstandings like this: int init_my_buffer(struct my_device *d) { d->buffer = kzalloc(d->buffer_size, GFP_KERNEL); return probe_err(d->dev, d->buffer, "failed to init buffer\n"); } and allowing that to compile without any hint of an error seems a little... unfair. Robin. > Signed-off-by: Andrzej Hajda > --- > drivers/base/core.c | 25 ++----------------------- > include/linux/device.h | 25 ++++++++++++++++++++++++- > 2 files changed, 26 insertions(+), 24 deletions(-) > > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 2a96954d5460..df283c62d9c0 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -3953,28 +3953,7 @@ 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. > - * In case of -EPROBE_DEFER it sets defer probe reason, which can be checked > - * later by reading devices_deferred debugfs attribute. > - * 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, ...) > +int __probe_err(const struct device *dev, int err, const char *fmt, ...) > { > struct va_format vaf; > va_list args; > @@ -3992,7 +3971,7 @@ int probe_err(const struct device *dev, int err, const char *fmt, ...) > > return err; > } > -EXPORT_SYMBOL_GPL(probe_err); > +EXPORT_SYMBOL_GPL(__probe_err); > > static inline bool fwnode_is_primary(struct fwnode_handle *fwnode) > { > diff --git a/include/linux/device.h b/include/linux/device.h > index 40a90d9bf799..22d3c3d4f461 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -965,7 +965,30 @@ void device_links_supplier_sync_state_pause(void); > void device_links_supplier_sync_state_resume(void); > > extern __printf(3, 4) > -int probe_err(const struct device *dev, int err, const char *fmt, ...); > +int __probe_err(const struct device *dev, int err, const char *fmt, ...); > + > +/** > + * probe_err - probe error check and log helper > + * @dev: the pointer to the struct device > + * @err: error value to test, can be integer or pointer type > + * @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. > + * In case of -EPROBE_DEFER it sets defer probe reason, which can be checked > + * later by reading devices_deferred debugfs attribute. > + * It replaces code sequence: > + * if (err != -EPROBE_DEFER) > + * dev_err(dev, ...); > + * return err; > + * with > + * return probe_err(dev, err, ...); > + * > + * Returns @err. > + * > + */ > +#define probe_err(dev, err, args...) __probe_err(dev, (long)(err), args) > > /* Create alias, so I can be autoloaded. */ > #define MODULE_ALIAS_CHARDEV(major,minor) \ >