diff mbox

[5/9] of/irq: Introduce __of_irq_to_resource()

Message ID 1379320326-13241-6-git-send-email-treding@nvidia.com
State Not Applicable
Headers show

Commit Message

Thierry Reding Sept. 16, 2013, 8:32 a.m. UTC
This is a version of of_irq_to_resource() that propagates the precise
error code instead of returning 0 for all errors. It will be used in
subsequent patches to allow further propagation of error codes.

To avoid code duplication, implement of_irq_to_resource() as a wrapper
around the new __of_irq_to_resource().

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/of/irq.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

Comments

Rob Herring Sept. 16, 2013, 9:29 p.m. UTC | #1
On 09/16/2013 03:32 AM, Thierry Reding wrote:
> This is a version of of_irq_to_resource() that propagates the precise
> error code instead of returning 0 for all errors. It will be used in
> subsequent patches to allow further propagation of error codes.
> 
> To avoid code duplication, implement of_irq_to_resource() as a wrapper
> around the new __of_irq_to_resource().

I think the callers in this case are manageable to update as well.
Several cases could simply use irq_of_parse_and_map instead as they just
pass in a NULL resource.

Rob

> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/of/irq.c | 33 +++++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/of/irq.c b/drivers/of/irq.c
> index 8225289..57396fd 100644
> --- a/drivers/of/irq.c
> +++ b/drivers/of/irq.c
> @@ -343,15 +343,15 @@ int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq
>  }
>  EXPORT_SYMBOL_GPL(of_irq_map_one);
>  
> -/**
> - * of_irq_to_resource - Decode a node's IRQ and return it as a resource
> - * @dev: pointer to device tree node
> - * @index: zero-based index of the irq
> - * @r: pointer to resource structure to return result into.
> - */
> -int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
> +static int __of_irq_to_resource(struct device_node *dev, unsigned int index,
> +				struct resource *r)
>  {
> -	int irq = irq_of_parse_and_map(dev, index);
> +	unsigned int irq;
> +	int ret;
> +
> +	ret = of_irq_get(dev, index, &irq);
> +	if (ret)
> +		return ret;
>  
>  	/* Only dereference the resource if both the
>  	 * resource and the irq are valid. */
> @@ -373,6 +373,23 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
>  
>  	return irq;
>  }
> +
> +/**
> + * of_irq_to_resource - Decode a node's IRQ and return it as a resource
> + * @dev: pointer to device tree node
> + * @index: zero-based index of the irq
> + * @r: pointer to resource structure to return result into.
> + */
> +int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
> +{
> +	int ret;
> +
> +	ret = __of_irq_to_resource(dev, index, r);
> +	if (ret < 0)
> +		return 0;
> +
> +	return ret;
> +}
>  EXPORT_SYMBOL_GPL(of_irq_to_resource);
>  
>  /**
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Sept. 23, 2013, 7:20 p.m. UTC | #2
On Mon, Sep 16, 2013 at 11:29 PM, Rob Herring <robherring2@gmail.com> wrote:
> On 09/16/2013 03:32 AM, Thierry Reding wrote:
>> This is a version of of_irq_to_resource() that propagates the precise
>> error code instead of returning 0 for all errors. It will be used in
>> subsequent patches to allow further propagation of error codes.
>>
>> To avoid code duplication, implement of_irq_to_resource() as a wrapper
>> around the new __of_irq_to_resource().
>
> I think the callers in this case are manageable to update as well.
> Several cases could simply use irq_of_parse_and_map instead as they just
> pass in a NULL resource.

I second this comment.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Thierry Reding Sept. 23, 2013, 8:50 p.m. UTC | #3
On Mon, Sep 23, 2013 at 09:20:37PM +0200, Linus Walleij wrote:
> On Mon, Sep 16, 2013 at 11:29 PM, Rob Herring <robherring2@gmail.com> wrote:
> > On 09/16/2013 03:32 AM, Thierry Reding wrote:
> >> This is a version of of_irq_to_resource() that propagates the precise
> >> error code instead of returning 0 for all errors. It will be used in
> >> subsequent patches to allow further propagation of error codes.
> >>
> >> To avoid code duplication, implement of_irq_to_resource() as a wrapper
> >> around the new __of_irq_to_resource().
> >
> > I think the callers in this case are manageable to update as well.
> > Several cases could simply use irq_of_parse_and_map instead as they just
> > pass in a NULL resource.
> 
> I second this comment.

That should be fixed in v2 of the series that I posted a few days ago.

Thierry
diff mbox

Patch

diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 8225289..57396fd 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -343,15 +343,15 @@  int of_irq_map_one(struct device_node *device, int index, struct of_irq *out_irq
 }
 EXPORT_SYMBOL_GPL(of_irq_map_one);
 
-/**
- * of_irq_to_resource - Decode a node's IRQ and return it as a resource
- * @dev: pointer to device tree node
- * @index: zero-based index of the irq
- * @r: pointer to resource structure to return result into.
- */
-int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
+static int __of_irq_to_resource(struct device_node *dev, unsigned int index,
+				struct resource *r)
 {
-	int irq = irq_of_parse_and_map(dev, index);
+	unsigned int irq;
+	int ret;
+
+	ret = of_irq_get(dev, index, &irq);
+	if (ret)
+		return ret;
 
 	/* Only dereference the resource if both the
 	 * resource and the irq are valid. */
@@ -373,6 +373,23 @@  int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
 
 	return irq;
 }
+
+/**
+ * of_irq_to_resource - Decode a node's IRQ and return it as a resource
+ * @dev: pointer to device tree node
+ * @index: zero-based index of the irq
+ * @r: pointer to resource structure to return result into.
+ */
+int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
+{
+	int ret;
+
+	ret = __of_irq_to_resource(dev, index, r);
+	if (ret < 0)
+		return 0;
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(of_irq_to_resource);
 
 /**