[PATCH 06/32] nvmem: core: propagate read failure
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Sep 5 02:55:31 PDT 2022
The read may fail and we may not depend on v's value then. Propagate the
error correctly to fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
drivers/nvmem/core.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index c5fe5f6b767a..c344738abd51 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -591,6 +591,9 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
/* setup the first byte with lsb bits from nvmem */
rc = nvmem->bus->read(nvmem->priv, cell->offset, &v, 1);
+ if (IS_ERR_VALUE(rc))
+ return ERR_PTR(rc);
+
*b++ |= GENMASK(bit_offset - 1, 0) & v;
/* setup rest of the byte if any */
@@ -609,6 +612,9 @@ static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
/* setup the last byte with msb bits from nvmem */
rc = nvmem->bus->read(nvmem->priv, cell->offset + cell->bytes - 1,
&v, 1);
+ if (IS_ERR_VALUE(rc))
+ return ERR_PTR(rc);
+
*p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
}
--
2.30.2
More information about the barebox
mailing list