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

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 16 14:02:45 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.10.1.vz7.162.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.10.1.vz7.162.3
------>
commit 6549f7646378a159bb9224146ef6ceb4b7b75490
Author: Mathieu Malaterre <malat at debian.org>
Date:   Fri May 11 12:07:03 2018 +0100

    ms/nvmem: properly handle returned value nvmem_reg_read
    
    Function nvmem_reg_read can return a non zero value indicating an error.
    This returned value must be read and error propagated to
    nvmem_cell_prepare_write_buffer. Silence the following gcc warning (W=1):
    
    drivers/nvmem/core.c:1093:9: warning: variable 'rc' set but
     not used [-Wunused-but-set-variable]
    
    Signed-off-by: Mathieu Malaterre <malat at debian.org>
    Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
    Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
    
    https://jira.sw.ru/browse/PSBM-104585
    
    (cherry picked from commit 50808bfcc14b854775a9f1d0abe3dac2babcf5c3)
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 drivers/nvmem/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

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);
 }
 
 /**


More information about the Devel mailing list