Skip to contentSkip to conversation

wrapper: rename offset in offset_devp().

PATCH In review Scott Wood 3 participants 4 messages Dec 11, 2007 – Dec 17, 2007 PowerPC

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 1/2 wrapper: rename offset in offset_devp().

fdt_wrapper_create_node passes a variable called offset to offset_devp(), which uses said parameter to initialize a local variable called offset.

Due to one of the odder aspects of the C language, the result is an undefined variable, with no error or warning.

---
 arch/powerpc/boot/libfdt-wrapper.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/boot/libfdt-wrapper.c +2 -2
index 002da16..868c504 100644
@@ -44,8 +44,8 @@
 
 #define offset_devp(off)	\
 	({ \
-		int offset = (off); \
-		check_err(offset) ? NULL : (void *)(offset+1); \
+		int _offset = (off); \
+		check_err(_offset) ? NULL : (void *)(_offset+1); \
 	})
 
 #define devp_offset(devp)	(((int)(devp))-1)
Signature · 1 line
1.5.3.7
#1 lore raw

arch/powerpc/boot/libfdt-wrapper.c line 49

Quoted 8 lines · On Tue, 11 Dec 2007 15:23:04 -0600 Scott Wood <[email protected]> wrote:

#define offset_devp(off) \

arch/powerpc/boot/libfdt-wrapper.c +2 -2
 	({ \
-		int offset = (off); \
-		check_err(offset) ? NULL : (void *)(offset+1); \
+		int _offset = (off); \
+		check_err(_offset) ? NULL : (void *)(_offset+1); \
 	})

Just wondering if this could be a static inline function?

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#2 lore raw
Quoted 11 lines · Stephen Rothwell

arch/powerpc/boot/libfdt-wrapper.c line 49

Quoted 8 lines · On Tue, 11 Dec 2007 15:23:04 -0600 Scott Wood <[email protected]> wrote:

#define offset_devp(off) \

arch/powerpc/boot/libfdt-wrapper.c +2 -2
 	({ \
-		int offset = (off); \
-		check_err(offset) ? NULL : (void *)(offset+1); \
+		int _offset = (off); \
+		check_err(_offset) ? NULL : (void *)(_offset+1); \
 	})

Just wondering if this could be a static inline function?

Alas, not really. If we did that, then the __FUNCTION__ and __LINE__ we use in the error message inside check_err() would always refer to the offset_devp() function, which would be substantially less useful than referring to the function which invoked the offset_devp() macro.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Acked-by on v1 1/2
#3 lore raw
In reply to Scott Wood
Quoted 5 lines · Scott Wood

fdt_wrapper_create_node passes a variable called offset to offset_devp(), which uses said parameter to initialize a local variable called offset.

Due to one of the odder aspects of the C language, the result is an undefined variable, with no error or warning.

Ouch, nasty! Good catch.

Quoted 1 line
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson