Claudio Jeker <cje...@diehard.n-r-g.com> wrote: > On Fri, Apr 07, 2023 at 04:53:52PM +1000, David Gwynne wrote: > > ethernet interfaces in device trees can have a "label" property which > > is generally used (when it is used) to identify which connector it is on > > the case or something like that. eg, eth2 in the turris omnia device > > tree has 'label = "wan"' on the mvneta interface. > > > > ive been using labels in the dts recently to help me figure out what > > goes where, so this has been useful to me. if/when we support switches > > (eg mvsw), their ports are often labelled so i'd like to apply this idea > > to them too. > > > > ok? > > I think doing this is OK but I'm not sure if the usage of OF_getprop() > is correct. OF_getprop() uses 'memcpy(buf, data, min(len, buflen));' > to fill the if_description buffer. So if the provided label is larger than > sizeof(ifp->if_description) the description string is no longer NUL > terminated.
I don't have a problem with the pre-population of the string either. It's informational either way. But claudio is right, OF_getprop() is not like strlcpy, it behaves like strncpy() so if you want to use it you need to copy n-1 bytes, and manuall set the last byte to 0. Or make a new function which is more suitable.