Message ID | a3bf7094a9f9ebf114736dc7944553dcc701fe73.1666710197.git.mazziesaccount@gmail.com (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
Series | fix fwnode_irq_get_byname() returnvalue | expand |
On Tue, Oct 25, 2022 at 06:11:49PM +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. and abd ? ... > + ret = fwnode_irq_get(fwnode, index); > + /* We treat mapping errors as invalid case */ > + if (ret == 0) > + return -EINVAL; > + > + return ret; This looks good.
diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..b4ccc64f7bd2 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); + /* We treat mapping errors as invalid case */ + if (ret == 0) + return -EINVAL; + + return ret; } EXPORT_SYMBOL(fwnode_irq_get_byname);