possible bug? OF_getprop() < sizeof()

Anders Gavare gavare at gmail.com
Fri Jan 20 22:04:41 UTC 2012


If I understood things correctly, there's a possible minor bug in
ofw_machdep.c for PowerPC, in parse_ofw_memory:

/*
 * Get #address-cells from root node, defaulting to 1 if it cannot
 * be found.
 */
phandle = OF_finddevice("/");
if (OF_getprop(phandle, "#address-cells", &address_cells, 
    sizeof(address_cells)) < sizeof(address_cells))
	address_cells = 1;
if (OF_getprop(phandle, "#size-cells", &size_cells, 
    sizeof(size_cells)) < sizeof(size_cells))
	size_cells = 1;

Running the code in GXemul, it seems that the comparison between
OF_getprop's return value (-1 in case the property is not found) and the
sizeof value is done as unsigned integers.

...
<ofwcall(0x908600,&smp_no_rendevous_barrier,&ofw_rendezvous_dispatch,&smp_no_rendevous_barrier,..)>
                                  <0xfff00000(0x908600,"D",0,0,..)>
[ of: getprop(1, "#address-cells", 0x908e7c, 4) ]
[ of: WARNING: getprop: no property '#address-cells' at handle 1 (device
'') ]

<smp_no_rendevous_barrier(0x9085e4,"D",0,0,..)>
                            <spinlock_exit(0x9085e4,"D",0,0,..)>
                              <critical_exit(0x9085e4,"D",0,0,..)>
                      <ofw_real_stop(-1,"D",0,0,..)>
0068bcf8: 2b830003	cmplwi	cr7,r3,3
BREAKPOINT: pc = 0x68bcf8
(The instruction has not yet executed.)
GXemul> print r3
0xffffffffffffffff
GXemul> s 10
0068bcf8:	2b830003	cmplwi	cr7,r3,3
0068bcfc:	419d000c	bc	12,29,0x68bd08	<parse_ofw_memory+0x5c>
0068bd08:	7fc3f378	mr	r3,r30
0068bd0c:	3c800090	lis	r4,144
0068bd10:	3884deb8	subi	r4,r4,8520
0068bd14:	38a10818	addi	r5,r1,2072
0068bd18:	38c00004	li	r6,4
0068bd1c:	4bfe0361	bl	0x66c07c	<OF_getprop>
                  <OF_getprop(0x1,"#size-cells",0x908e78,4,..)>


Real machines perhaps always have #address-cells and #size-cells
properties for the / node, so this problem perhaps does not show up IRL.

However, if this pattern  OF_getprop(...) < sizeof(..)  is common, maybe
there are other similar bugs.

Or did I misunderstand the semantics of cmplwi?

(The binary and source code were from
ftp://ftp.freebsd.org/pub/FreeBSD/releases/powerpc/powerpc/9.0-RELEASE.)


Anders
(not subscribed to the list)




More information about the freebsd-ppc mailing list