ret = misc_read(dev, BSEC_OTP_MAC * 4 + STM32_BSEC_OTP_OFFSET,
otp, sizeof(otp));
- if (ret)
+ if (ret < 0)
return ret;
for (i = 0; i < 6; i++)
ret = misc_read(dev, BSEC_OTP_SERIAL * 4 + STM32_BSEC_OTP_OFFSET,
otp, sizeof(otp));
- if (ret)
+ if (ret < 0)
return ret;
sprintf(serial_string, "%08x%08x%08x", otp[0], otp[1], otp[2]);
data = CLK_FUNCTION | priv->osc;
err = misc_read(vexpress_cfg, 0, &data, sizeof(data));
- if (err)
+ if (err < 0)
return err;
return data;
buffer[0] = CLK_FUNCTION | priv->osc;
buffer[1] = rate;
err = misc_write(vexpress_cfg, 0, buffer, 2 * sizeof(u32));
- if (err)
+ if (err < 0)
return err;
return rate;
if (ret)
return;
ret = misc_read(dev, 0, &sysid, sizeof(sysid));
- if (ret)
+ if (ret < 0)
return;
stamp = sysid[1];
memcpy(buf, priv->mem + offset, size);
- return 0;
+ return size;
}
int misc_sandbox_write(struct udevice *dev, int offset, const void *buf,
memcpy(priv->mem + offset, buf, size);
- return 0;
+ return size;
}
int misc_sandbox_ioctl(struct udevice *dev, unsigned long request, void *buf)
}
ret = misc_read(dev, 0, &fuses, sizeof(fuses));
- if (ret) {
+ if (ret < 0) {
printf("%s: misc_read failed\n", __func__);
return 0;
}
return ret;
ret = misc_read(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
val, 4);
+ if (ret < 0)
+ return ret;
+ ret = 0;
break;
default:
return ret;
ret = misc_write(dev, word * 4 + STM32_BSEC_OTP_OFFSET,
&val, 4);
+ if (ret < 0)
+ return ret;
+ ret = 0;
break;
default:
if (ret)
return ret;
ret = misc_read(dev, word * 4 + STM32_BSEC_OTP_OFFSET, val, 4);
+ if (ret < 0)
+ return ret;
+ ret = 0;
break;
default:
return ret;
ret = misc_write(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
&val, 4);
+ if (ret < 0)
+ return ret;
+ ret = 0;
break;
default:
* @buf: pointer to data buffer
* @size: data size in bytes to read the device
*
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
*/
int misc_read(struct udevice *dev, int offset, void *buf, int size);
* @buf: pointer to data buffer
* @size: data size in bytes to write the device
*
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes written if OK (may be < @size), -ve on error
*/
int misc_write(struct udevice *dev, int offset, void *buf, int size);
* @buf: pointer to data buffer
* @size: data size in bytes to read the device
*
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
*/
int (*read)(struct udevice *dev, int offset, void *buf, int size);
* @buf: pointer to data buffer
* @size: data size in bytes to write the device
*
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes written if OK (may be < @size), -ve on error
*/
int (*write)(struct udevice *dev, int offset, const void *buf,
int size);
ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "misc-test", &dev));
/* Read / write tests */
- ut_assertok(misc_write(dev, 0, "TEST", 4));
- ut_assertok(misc_write(dev, 4, "WRITE", 5));
- ut_assertok(misc_read(dev, 0, buf, 9));
+ ut_asserteq(4, misc_write(dev, 0, "TEST", 4));
+ ut_asserteq(5, misc_write(dev, 4, "WRITE", 5));
+ ut_asserteq(9, misc_read(dev, 0, buf, 9));
ut_assertok(memcmp(buf, "TESTWRITE", 9));