linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc
@ 2022-10-25  5:24 Matti Vaittinen
  2022-10-25  6:48 ` Sakari Ailus
  0 siblings, 1 reply; 5+ messages in thread
From: Matti Vaittinen @ 2022-10-25  5:24 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Wolfram Sang, Akhil R,
	linux-acpi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

The fwnode_irq_get_byname() may return zero on device-tree mapping
error. Fix documentation to reflect this as current documentation
suggests check:

if (ret < 0)
is enough to detect the errors. This is not the case.

Add zero as a return value indicating error.

Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
 drivers/base/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 4d6278a84868..df437d10aa08 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -960,7 +960,7 @@ EXPORT_SYMBOL(fwnode_irq_get);
  * string.
  *
  * Return:
- * Linux IRQ number on success, or negative errno otherwise.
+ * Linux IRQ number on success, zero or negative errno otherwise.
  */
 int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
 {
-- 
2.37.3


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc
  2022-10-25  5:24 [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc Matti Vaittinen
@ 2022-10-25  6:48 ` Sakari Ailus
  2022-10-25  7:06   ` Matti Vaittinen
  0 siblings, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2022-10-25  6:48 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Wolfram Sang, Akhil R,
	linux-acpi, linux-kernel

Moi,

On Tue, Oct 25, 2022 at 08:24:24AM +0300, Matti Vaittinen wrote:
> The fwnode_irq_get_byname() may return zero on device-tree mapping
> error. Fix documentation to reflect this as current documentation
> suggests check:
> 
> if (ret < 0)
> is enough to detect the errors. This is not the case.
> 
> Add zero as a return value indicating error.
> 
> Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> ---
>  drivers/base/property.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 4d6278a84868..df437d10aa08 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -960,7 +960,7 @@ EXPORT_SYMBOL(fwnode_irq_get);
>   * string.
>   *
>   * Return:
> - * Linux IRQ number on success, or negative errno otherwise.
> + * Linux IRQ number on success, zero or negative errno otherwise.

I wonder if it would be possible instead to always return a negative error
code on error. Returning zero on error is really unconventional and can be
expected to be a source of bugs.

We have code already that takes the error code zero into account in e.g.

static int smbalert_probe(struct i2c_client *ara,
                          const struct i2c_device_id *id)
{
...
                irq = fwnode_irq_get_byname(dev_fwnode(adapter->dev.parent),
                                            "smbus_alert");
                if (irq <= 0)
                        return irq;

And zero turns into successful probe!

>   */
>  int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
>  {

-- 
Terveisin,

Sakari Ailus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc
  2022-10-25  6:48 ` Sakari Ailus
@ 2022-10-25  7:06   ` Matti Vaittinen
  2022-10-25  7:17     ` Matti Vaittinen
  0 siblings, 1 reply; 5+ messages in thread
From: Matti Vaittinen @ 2022-10-25  7:06 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Matti Vaittinen, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Wolfram Sang, Akhil R,
	linux-acpi, linux-kernel

Hi Sakari,

On 10/25/22 09:48, Sakari Ailus wrote:
> Moi,
> 
> On Tue, Oct 25, 2022 at 08:24:24AM +0300, Matti Vaittinen wrote:
>> The fwnode_irq_get_byname() may return zero on device-tree mapping
>> error. Fix documentation to reflect this as current documentation
>> suggests check:
>>
>> if (ret < 0)
>> is enough to detect the errors. This is not the case.
>>
>> Add zero as a return value indicating error.
>>
>> Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
>> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>> ---
>>   drivers/base/property.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/property.c b/drivers/base/property.c
>> index 4d6278a84868..df437d10aa08 100644
>> --- a/drivers/base/property.c
>> +++ b/drivers/base/property.c
>> @@ -960,7 +960,7 @@ EXPORT_SYMBOL(fwnode_irq_get);
>>    * string.
>>    *
>>    * Return:
>> - * Linux IRQ number on success, or negative errno otherwise.
>> + * Linux IRQ number on success, zero or negative errno otherwise.
> 
> I wonder if it would be possible instead to always return a negative error
> code on error. Returning zero on error is really unconventional and can be
> expected to be a source of bugs.

Agree, and I did also consider just adding:

if (!ret)
	return -EINVAL; (or another feasible errno)

return ret;

at the end of the fwnode_irq_get_byname().

However, such a functional change would require auditing the existing 
callers which I have no time right now.
if (someone is up to the task)
	be my guest :)
else
	please fix the doc ;)

Yours
	-- Matti

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

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc
  2022-10-25  7:06   ` Matti Vaittinen
@ 2022-10-25  7:17     ` Matti Vaittinen
  2022-10-25  7:43       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Matti Vaittinen @ 2022-10-25  7:17 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Matti Vaittinen, Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Wolfram Sang, Akhil R,
	linux-acpi, linux-kernel

ti 25. lokak. 2022 klo 10.06 Matti Vaittinen
(mazziesaccount@gmail.com) kirjoitti:
>
> Hi Sakari,
>
> On 10/25/22 09:48, Sakari Ailus wrote:
> > Moi,
> >
> > On Tue, Oct 25, 2022 at 08:24:24AM +0300, Matti Vaittinen wrote:
> >> The fwnode_irq_get_byname() may return zero on device-tree mapping
> >> error. Fix documentation to reflect this as current documentation
> >> suggests check:
> >>
> >> if (ret < 0)
> >> is enough to detect the errors. This is not the case.
> >>
> >> Add zero as a return value indicating error.
> >>
> >> Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
> >> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> >> ---
> >>   drivers/base/property.c | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/base/property.c b/drivers/base/property.c
> >> index 4d6278a84868..df437d10aa08 100644
> >> --- a/drivers/base/property.c
> >> +++ b/drivers/base/property.c
> >> @@ -960,7 +960,7 @@ EXPORT_SYMBOL(fwnode_irq_get);
> >>    * string.
> >>    *
> >>    * Return:
> >> - * Linux IRQ number on success, or negative errno otherwise.
> >> + * Linux IRQ number on success, zero or negative errno otherwise.
> >
> > I wonder if it would be possible instead to always return a negative error
> > code on error. Returning zero on error is really unconventional and can be
> > expected to be a source of bugs.
>
> Agree, and I did also consider just adding:
>
> if (!ret)
>         return -EINVAL; (or another feasible errno)
>
> return ret;
>
> at the end of the fwnode_irq_get_byname().
>
> However, such a functional change would require auditing the existing
> callers which I have no time right now.

Oh. I just did grep the callers. It seems to me that there are only a
handful of callers in 6.1-rc2. Auditing those does not seem like a big
task after all. So I guess I can check them if changing the return
value is preferred.

Yours,
--Matti

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc
  2022-10-25  7:17     ` Matti Vaittinen
@ 2022-10-25  7:43       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2022-10-25  7:43 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Sakari Ailus, Matti Vaittinen, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Rafael J. Wysocki, Wolfram Sang, Akhil R,
	linux-acpi, linux-kernel

On Tue, Oct 25, 2022 at 10:17:21AM +0300, Matti Vaittinen wrote:
> ti 25. lokak. 2022 klo 10.06 Matti Vaittinen
> (mazziesaccount@gmail.com) kirjoitti:
> >
> > Hi Sakari,
> >
> > On 10/25/22 09:48, Sakari Ailus wrote:
> > > Moi,
> > >
> > > On Tue, Oct 25, 2022 at 08:24:24AM +0300, Matti Vaittinen wrote:
> > >> The fwnode_irq_get_byname() may return zero on device-tree mapping
> > >> error. Fix documentation to reflect this as current documentation
> > >> suggests check:
> > >>
> > >> if (ret < 0)
> > >> is enough to detect the errors. This is not the case.
> > >>
> > >> Add zero as a return value indicating error.
> > >>
> > >> Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname")
> > >> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> > >> ---
> > >>   drivers/base/property.c | 2 +-
> > >>   1 file changed, 1 insertion(+), 1 deletion(-)
> > >>
> > >> diff --git a/drivers/base/property.c b/drivers/base/property.c
> > >> index 4d6278a84868..df437d10aa08 100644
> > >> --- a/drivers/base/property.c
> > >> +++ b/drivers/base/property.c
> > >> @@ -960,7 +960,7 @@ EXPORT_SYMBOL(fwnode_irq_get);
> > >>    * string.
> > >>    *
> > >>    * Return:
> > >> - * Linux IRQ number on success, or negative errno otherwise.
> > >> + * Linux IRQ number on success, zero or negative errno otherwise.
> > >
> > > I wonder if it would be possible instead to always return a negative error
> > > code on error. Returning zero on error is really unconventional and can be
> > > expected to be a source of bugs.
> >
> > Agree, and I did also consider just adding:
> >
> > if (!ret)
> >         return -EINVAL; (or another feasible errno)
> >
> > return ret;
> >
> > at the end of the fwnode_irq_get_byname().
> >
> > However, such a functional change would require auditing the existing
> > callers which I have no time right now.
> 
> Oh. I just did grep the callers. It seems to me that there are only a
> handful of callers in 6.1-rc2. Auditing those does not seem like a big
> task after all. So I guess I can check them if changing the return
> value is preferred.

Yes, please do so.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-25  7:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  5:24 [PATCH] drivers: fwnode: fix fwnode_irq_get_byname() kerneldoc Matti Vaittinen
2022-10-25  6:48 ` Sakari Ailus
2022-10-25  7:06   ` Matti Vaittinen
2022-10-25  7:17     ` Matti Vaittinen
2022-10-25  7:43       ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).