diff options
-rw-r--r-- | board/starfive/evb/starfive_evb.c | 2 | ||||
-rwxr-xr-x | board/starfive/visionfive/starfive_visionfive.c | 2 | ||||
-rw-r--r-- | drivers/misc/starfive-otp.c | 15 |
3 files changed, 14 insertions, 5 deletions
diff --git a/board/starfive/evb/starfive_evb.c b/board/starfive/evb/starfive_evb.c index 1dd722ef40..8a30a24de0 100644 --- a/board/starfive/evb/starfive_evb.c +++ b/board/starfive/evb/starfive_evb.c @@ -244,7 +244,7 @@ int misc_init_r(void) } ret = misc_read(dev, MACADDR_OFFSET, buf, sizeof(buf)); - if (ret) + if (ret != sizeof(buf)) printf("%s: error reading mac from OTP\n", __func__); else if (buf[0] != 0xff) { diff --git a/board/starfive/visionfive/starfive_visionfive.c b/board/starfive/visionfive/starfive_visionfive.c index 7f9de3d9de..e1b0042f10 100755 --- a/board/starfive/visionfive/starfive_visionfive.c +++ b/board/starfive/visionfive/starfive_visionfive.c @@ -192,7 +192,7 @@ int misc_init_r(void) } ret = misc_read(dev, MACADDR_OFFSET, buf, sizeof(buf)); - if (ret) + if (ret != sizeof(buf)) printf("%s: error reading mac from OTP\n", __func__); else if (buf[0] != 0xff) diff --git a/drivers/misc/starfive-otp.c b/drivers/misc/starfive-otp.c index 5fa91582a0..8ff189c35d 100644 --- a/drivers/misc/starfive-otp.c +++ b/drivers/misc/starfive-otp.c @@ -116,11 +116,19 @@ static int starfive_otp_read(struct udevice *dev, int offset, int bytescnt; int i; - if (!buf || (offset >= OTP_MEM_SIZE) || (offset & 0x3)) { - printf("%s:invalid parameter.\n", __func__); + if ((size % BYTES_PER_INT) || (offset % BYTES_PER_INT)) { + printf("%s: size and offset must be multiple of 4.\n", __func__); return -EINVAL; } + /* check bounds */ + if (!buf) + return -EINVAL; + if (offset >= OTP_MEM_SIZE) + return -EINVAL; + if ((offset + size) > OTP_MEM_SIZE) + return -EINVAL; + bytescnt = size / BYTES_PER_INT; for (i = 0; i < bytescnt; i++) { @@ -133,7 +141,8 @@ static int starfive_otp_read(struct udevice *dev, int offset, databuf[i] = data; offset += 4; } - return 0; + + return size; } static int starfive_otp_probe(struct udevice *dev) |