From 440eb8cb1201e57b14edadfb7633284866ce6d4a Mon Sep 17 00:00:00 2001 From: leitao Date: Thu, 7 Jun 2018 15:59:08 +0000 Subject: [PATCH] dev/ofw: Fix ofw_fdt_getprop() return values to match documentation Fix the behavior of ofw_fdt_getprop() and ofw_fdt_getprop() functions to match the documentation as the non-fdt code. Submitted by: Luis Pires Reviewed by: manu, jhibbits Approved by: jhibbits (mentor) Differential Revision: https://reviews.freebsd.org/D15680 --- sys/dev/ofw/ofw_fdt.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index 92c71c710a5e..aa7eadfdb022 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -279,8 +279,6 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, /* Emulate the 'name' property */ name = fdt_get_name(fdtp, offset, &len); strncpy(buf, name, buflen); - if (len + 1 > buflen) - len = buflen; return (len + 1); } @@ -299,9 +297,8 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, if (prop == NULL) return (-1); - if (len > buflen) - len = buflen; - bcopy(prop, buf, len); + bcopy(prop, buf, min(len, buflen)); + return (len); }