Skip to contentSkip to conversation

gianfar: Fix tests of unsigneds in gfar_parse_group()

PATCH In review Roel Kluin 2 participants 4 messages Dec 15, 2009 – Dec 16, 2009

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 gianfar: Fix tests of unsigneds in gfar_parse_group()

interruptTransmit, -Receive and -Error are unsigned so the tests did not work.

This also changes that if irq_of_parse_and_map(np, 0) returns NO_IRQ, that gfar_parse_group() returns an -EINVAL.

---
Found using coccinelle: http://coccinelle.lip6.fr/

drivers/net/gianfar.c +13 -10
index 6850dc0..c411682 100644
@@ -522,6 +522,7 @@ static int gfar_parse_group(struct device_node *np,
 {
 	u32 *queue_mask;
 	u64 addr, size;
+	int irq;
 
 	addr = of_translate_address(np,
 			of_get_address(np, 0, &size, NULL));
@@ -530,20 +531,22 @@ static int gfar_parse_group(struct device_node *np,
 	if (!priv->gfargrp[priv->num_grps].regs)
 		return -ENOMEM;
 
-	priv->gfargrp[priv->num_grps].interruptTransmit =
-			irq_of_parse_and_map(np, 0);
+	irq = irq_of_parse_and_map(np, 0);
+	if (irq < 0)
+		return -EINVAL;
+	priv->gfargrp[priv->num_grps].interruptTransmit = irq;
 
 	/* If we aren't the FEC we have multiple interrupts */
 	if (model && strcasecmp(model, "FEC")) {
-		priv->gfargrp[priv->num_grps].interruptReceive =
-			irq_of_parse_and_map(np, 1);
-		priv->gfargrp[priv->num_grps].interruptError =
-			irq_of_parse_and_map(np,2);
-		if (priv->gfargrp[priv->num_grps].interruptTransmit < 0 ||
-			priv->gfargrp[priv->num_grps].interruptReceive < 0 ||
-			priv->gfargrp[priv->num_grps].interruptError < 0) {
+		irq = irq_of_parse_and_map(np, 1);
+		if (irq < 0)
 			return -EINVAL;
-		}
+		priv->gfargrp[priv->num_grps].interruptReceive = irq;
+
+		irq = irq_of_parse_and_map(np, 2);
+		if (irq < 0)
+			return -EINVAL;
+		priv->gfargrp[priv->num_grps].interruptError = irq;
 	}
 
 	priv->gfargrp[priv->num_grps].grp_id = priv->num_grps;
#1 lore raw
Quoted 57 lines

interruptTransmit, -Receive and -Error are unsigned so the tests did not work.

This also changes that if irq_of_parse_and_map(np, 0) returns NO_IRQ, that
gfar_parse_group() returns an -EINVAL.

---
Found using coccinelle: http://coccinelle.lip6.fr/

drivers/net/gianfar.c +1 -1
index 6850dc0..c411682 100644
@@ -522,6 +522,7 @@ static int gfar_parse_group(struct 
 device_node *np,  {
 	u32 *queue_mask;
 	u64 addr, size;
+	int irq;
 
 	addr = of_translate_address(np,
 			of_get_address(np, 0, &size, NULL)); @@ 
-530,20 +531,22 @@ static int gfar_parse_group(struct device_node *np,
	if (!priv->gfargrp[priv->num_grps].regs)
		return -ENOMEM;
drivers/net/gianfar.c +4 -2
-	priv->gfargrp[priv->num_grps].interruptTransmit =
-			irq_of_parse_and_map(np, 0);
+	irq = irq_of_parse_and_map(np, 0);
+	if (irq < 0)
+		return -EINVAL;
+	priv->gfargrp[priv->num_grps].interruptTransmit = irq;
	/* If we aren't the FEC we have multiple interrupts */
	if (model && strcasecmp(model, "FEC")) {
drivers/net/gianfar.c +0 -5
-		priv->gfargrp[priv->num_grps].interruptReceive =
-			irq_of_parse_and_map(np, 1);
-		priv->gfargrp[priv->num_grps].interruptError =
-			irq_of_parse_and_map(np,2);
-		if 

(priv->gfargrp[priv->num_grps].interruptTransmit < 0 ||

drivers/net/gianfar.c +0 -1
-			

priv->gfargrp[priv->num_grps].interruptReceive < 0 ||

drivers/net/gianfar.c +0 -1
-			

priv->gfargrp[priv->num_grps].interruptError < 0) {

drivers/net/gianfar.c +2 -0
+		irq = irq_of_parse_and_map(np, 1);
+		if (irq < 0)
			return -EINVAL;
drivers/net/gianfar.c +6 -1
-		}
+		priv->gfargrp[priv->num_grps].interruptReceive = irq;
+
+		irq = irq_of_parse_and_map(np, 2);
+		if (irq < 0)
+			return -EINVAL;
+		priv->gfargrp[priv->num_grps].interruptError = irq;
Quoted 3 lines
	}

	priv->gfargrp[priv->num_grps].grp_id = priv->num_grps;

Won't it be better to change types of interruptTransmit, -Receive and -Error
in struct gfar_priv_grp itself. Something like this:

struct gfar_priv_grp {
....
- unsigned int interruptTransmit;
- unsigned int interruptReceive;
- unsigned int interruptError;

+ unsigned int interruptTransmit;
+ unsigned int interruptReceive;
+ unsigned int interruptError;
....
}

--

Thanks
Sandeep

#2 lore raw
In reply to Roel Kluin
Quoted 15 lines

Won't it be better to change types of interruptTransmit, -Receive and -Error in struct gfar_priv_grp itself. Something like this:

struct gfar_priv_grp {
....

(quoted diff) +3 -3
-	unsigned int interruptTransmit;
-	unsigned int interruptReceive;
-	unsigned int interruptError;
 
+	unsigned int interruptTransmit;
+	unsigned int interruptReceive;
+	unsigned int interruptError;
....
Quoted 2 lines

}

Sorry for my earlier mail, What I meant is something like this:

struct gfar_priv_grp {
....
- unsigned int interruptTransmit;
- unsigned int interruptReceive;
- unsigned int interruptError;

+ int interruptTransmit;
+ int interruptReceive;
+ int interruptError;
....
}

--

Thanks
Sandeep

author
#3 lore raw
Quoted 17 lines · On Wed, Dec 16, 2009 at 6:04 AM, Kumar Gopalpet-B05799 <[email protected]>…
Quoted 4 lines

Won't it be better to change types of interruptTransmit, -Receive and -Error in  struct gfar_priv_grp itself. Something like this:

struct gfar_priv_grp {
....
-       unsigned int interruptTransmit;
-       unsigned int interruptReceive;
-       unsigned int interruptError;

+       int interruptTransmit;
+       int interruptReceive;
+       int interruptError;
....
}

Quoted 4 lines

--

Thanks
Sandeep

I don't think that's better. Only the error returned is signed, If none occurred the irq thereafter is unsigned.

Thanks,

Roel