Add serial-number if that fdt property exists.
Details
tested on Raspberry Pi 3B+ and 4
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
sys/dev/ofw/ofw_fdt.c | ||
---|---|---|
194 | what ensures this is NUL terminated? |
sys/dev/ofw/ofw_fdt.c | ||
---|---|---|
194 | Mhm, I don't remember why I used 80 for model but that seems wrong. |
The problem I have with this is that serial-number isn't standard so we don't know what a manufacturer could put in it (string, stringlist, integer etc ...)
Would it be sufficient to check for ASCII with a NUL termination at the end?
We could check the length vs. the buffer size on the others to make sure there is room for the NUL.
I think so.
We could check the length vs. the buffer size on the others to make sure there is room for the NUL.
Yup
sys/dev/ofw/ofw_fdt.c | ||
---|---|---|
207 | So what happens if it is all 'a's, then? I think this fails. I think you want: for (i = 0; i < len - 1; i++) { if (!isascii(fdt_serial[i])) break; } if (i < len || fdt_serial[len - 1] != '\0') fdt_serial[0] = 0; (properly formatted) That is, if there's any non-ascii characters (I'd be tempted even to restrict it to isalnum() instead), break. if we don't get through all the characters, or the last one isn't a NUL, zero the string. |
sys/dev/ofw/ofw_fdt.c | ||
---|---|---|
207 | '-' and '.' are likely to be found in serial number I think. |
Oops, you are right; I tried to combine tests and it failed to check for a final NUL properly. Fixed, and I changed to isprint(); that should be liberal enough.