[RHEL7,COMMIT] ms/nvmem: properly handle returned value nvmem_reg_read

Submitted by Konstantin Khorenko on June 16, 2020, 11:02 a.m.

Details

Message ID 202006161102.05GB2jRj030931@finist-ce7.sw.ru
State New
Headers show

Patch hide | download patch | download mbox

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 344b40bde63a5..78d6d6b927b7c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -878,6 +878,8 @@  static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
 
 		/* setup the first byte with lsb bits from nvmem */
 		rc = nvmem_reg_read(nvmem, cell->offset, &v, 1);
+		if (rc)
+			goto err;
 		*b++ |= GENMASK(bit_offset - 1, 0) & v;
 
 		/* setup rest of the byte if any */
@@ -896,11 +898,16 @@  static inline void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell,
 		/* setup the last byte with msb bits from nvmem */
 		rc = nvmem_reg_read(nvmem,
 				    cell->offset + cell->bytes - 1, &v, 1);
+		if (rc)
+			goto err;
 		*p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
 
 	}
 
 	return buf;
+err:
+	kfree(buf);
+	return ERR_PTR(rc);
 }
 
 /**