mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Daniel Scally <djrscally@gmail.com>,
	Heikki Krogerus <heikki.krogerus@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: Re: [PATCH 1/2] drivers: fwnode: fix fwnode_irq_get_byname()
Date: Tue, 25 Oct 2022 12:17:27 +0300	[thread overview]
Message-ID: <57dd517f-f3c9-5818-780b-c3a8d4c29d5a@gmail.com> (raw)
In-Reply-To: <Y1ennbK6WSHT27Am@paasikivi.fi.intel.com>

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

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~


  reply	other threads:[~2022-10-25  9:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25  8:50 [PATCH 0/2] fix fwnode_irq_get_byname() returnvalue Matti Vaittinen
2022-10-25  8:50 ` [PATCH 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Matti Vaittinen
2022-10-25  9:08   ` Sakari Ailus
2022-10-25  9:17     ` Matti Vaittinen [this message]
2022-10-25  9:18   ` Andy Shevchenko
2022-10-25 10:00     ` Vaittinen, Matti
2022-10-25 11:15       ` Andy Shevchenko
2022-10-25  8:51 ` [PATCH 2/2] i2c: i2c-smbus: fwnode_irq_get_byname() return value fix Matti Vaittinen
2022-10-25  9:20 ` [PATCH 0/2] fix fwnode_irq_get_byname() returnvalue Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57dd517f-f3c9-5818-780b-c3a8d4c29d5a@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=akhilrajeev@nvidia.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=djrscally@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=rafael@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®