diff mbox

[V2,12/19] irqchip: crossbar: return proper error value

Message ID 1402574007-13987-13-git-send-email-r.sricharan@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

R Sricharan June 12, 2014, 11:53 a.m. UTC
From: Nishanth Menon <nm@ti.com>

crossbar_of_init always returns -ENOMEM in case of errors, return proper
error results in case of failures.

Signed-off-by: Nishanth Menon <nm@ti.com>
---
 drivers/irqchip/irq-crossbar.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Jason Cooper June 12, 2014, 1:39 p.m. UTC | #1
On Thu, Jun 12, 2014 at 05:23:20PM +0530, Sricharan R wrote:
> From: Nishanth Menon <nm@ti.com>
> 
> crossbar_of_init always returns -ENOMEM in case of errors, return proper
> error results in case of failures.

Please describe what the other possible failures are and how the changes
are more correct.

> 
> Signed-off-by: Nishanth Menon <nm@ti.com>
> ---
>  drivers/irqchip/irq-crossbar.c |   15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-crossbar.c b/drivers/irqchip/irq-crossbar.c
> index fea3e5d..524e6e9 100644
> --- a/drivers/irqchip/irq-crossbar.c
> +++ b/drivers/irqchip/irq-crossbar.c
> @@ -140,20 +140,26 @@ static const struct irq_domain_ops routable_irq_domain_ops = {
>  static int __init crossbar_of_init(struct device_node *node,
>  				   const struct crossbar_data *data)
>  {
> -	int i, size, max, reserved = 0, entry, safe_map;
> +	int i, size, max = 0, reserved = 0, entry, safe_map;
>  	const __be32 *irqsr;
>  	const int *irqsk = NULL;
> +	int ret = -ENOMEM;
>  
>  	cb = kzalloc(sizeof(*cb), GFP_KERNEL);
>  
>  	if (!cb)
> -		return -ENOMEM;
> +		return ret;
>  
>  	cb->crossbar_base = of_iomap(node, 0);
>  	if (!cb->crossbar_base)
>  		goto err1;
>  
>  	of_property_read_u32(node, "ti,max-irqs", &max);
> +	if (!max) {
> +		pr_err("missing 'ti,max-irqs' property\n");
> +		ret = -EINVAL;
> +		goto err2;
> +	}
>  	cb->irq_map = kcalloc(max, sizeof(int), GFP_KERNEL);
>  	if (!cb->irq_map)
>  		goto err2;
> @@ -174,6 +180,7 @@ static int __init crossbar_of_init(struct device_node *node,
>  						   i, &entry);
>  			if (entry > max) {
>  				pr_err("Invalid reserved entry\n");
> +				ret = -EINVAL;
>  				goto err3;
>  			}
>  			cb->irq_map[entry] = IRQ_RESERVED;
> @@ -198,6 +205,7 @@ static int __init crossbar_of_init(struct device_node *node,
>  		break;
>  	default:
>  		pr_err("Invalid reg-size property\n");
> +		ret = -EINVAL;
>  		goto err4;
>  		break;
>  	}
> @@ -225,6 +233,7 @@ static int __init crossbar_of_init(struct device_node *node,
>  
>  			if (entry > max) {
>  				pr_err("Invalid skip entry\n");
> +				ret = -EINVAL;
>  				goto err4;
>  			}
>  			cb->irq_map[entry] = IRQ_SKIP;
> @@ -250,7 +259,7 @@ err2:
>  	iounmap(cb->crossbar_base);
>  err1:
>  	kfree(cb);
> -	return -ENOMEM;
> +	return ret;
>  }

So, where is the change to the successful initialization?  Shouldn't it
now set ret = 0?

This whole function seems to be a hodge-podge of different error
handling styles, which led to the memory leak fixed earlier in this
series.

Please go over this function, choose sane labels, and consolidate _all_
returns to the end of the function.

thx,

Jason.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/irqchip/irq-crossbar.c b/drivers/irqchip/irq-crossbar.c
index fea3e5d..524e6e9 100644
--- a/drivers/irqchip/irq-crossbar.c
+++ b/drivers/irqchip/irq-crossbar.c
@@ -140,20 +140,26 @@  static const struct irq_domain_ops routable_irq_domain_ops = {
 static int __init crossbar_of_init(struct device_node *node,
 				   const struct crossbar_data *data)
 {
-	int i, size, max, reserved = 0, entry, safe_map;
+	int i, size, max = 0, reserved = 0, entry, safe_map;
 	const __be32 *irqsr;
 	const int *irqsk = NULL;
+	int ret = -ENOMEM;
 
 	cb = kzalloc(sizeof(*cb), GFP_KERNEL);
 
 	if (!cb)
-		return -ENOMEM;
+		return ret;
 
 	cb->crossbar_base = of_iomap(node, 0);
 	if (!cb->crossbar_base)
 		goto err1;
 
 	of_property_read_u32(node, "ti,max-irqs", &max);
+	if (!max) {
+		pr_err("missing 'ti,max-irqs' property\n");
+		ret = -EINVAL;
+		goto err2;
+	}
 	cb->irq_map = kcalloc(max, sizeof(int), GFP_KERNEL);
 	if (!cb->irq_map)
 		goto err2;
@@ -174,6 +180,7 @@  static int __init crossbar_of_init(struct device_node *node,
 						   i, &entry);
 			if (entry > max) {
 				pr_err("Invalid reserved entry\n");
+				ret = -EINVAL;
 				goto err3;
 			}
 			cb->irq_map[entry] = IRQ_RESERVED;
@@ -198,6 +205,7 @@  static int __init crossbar_of_init(struct device_node *node,
 		break;
 	default:
 		pr_err("Invalid reg-size property\n");
+		ret = -EINVAL;
 		goto err4;
 		break;
 	}
@@ -225,6 +233,7 @@  static int __init crossbar_of_init(struct device_node *node,
 
 			if (entry > max) {
 				pr_err("Invalid skip entry\n");
+				ret = -EINVAL;
 				goto err4;
 			}
 			cb->irq_map[entry] = IRQ_SKIP;
@@ -250,7 +259,7 @@  err2:
 	iounmap(cb->crossbar_base);
 err1:
 	kfree(cb);
-	return -ENOMEM;
+	return ret;
 }
 
 /* irq number 10,133,139 and 140 cannot be used because of hw bug */