Re: Fix return value of OF_getprop() when name has a '@' in it
> Date: Tue, 14 Jun 2016 14:33:14 +0100 (BST) > From: Tom Cosgrove> > >>> Tom Cosgrove 12-Jun-16 22:05 >>> > > > > In OF_getprop(), if the "name" property doesn't exist it is synthesised > > from the unit name. If that synthesised property has an "@" in it, we > > truncate the name just before the "@", but we currently continue to return > > the full length of the unit name. > > > > This diff returns the length of the truncated name. > > > > Thanks > > > > Tom > > Updated diff following the recent commit to fdt.c > > Ensures that OF_getprop() returns the same length value that > OF_getproplen() did when it's called on a node name with '@' in it > > (Also implemented slightly differently this time, keeping a single 'return' > and instead re-calculating 'len'.) > > Thanks Thanks Tom, had to get that other diff out of the way before testing this. It's committed now. > Index: sys/dev/ofw/fdt.c > === > RCS file: /home/OpenBSD/cvs/src/sys/dev/ofw/fdt.c,v > retrieving revision 1.13 > diff -u -p -r1.13 fdt.c > --- sys/dev/ofw/fdt.c 14 Jun 2016 10:03:51 - 1.13 > +++ sys/dev/ofw/fdt.c 14 Jun 2016 13:29:39 - > @@ -782,8 +782,10 @@ OF_getprop(int handle, char *prop, void > if (data) { > len = strlcpy(buf, data, buflen); > data = strchr(buf, '@'); > - if (data) > + if (data) { > *data = 0; > + len = data - (char *)buf; > + } > return len + 1; > } > } > >
Re: Fix return value of OF_getprop() when name has a '@' in it
>>> Tom Cosgrove 12-Jun-16 22:05 >>> > > In OF_getprop(), if the "name" property doesn't exist it is synthesised > from the unit name. If that synthesised property has an "@" in it, we > truncate the name just before the "@", but we currently continue to return > the full length of the unit name. > > This diff returns the length of the truncated name. > > Thanks > > Tom Updated diff following the recent commit to fdt.c Ensures that OF_getprop() returns the same length value that OF_getproplen() did when it's called on a node name with '@' in it (Also implemented slightly differently this time, keeping a single 'return' and instead re-calculating 'len'.) Thanks Tom Index: sys/dev/ofw/fdt.c === RCS file: /home/OpenBSD/cvs/src/sys/dev/ofw/fdt.c,v retrieving revision 1.13 diff -u -p -r1.13 fdt.c --- sys/dev/ofw/fdt.c 14 Jun 2016 10:03:51 - 1.13 +++ sys/dev/ofw/fdt.c 14 Jun 2016 13:29:39 - @@ -782,8 +782,10 @@ OF_getprop(int handle, char *prop, void if (data) { len = strlcpy(buf, data, buflen); data = strchr(buf, '@'); - if (data) + if (data) { *data = 0; + len = data - (char *)buf; + } return len + 1; } }
Fix return value of OF_getprop() when name has a '@' in it
In OF_getprop(), if the "name" property doesn't exist it is synthesised from the unit name. If that synthesised property has an "@" in it, we truncate the name just before the "@", but we currently continue to return the full length of the unit name. This diff returns the length of the truncated name. Thanks Tom Index: sys/dev/ofw/fdt.c === RCS file: /home/OpenBSD/cvs/src/sys/dev/ofw/fdt.c,v retrieving revision 1.12 diff -u -p -u -r1.12 fdt.c --- sys/dev/ofw/fdt.c 12 Jun 2016 12:55:42 - 1.12 +++ sys/dev/ofw/fdt.c 12 Jun 2016 20:59:31 - @@ -782,8 +782,10 @@ OF_getprop(int handle, char *prop, void if (data) { len = strlcpy(buf, data, buflen); data = strchr(buf, '@'); - if (data) + if (data) { *data = 0; + return data - (char *)buf + 1; + } return len + 1; } }