* Re: [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname()
2014-05-19 13:30 [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname() Grygorii Strashko
@ 2014-05-19 12:57 ` Thierry Reding
2014-05-20 6:17 ` Grant Likely
2014-05-20 10:42 ` Grygorii Strashko
0 siblings, 2 replies; 5+ messages in thread
From: Thierry Reding @ 2014-05-19 12:57 UTC (permalink / raw)
To: Grygorii Strashko
Cc: Greg Kroah-Hartman, Rob Herring, Grant Likely, santosh.shilimkar,
linux-kernel, devicetree, linux-arm-kernel, Russell King,
Rob Herring, Tony Lindgren
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]
On Mon, May 19, 2014 at 04:30:59PM +0300, Grygorii Strashko wrote:
[...]
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
[...]
> /**
> + * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number
> + * @dev: pointer to device tree node
> + * @name: zero-based index of the irq
This is a name, not an index.
> + *
> + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain
> + * is not yet created, or errorno in case of failure.
s/errorno/error code/? Also EPROBE_DEFER is also an error code, so I'm
not sure if it's worth a special case in the description here.
> + *
> + */
> +int of_irq_get_byname(struct device_node *dev, const char *name)
> +{
> + const char *name_irq = NULL;
> + int index = 0;
> +
> + if (unlikely(!name))
> + return -EINVAL;
> +
> + while (!of_property_read_string_index(dev, "interrupt-names",
> + index, &name_irq))
> + if (!strcmp(name, name_irq))
> + return of_irq_get(dev, index);
Isn't this missing an index++ somewhere? Otherwise it seems like this
would loop infinitely if there was no match on the first entry.
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname()
@ 2014-05-19 13:30 Grygorii Strashko
2014-05-19 12:57 ` Thierry Reding
0 siblings, 1 reply; 5+ messages in thread
From: Grygorii Strashko @ 2014-05-19 13:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rob Herring, Grant Likely
Cc: santosh.shilimkar, linux-kernel, devicetree, linux-arm-kernel,
Grygorii Strashko, Russell King, Rob Herring, Tony Lindgren,
Thierry Reding
The commit 9ec36cafe43bf835f8f29273597a5b0cbc8267ef
"of/irq: do irq resolution in platform_get_irq" from Rob Herring -
moves resolving of the interrupt resources in platform_get_irq().
But this solution isn't complete because platform_get_irq_byname()
need to be modified the same way.
Hence, fix it by adding interrupt resolution code at the
platform_get_irq_byname() function too.
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Rob Herring <robh@kernel.org>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
drivers/base/platform.c | 7 +++++--
drivers/of/irq.c | 25 +++++++++++++++++++++++++
include/linux/of_irq.h | 5 +++++
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 5b47210..9e9227e 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -131,9 +131,12 @@ EXPORT_SYMBOL_GPL(platform_get_resource_byname);
*/
int platform_get_irq_byname(struct platform_device *dev, const char *name)
{
- struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ,
- name);
+ struct resource *r;
+
+ if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node)
+ return of_irq_get_byname(dev->dev.of_node, name);
+ r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
return r ? r->start : -ENXIO;
}
EXPORT_SYMBOL_GPL(platform_get_irq_byname);
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 5aeb894..6419de9 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -406,6 +406,31 @@ int of_irq_get(struct device_node *dev, int index)
}
/**
+ * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number
+ * @dev: pointer to device tree node
+ * @name: zero-based index of the irq
+ *
+ * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain
+ * is not yet created, or errorno in case of failure.
+ *
+ */
+int of_irq_get_byname(struct device_node *dev, const char *name)
+{
+ const char *name_irq = NULL;
+ int index = 0;
+
+ if (unlikely(!name))
+ return -EINVAL;
+
+ while (!of_property_read_string_index(dev, "interrupt-names",
+ index, &name_irq))
+ if (!strcmp(name, name_irq))
+ return of_irq_get(dev, index);
+
+ return -ENXIO;
+}
+
+/**
* of_irq_count - Count the number of IRQs a node uses
* @dev: pointer to device tree node
*/
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 6404253..bfec136 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -45,6 +45,7 @@ extern void of_irq_init(const struct of_device_id *matches);
#ifdef CONFIG_OF_IRQ
extern int of_irq_count(struct device_node *dev);
extern int of_irq_get(struct device_node *dev, int index);
+extern int of_irq_get_byname(struct device_node *dev, const char *name);
#else
static inline int of_irq_count(struct device_node *dev)
{
@@ -54,6 +55,10 @@ static inline int of_irq_get(struct device_node *dev, int index)
{
return 0;
}
+static inline int of_irq_get_byname(struct device_node *dev, const char *name)
+{
+ return 0;
+}
#endif
#if defined(CONFIG_OF)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname()
2014-05-19 12:57 ` Thierry Reding
@ 2014-05-20 6:17 ` Grant Likely
2014-05-20 10:45 ` Grygorii Strashko
2014-05-20 10:42 ` Grygorii Strashko
1 sibling, 1 reply; 5+ messages in thread
From: Grant Likely @ 2014-05-20 6:17 UTC (permalink / raw)
To: Thierry Reding, Grygorii Strashko
Cc: Greg Kroah-Hartman, Rob Herring, santosh.shilimkar, linux-kernel,
devicetree, linux-arm-kernel, Russell King, Rob Herring,
Tony Lindgren
On Mon, 19 May 2014 14:57:39 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
> On Mon, May 19, 2014 at 04:30:59PM +0300, Grygorii Strashko wrote:
> [...]
> > diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> [...]
> > /**
> > + * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number
> > + * @dev: pointer to device tree node
> > + * @name: zero-based index of the irq
>
> This is a name, not an index.
>
> > + *
> > + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain
> > + * is not yet created, or errorno in case of failure.
>
> s/errorno/error code/? Also EPROBE_DEFER is also an error code, so I'm
> not sure if it's worth a special case in the description here.
>
> > + *
> > + */
> > +int of_irq_get_byname(struct device_node *dev, const char *name)
> > +{
> > + const char *name_irq = NULL;
> > + int index = 0;
> > +
> > + if (unlikely(!name))
> > + return -EINVAL;
> > +
> > + while (!of_property_read_string_index(dev, "interrupt-names",
> > + index, &name_irq))
> > + if (!strcmp(name, name_irq))
> > + return of_irq_get(dev, index);
>
> Isn't this missing an index++ somewhere? Otherwise it seems like this
> would loop infinitely if there was no match on the first entry.
Better yet, use of_property_match_string().
g.
>
> Thierry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname()
2014-05-19 12:57 ` Thierry Reding
2014-05-20 6:17 ` Grant Likely
@ 2014-05-20 10:42 ` Grygorii Strashko
1 sibling, 0 replies; 5+ messages in thread
From: Grygorii Strashko @ 2014-05-20 10:42 UTC (permalink / raw)
To: Thierry Reding
Cc: Greg Kroah-Hartman, Rob Herring, Grant Likely, santosh.shilimkar,
linux-kernel, devicetree, linux-arm-kernel, Russell King,
Rob Herring, Tony Lindgren
Hi Thierry,
On 05/19/2014 03:57 PM, Thierry Reding wrote:
> On Mon, May 19, 2014 at 04:30:59PM +0300, Grygorii Strashko wrote:
> [...]
>> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> [...]
>> /**
>> + * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number
>> + * @dev: pointer to device tree node
>> + * @name: zero-based index of the irq
>
> This is a name, not an index.
>
>> + *
>> + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain
>> + * is not yet created, or errorno in case of failure.
>
> s/errorno/error code/? Also EPROBE_DEFER is also an error code, so I'm
> not sure if it's worth a special case in the description here.
>From my experience, It's very useful to know that function can return
EPROBE_DEFER, otherwise, the code need to be traced till place where
EPROBE_DEFER is returned.
>
>> + *
>> + */
>> +int of_irq_get_byname(struct device_node *dev, const char *name)
>> +{
>> + const char *name_irq = NULL;
>> + int index = 0;
>> +
>> + if (unlikely(!name))
>> + return -EINVAL;
>> +
>> + while (!of_property_read_string_index(dev, "interrupt-names",
>> + index, &name_irq))
>> + if (!strcmp(name, name_irq))
>> + return of_irq_get(dev, index);
>
> Isn't this missing an index++ somewhere? Otherwise it seems like this
> would loop infinitely if there was no match on the first entry.
Omg. You're right. It was bad day (
Thanks for your review. Patch re-sent.
Regards,
-grygorii
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname()
2014-05-20 6:17 ` Grant Likely
@ 2014-05-20 10:45 ` Grygorii Strashko
0 siblings, 0 replies; 5+ messages in thread
From: Grygorii Strashko @ 2014-05-20 10:45 UTC (permalink / raw)
To: Grant Likely, Thierry Reding
Cc: Greg Kroah-Hartman, Rob Herring, santosh.shilimkar, linux-kernel,
devicetree, linux-arm-kernel, Russell King, Rob Herring,
Tony Lindgren
Hi Grant,
On 05/20/2014 09:17 AM, Grant Likely wrote:
> On Mon, 19 May 2014 14:57:39 +0200, Thierry Reding <thierry.reding@gmail.com> wrote:
>> On Mon, May 19, 2014 at 04:30:59PM +0300, Grygorii Strashko wrote:
>> [...]
>>> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
>> [...]
>>> /**
>>> + * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number
>>> + * @dev: pointer to device tree node
>>> + * @name: zero-based index of the irq
>>
>> This is a name, not an index.
>>
>>> + *
>>> + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain
>>> + * is not yet created, or errorno in case of failure.
>>
>> s/errorno/error code/? Also EPROBE_DEFER is also an error code, so I'm
>> not sure if it's worth a special case in the description here.
>>
>>> + *
>>> + */
>>> +int of_irq_get_byname(struct device_node *dev, const char *name)
>>> +{
>>> + const char *name_irq = NULL;
>>> + int index = 0;
>>> +
>>> + if (unlikely(!name))
>>> + return -EINVAL;
>>> +
>>> + while (!of_property_read_string_index(dev, "interrupt-names",
>>> + index, &name_irq))
>>> + if (!strcmp(name, name_irq))
>>> + return of_irq_get(dev, index);
>>
>> Isn't this missing an index++ somewhere? Otherwise it seems like this
>> would loop infinitely if there was no match on the first entry.
>
> Better yet, use of_property_match_string().
yep. Thanks. I've just come to the same idea. Patch re-sent.
Regards,
-grygorii
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-20 9:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-19 13:30 [RFC PATCH] of/irq: do irq resolution in platform_get_irq_byname() Grygorii Strashko
2014-05-19 12:57 ` Thierry Reding
2014-05-20 6:17 ` Grant Likely
2014-05-20 10:45 ` Grygorii Strashko
2014-05-20 10:42 ` Grygorii Strashko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox