misc: Update read() and write() methods to return bytes xfered

At present these functions return 0 on success. For some devices we want
to know how many bytes were transferred. It seems useful to adjust the API
to be more like the POSIX read() and write() functions.

Update these two methods, a test and all users.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
diff --git a/drivers/clk/clk_vexpress_osc.c b/drivers/clk/clk_vexpress_osc.c
index 7fef4b2..c692a6d 100644
--- a/drivers/clk/clk_vexpress_osc.c
+++ b/drivers/clk/clk_vexpress_osc.c
@@ -29,7 +29,7 @@
 
 	data = CLK_FUNCTION | priv->osc;
 	err = misc_read(vexpress_cfg, 0, &data, sizeof(data));
-	if (err)
+	if (err < 0)
 		return err;
 
 	return data;
@@ -53,7 +53,7 @@
 	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;
diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c
index 883b2a3..eff33f7 100644
--- a/drivers/misc/altera_sysid.c
+++ b/drivers/misc/altera_sysid.c
@@ -35,7 +35,7 @@
 	if (ret)
 		return;
 	ret = misc_read(dev, 0, &sysid, sizeof(sysid));
-	if (ret)
+	if (ret < 0)
 		return;
 
 	stamp = sysid[1];
diff --git a/drivers/misc/misc_sandbox.c b/drivers/misc/misc_sandbox.c
index e4164f7..f7c5b2e 100644
--- a/drivers/misc/misc_sandbox.c
+++ b/drivers/misc/misc_sandbox.c
@@ -20,7 +20,7 @@
 
 	memcpy(buf, priv->mem + offset, size);
 
-	return 0;
+	return size;
 }
 
 int misc_sandbox_write(struct udevice *dev, int offset, const void *buf,
@@ -30,7 +30,7 @@
 
 	memcpy(priv->mem + offset, buf, size);
 
-	return 0;
+	return size;
 }
 
 int misc_sandbox_ioctl(struct udevice *dev, unsigned long request, void *buf)
diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c
index 8a213c9..2520c6a 100644
--- a/drivers/misc/rockchip-efuse.c
+++ b/drivers/misc/rockchip-efuse.c
@@ -65,7 +65,7 @@
 	}
 
 	ret = misc_read(dev, 0, &fuses, sizeof(fuses));
-	if (ret) {
+	if (ret < 0) {
 		printf("%s: misc_read failed\n", __func__);
 		return 0;
 	}
diff --git a/drivers/misc/stm32mp_fuse.c b/drivers/misc/stm32mp_fuse.c
index 2d66135..33943a2 100644
--- a/drivers/misc/stm32mp_fuse.c
+++ b/drivers/misc/stm32mp_fuse.c
@@ -29,6 +29,9 @@
 			return ret;
 		ret = misc_read(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
 				val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
@@ -54,6 +57,9 @@
 			return ret;
 		ret = misc_write(dev, word * 4 + STM32_BSEC_OTP_OFFSET,
 				 &val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
@@ -78,6 +84,9 @@
 		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:
@@ -103,6 +112,9 @@
 			return ret;
 		ret = misc_write(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
 				 &val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default: