Skip to contentSkip to conversation

resources: clean up pnp_irq() error return

PATCH In review Dan Carpenter 2 participants 2 messages Nov 7, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 resources: clean up pnp_irq() error return

pnp_irq() returns -1 on error but cast to an unsigned. It is confusing for callers who assume that it returns a negative value. I have introduced a new define IORESOURCE_INVALID which is the same value but hopefully it looks less like a negative value.

include/linux/ioport.h +2 -0
index 89b7c24..fdccfa5 100644
@@ -55,6 +55,8 @@ struct resource {
 #define IORESOURCE_AUTO		0x40000000
 #define IORESOURCE_BUSY		0x80000000	/* Driver has marked this resource busy */
 
+#define IORESOURCE_INVALID	((resource_size_t)-1)
+
 /* PnP IRQ specific bits (IORESOURCE_BITS) */
 #define IORESOURCE_IRQ_HIGHEDGE		(1<<0)
 #define IORESOURCE_IRQ_LOWEDGE		(1<<1)
include/linux/pnp.h +1 -1
index 195aafc..818669c 100644
@@ -151,7 +151,7 @@ static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
 
 	if (pnp_resource_valid(res))
 		return res->start;
-	return -1;
+	return IORESOURCE_INVALID;
 }
 
 static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
#1 lore raw

At Thu, 7 Nov 2013 11:17:49 +0300,

Quoted 5 lines · Dan Carpenter

pnp_irq() returns -1 on error but cast to an unsigned. It is confusing for callers who assume that it returns a negative value. I have introduced a new define IORESOURCE_INVALID which is the same value but hopefully it looks less like a negative value.

How about just returning int instead of resource_size_t? IRQ numbers are handled by int in almost all drivers.

thanks,

Takashi

Quoted 30 lines
include/linux/ioport.h +2 -0
index 89b7c24..fdccfa5 100644
@@ -55,6 +55,8 @@ struct resource {
 #define IORESOURCE_AUTO		0x40000000
 #define IORESOURCE_BUSY		0x80000000	/* Driver has marked this resource busy */
 
+#define IORESOURCE_INVALID	((resource_size_t)-1)
+
 /* PnP IRQ specific bits (IORESOURCE_BITS) */
 #define IORESOURCE_IRQ_HIGHEDGE		(1<<0)
 #define IORESOURCE_IRQ_LOWEDGE		(1<<1)
include/linux/pnp.h +1 -1
index 195aafc..818669c 100644
@@ -151,7 +151,7 @@ static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
 
 	if (pnp_resource_valid(res))
 		return res->start;
-	return -1;
+	return IORESOURCE_INVALID;
 }
 
 static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)