Skip to contentSkip to conversation

sh: Make sure indexes are positive

PATCH In review Roel Kluin 2 participants 2 messages Nov 2, 2009 – Nov 4, 2009 SuperH

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 sh: Make sure indexes are positive

The indexes are signed, make sure they are not negative when we read array elements.

---
 arch/sh/boards/mach-highlander/setup.c |    2 +-
 arch/sh/boards/mach-r2d/irq.c          |    2 +-
 arch/sh/mm/numa.c                      |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Found by code analysis, is this required?

arch/sh/boards/mach-highlander/setup.c +1 -1
index 566e69d..f663c14 100644
@@ -384,7 +384,7 @@ static unsigned char irl2irq[HL_NR_IRL];
 
 static int highlander_irq_demux(int irq)
 {
-	if (irq >= HL_NR_IRL || !irl2irq[irq])
+	if (irq >= HL_NR_IRL || irq < 0 || !irl2irq[irq])
 		return irq;
 
 	return irl2irq[irq];
arch/sh/boards/mach-r2d/irq.c +1 -1
index c70fece..78d7b27 100644
@@ -116,7 +116,7 @@ static unsigned char irl2irq[R2D_NR_IRL];
 
 int rts7751r2d_irq_demux(int irq)
 {
-	if (irq >= R2D_NR_IRL || !irl2irq[irq])
+	if (irq >= R2D_NR_IRL || irq < 0 || !irl2irq[irq])
 		return irq;
 
 	return irl2irq[irq];
arch/sh/mm/numa.c +1 -1
index 9b784fd..6c52444 100644
@@ -60,7 +60,7 @@ void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
 	unsigned long bootmem_paddr;
 
 	/* Don't allow bogus node assignment */
-	BUG_ON(nid > MAX_NUMNODES || nid == 0);
+	BUG_ON(nid > MAX_NUMNODES || nid <= 0);
 
 	start_pfn = start >> PAGE_SHIFT;
 	end_pfn = end >> PAGE_SHIFT;
#1 lore raw
Quoted 4 lines · Roel Kluin

The indexes are signed, make sure they are not negative when we read array elements.

In practice none of these are likely to be an issue, but it doesn't really hurt to add the sanity checks given that there's already a number of them anyways. So, applied.