Skip to content

Commit 1437e21

Browse files
author
Fox Snowpatch
committed
1 parent a2f7734 commit 1437e21

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

arch/powerpc/boot/ops.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ static inline int getprop(void *devp, const char *name, void *buf, int buflen)
106106
return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
107107
}
108108

109+
static inline int getprop_str(void *devp, const char *name, char *buf,
110+
int buflen)
111+
{
112+
int len;
113+
114+
if (buflen <= 0)
115+
return -1;
116+
117+
len = getprop(devp, name, buf, buflen);
118+
if (len <= 0) {
119+
buf[0] = '\0';
120+
return len;
121+
}
122+
123+
if (len >= buflen) {
124+
buf[buflen - 1] = '\0';
125+
return -1;
126+
}
127+
buf[len] = '\0';
128+
129+
return len;
130+
}
131+
109132
static inline int setprop(void *devp, const char *name,
110133
const void *buf, int buflen)
111134
{
@@ -172,7 +195,7 @@ static inline void *find_node_by_alias(const char *alias)
172195

173196
if (devp) {
174197
char path[MAX_PATH_LEN];
175-
if (getprop(devp, alias, path, MAX_PATH_LEN) > 0)
198+
if (getprop_str(devp, alias, path, MAX_PATH_LEN) > 0)
176199
return finddevice(path);
177200
}
178201

arch/powerpc/boot/serial.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ static void *serial_get_stdout_devp(void)
9090
if (devp == NULL)
9191
goto err_out;
9292

93-
if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0 ||
94-
getprop(devp, "stdout-path", path, MAX_PATH_LEN) > 0) {
93+
if (getprop_str(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0 ||
94+
getprop_str(devp, "stdout-path", path, MAX_PATH_LEN) > 0) {
9595
devp = finddevice(path);
9696
if (devp == NULL)
9797
goto err_out;
9898

99-
if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
99+
if ((getprop_str(devp, "device_type", devtype,
100+
sizeof(devtype)) > 0)
100101
&& !strcmp(devtype, "serial"))
101102
return devp;
102103
}

0 commit comments

Comments
 (0)