Message ID | cc853a7e4b3533585e3641620bf4972663f22edc.1666687086.git.mazziesaccount@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp891258wru; Tue, 25 Oct 2022 02:06:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ynUnlGZ2HgV0UmKJH0pIoQSQnMnSeH7GE5ar1JyPxCQ7Y7KAHBZa9XssyuxDFBRoJKeLo X-Received: by 2002:a17:907:e89:b0:78d:cdd7:5a28 with SMTP id ho9-20020a1709070e8900b0078dcdd75a28mr32406219ejc.167.1666688791342; Tue, 25 Oct 2022 02:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666688791; cv=none; d=google.com; s=arc-20160816; b=jNsSNCbbR8znD0JXa5B7tAVZ2rH4xOuEXEdGF5djACZrPP/xRt1XYt3bSsMD2WzzJE hN7JJe+ESlupVQ10eenpxAU1Cn773ZSaWXSmvwOiYX4mUQ7d4/dNTnP2UfFhcUG01ubi ydG3JB1EvIFtc3htNBZRa7ABJORUNsY7O9mFJmtO0RVul/Aq6/gsisVntwjLo9morncK l4yFwf2soGIHU2T/BGpAPGjbqDZ7FbCRyzDHU4EsjEvRiJGiGRQSPTjaan69tr4pCxi+ Q3AoBnKrjrJcw1VqNtc23PnrTkQ69qgLZlDzGsAce1ciailzJ0UwedSzIrqIwBOgLvOc 5u1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8R7Dzkg4GW8RstwwsY0aTGhaifKaL40i/WfeE85O4HQ=; b=bcqD6k5YRDavbBk7l6rMCX6ixqhhHwVRNPoTdUhJtUBHENAK9OIp3kCcOE6W/KwmpQ FAmelgXo+nLgKMwFL+yy5abNx/U6XEarWYlfwOaWXkvmvdAkxnLS9d1jnidpYRFB0kVP 0kU1PKskTkgexbc00IbsWP73aXvA+wHYfq4KUx33zWlsB90wMgCDVY6VmZElVKRpZptg RPkz+UqAEsYHWLcYJAKhxoRZVLiJsaHPGoEjsqaNceSQLiosA/hRFRreLIE8QwbYhrEQ QznK7uJZ6VfrCMH/2Aj4uG1kUsruyBSNSAcE9qRau1ZnrbjsR0tRzLRUF4C0J7A1nJWF 9zeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=M4gG5q52; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv12-20020a17090760cc00b0077951929340si1190061ejc.271.2022.10.25.02.06.05; Tue, 25 Oct 2022 02:06:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=M4gG5q52; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231769AbiJYIvU (ORCPT <rfc822;lucius.rs.storz@gmail.com> + 99 others); Tue, 25 Oct 2022 04:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231918AbiJYIvJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 04:51:09 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE83100BEF; Tue, 25 Oct 2022 01:51:06 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id bn35so7203826ljb.5; Tue, 25 Oct 2022 01:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8R7Dzkg4GW8RstwwsY0aTGhaifKaL40i/WfeE85O4HQ=; b=M4gG5q52M/fQ9S4AOTPRH4k1dtWqpvOU0rll7wPOXPb3Bwet7P3t8f3mFv42GbrAy9 5EURqb4L7WnK/nC3JOiYfyGIGCDzWD4i6bHe0GX6e4/4fdYuaGk5orrzxKxmyHHnH1zN u24zaLTaynom7ACPi3VX8hiX03meCkywL+o6ONYMDc5scpG5EccOSBdrcVeSalgbzLRA v5V3PsOAfFOcJUWy+q/jA/g+oCqwET8SAAEiVCdOT9tLmshrPsEBrUewWDE0z99G/q6B 4rxDuEI7l8y/uV0E2Kinc6RPR7lKpJkMy3zF8fYozGaU+HIIUXEuq5+s56J/W0PPufAg Gp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8R7Dzkg4GW8RstwwsY0aTGhaifKaL40i/WfeE85O4HQ=; b=WjJnxSb30D1Za/VjN+lzib1JeT0D1FITxn53zBKuM9pWP1rAuJuPzVcdZ1b2K8AUKf tP56pn/17WP3s7VM8We1wasPGpJvpu+R5sxFhwhMSNCXo5C9i4lYmVKoXBCmHMWH3FjX YWPCmcayDn/Cof7ZrBoo9i3fvZKecaWhZcHfBBoMpCdPW6Dlb1YcVzGcAJfkPh8RsA2w qPTauK9cNYCaP4w3nmVLxQokF/EljO9lRSKrJE4/EIN9muNORRu4cKHdI/DbrVmSNnZF Rz0X2qSuGTxUEO575l1dW5GlfDm6/ZM4Zrjtly60V5iw9Q9oppxUD5O6PEQzWuCcbNbI kIeQ== X-Gm-Message-State: ACrzQf06MhXtJNTKCnqaeQHB853PyXS8rulsC0dffQ/G/+WLrMAg23qZ YzZ8GygLwV1Y19MRf8X6ydRlLod0FC0= X-Received: by 2002:a2e:9b17:0:b0:26e:367c:c904 with SMTP id u23-20020a2e9b17000000b0026e367cc904mr14717348lji.326.1666687864570; Tue, 25 Oct 2022 01:51:04 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::2]) by smtp.gmail.com with ESMTPSA id m4-20020a056512114400b0049b8c0571e5sm326150lfg.113.2022.10.25.01.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 01:51:03 -0700 (PDT) Date: Tue, 25 Oct 2022 11:50:59 +0300 From: Matti Vaittinen <mazziesaccount@gmail.com> To: Matti Vaittinen <mazziesaccount@gmail.com>, Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>, Daniel Scally <djrscally@gmail.com>, Heikki Krogerus <heikki.krogerus@linux.intel.com>, Sakari Ailus <sakari.ailus@linux.intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Wolfram Sang <wsa@kernel.org>, Akhil R <akhilrajeev@nvidia.com>, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Message-ID: <cc853a7e4b3533585e3641620bf4972663f22edc.1666687086.git.mazziesaccount@gmail.com> References: <cover.1666687086.git.mazziesaccount@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="GQxlVILDjRRRfse1" Content-Disposition: inline In-Reply-To: <cover.1666687086.git.mazziesaccount@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747649865820017365?= X-GMAIL-MSGID: =?utf-8?q?1747649865820017365?= |
Series |
fix fwnode_irq_get_byname() returnvalue
|
|
Commit Message
Matti Vaittinen
Oct. 25, 2022, 8:50 a.m. UTC
The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping
failure. This is contradicting the function documentation and can
potentially be a source of errors like:
int probe(...) {
...
irq = fwnode_irq_get_byname();
if (irq <= 0)
return irq;
...
}
Here we do correctly check the return value from fwnode_irq_get_byname()
but the driver probe will now return success. (There was already one
such user in-tree).
Change the fwnode_irq_get_byname() to work as documented and according to
the common convention and abd always return a negative errno upon failure.
Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
I did a quick audit for the callers at v6.1-rc2:
drivers/i2c/i2c-smbus.c
drivers/iio/accel/adxl355_core.c
drivers/iio/gyro/fxas21002c_core.c
drivers/iio/imu/adis16480.c
drivers/iio/imu/bmi160/bmi160_core.c
drivers/iio/imu/bmi160/bmi160_core.c
I did not spot any errors to be caused by this change. There will be a
functional change in i2c-smbus.c as the probe will now return -EINVAL
should the IRQ dt-mapping fail. It'd be nice if this was checked to be
Ok by the peeps knowing the i2c-smbus :)
---
drivers/base/property.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
Comments
Moi, On Tue, Oct 25, 2022 at 11:50:59AM +0300, Matti Vaittinen wrote: > The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping > failure. This is contradicting the function documentation and can > potentially be a source of errors like: > > int probe(...) { > ... > > irq = fwnode_irq_get_byname(); > if (irq <= 0) > return irq; > > ... > } > > Here we do correctly check the return value from fwnode_irq_get_byname() > but the driver probe will now return success. (There was already one > such user in-tree). > > Change the fwnode_irq_get_byname() to work as documented and according to > the common convention and abd always return a negative errno upon failure. > > Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname") > Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> > > --- > > I did a quick audit for the callers at v6.1-rc2: > drivers/i2c/i2c-smbus.c > drivers/iio/accel/adxl355_core.c > drivers/iio/gyro/fxas21002c_core.c > drivers/iio/imu/adis16480.c > drivers/iio/imu/bmi160/bmi160_core.c > drivers/iio/imu/bmi160/bmi160_core.c > > I did not spot any errors to be caused by this change. There will be a It won't as you're decreasing the possible values the function may return... > functional change in i2c-smbus.c as the probe will now return -EINVAL > should the IRQ dt-mapping fail. It'd be nice if this was checked to be > Ok by the peeps knowing the i2c-smbus :) FWIW, for both patches (but see below): Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > drivers/base/property.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/base/property.c b/drivers/base/property.c > index 4d6278a84868..bfc6c7286db2 100644 > --- a/drivers/base/property.c > +++ b/drivers/base/property.c > @@ -964,7 +964,7 @@ EXPORT_SYMBOL(fwnode_irq_get); > */ > int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) > { > - int index; > + int index, ret; > > if (!name) > return -EINVAL; > @@ -973,7 +973,12 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) > if (index < 0) > return index; > > - return fwnode_irq_get(fwnode, index); > + ret = fwnode_irq_get(fwnode, index); > + This newline is extra. Or: return ret ?: -EINVAL; Or even: return fwnode_irq_get(fwnode, index) ?: -EINVAL; Up to you. > + if (!ret) > + return -EINVAL; > + > + return ret; > } > EXPORT_SYMBOL(fwnode_irq_get_byname);
Moro Sakari, Thanks for the review (and the suggestion)! On 10/25/22 12:08, Sakari Ailus wrote: > Moi, > > On Tue, Oct 25, 2022 at 11:50:59AM +0300, Matti Vaittinen wrote: >> The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping >> failure. This is contradicting the function documentation and can >> potentially be a source of errors like: >> >> int probe(...) { >> ... >> >> irq = fwnode_irq_get_byname(); >> if (irq <= 0) >> return irq; >> >> ... >> } >> >> Here we do correctly check the return value from fwnode_irq_get_byname() >> but the driver probe will now return success. (There was already one >> such user in-tree). >> >> Change the fwnode_irq_get_byname() to work as documented and according to >> the common convention and abd always return a negative errno upon failure. >> >> Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname") >> Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> >> >> --- >> >> I did a quick audit for the callers at v6.1-rc2: >> drivers/i2c/i2c-smbus.c >> drivers/iio/accel/adxl355_core.c >> drivers/iio/gyro/fxas21002c_core.c >> drivers/iio/imu/adis16480.c >> drivers/iio/imu/bmi160/bmi160_core.c >> drivers/iio/imu/bmi160/bmi160_core.c >> >> I did not spot any errors to be caused by this change. There will be a > > It won't as you're decreasing the possible values the function may > return... > Unless someone had implemented special handling for the IRQ mapping failure... >> functional change in i2c-smbus.c as the probe will now return -EINVAL >> should the IRQ dt-mapping fail. It'd be nice if this was checked to be >> Ok by the peeps knowing the i2c-smbus :) > > FWIW, for both patches (but see below): > > Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> > >> --- >> drivers/base/property.c | 9 +++++++-- >> 1 file changed, 7 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/base/property.c b/drivers/base/property.c >> index 4d6278a84868..bfc6c7286db2 100644 >> --- a/drivers/base/property.c >> +++ b/drivers/base/property.c >> @@ -964,7 +964,7 @@ EXPORT_SYMBOL(fwnode_irq_get); >> */ >> int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) >> { >> - int index; >> + int index, ret; >> >> if (!name) >> return -EINVAL; >> @@ -973,7 +973,12 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) >> if (index < 0) >> return index; >> >> - return fwnode_irq_get(fwnode, index); >> + ret = fwnode_irq_get(fwnode, index); >> + > > This newline is extra. > > Or: > > return ret ?: -EINVAL; > > Or even: > > return fwnode_irq_get(fwnode, index) ?: -EINVAL; > > Up to you. > My personal preference is to not use the ternary. I think the plain clarity of if() just in many places justifies burning couple of lines more :) Yours -- Matti
On Tue, Oct 25, 2022 at 11:50:59AM +0300, Matti Vaittinen wrote: > The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping > failure. This is contradicting the function documentation and can > potentially be a source of errors like: > > int probe(...) { > ... > > irq = fwnode_irq_get_byname(); > if (irq <= 0) > return irq; > > ... > } > > Here we do correctly check the return value from fwnode_irq_get_byname() > but the driver probe will now return success. (There was already one > such user in-tree). > > Change the fwnode_irq_get_byname() to work as documented and according to > the common convention and abd always return a negative errno upon failure. ... > + ret = fwnode_irq_get(fwnode, index); > + Redundant blank line and better to use traditional pattern: > + if (!ret) > + return -EINVAL; > + > + return ret; if (ret) return ret; /* We treat mapping errors as invalid case */ return -EINVAL; > }
Hi Andy, Thanks for the review. On 10/25/22 12:18, Andy Shevchenko wrote: > On Tue, Oct 25, 2022 at 11:50:59AM +0300, Matti Vaittinen wrote: >> The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping >> failure. This is contradicting the function documentation and can >> potentially be a source of errors like: >> >> int probe(...) { >> ... >> >> irq = fwnode_irq_get_byname(); >> if (irq <= 0) >> return irq; >> >> ... >> } >> >> Here we do correctly check the return value from fwnode_irq_get_byname() >> but the driver probe will now return success. (There was already one >> such user in-tree). >> >> Change the fwnode_irq_get_byname() to work as documented and according to >> the common convention and abd always return a negative errno upon failure. > > ... > >> + ret = fwnode_irq_get(fwnode, index); > >> + > > Redundant blank line and better to use traditional pattern: > >> + if (!ret) >> + return -EINVAL; >> + >> + return ret; > > if (ret) > return ret; > > /* We treat mapping errors as invalid case */ > return -EINVAL; > >> } I like the added comment - but in this case I don't prefer the "traditional pattern" you suggest. We do check for a very special error case indicated by ret 0. if (!ret) return -EINVAL; makes it obvious the zero is special error. if (ret) return ret; the traditional pattern makes this look like traditional error return - which it is not. The comment you added is nice though. It could be just before the check for if (!ret). I can cook v2 later when I have finished my current task - which may or may not take a while though.... Yours -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
On Tue, Oct 25, 2022 at 10:00:07AM +0000, Vaittinen, Matti wrote: > On 10/25/22 12:18, Andy Shevchenko wrote: > > On Tue, Oct 25, 2022 at 11:50:59AM +0300, Matti Vaittinen wrote: ... > >> + ret = fwnode_irq_get(fwnode, index); > > > >> + > > > > Redundant blank line and better to use traditional pattern: > > >> + if (!ret) > >> + return -EINVAL; > >> + > >> + return ret; > > > > if (ret) > > return ret; > > > > /* We treat mapping errors as invalid case */ > > return -EINVAL; > > > >> } > > I like the added comment - but in this case I don't prefer the > "traditional pattern" you suggest. We do check for a very special error > case indicated by ret 0. > > if (!ret) > return -EINVAL; > > makes it obvious the zero is special error. I don't think so. It makes ! easily to went through the cracks. If you want an explicit, use ' == 0' and add a comment. > if (ret) > return ret; > > the traditional pattern makes this look like traditional error return - > which it is not. The comment you added is nice though. It could be just > before the check for > > if (!ret).
diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..bfc6c7286db2 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -964,7 +964,7 @@ EXPORT_SYMBOL(fwnode_irq_get); */ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) { - int index; + int index, ret; if (!name) return -EINVAL; @@ -973,7 +973,12 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) if (index < 0) return index; - return fwnode_irq_get(fwnode, index); + ret = fwnode_irq_get(fwnode, index); + + if (!ret) + return -EINVAL; + + return ret; } EXPORT_SYMBOL(fwnode_irq_get_byname);