From 226ecdea99ce2ad4e1554b50fc7c2c4ca069191f Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Wed, 17 Mar 2021 04:21:34 -0400 Subject: [PATCH] raw/ifpga/base: check lseek failure In write_flash_image(), calling function "lseek" without checking return value has risk. Negative return value should be handled as an error condition. Coverity issue: 367478 Fixes: a05bd1b40bde ("raw/ifpga: add FPGA RSU APIs") Signed-off-by: Wei Huang Acked-by: Tianfei Zhang Acked-by: Rosen Xu --- drivers/raw/ifpga/base/ifpga_fme_rsu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/raw/ifpga/base/ifpga_fme_rsu.c b/drivers/raw/ifpga/base/ifpga_fme_rsu.c index 28198abd78..b5e018d3e7 100644 --- a/drivers/raw/ifpga/base/ifpga_fme_rsu.c +++ b/drivers/raw/ifpga/base/ifpga_fme_rsu.c @@ -128,7 +128,12 @@ static int write_flash_image(struct ifpga_sec_mgr *smgr, const char *image, do { to_transfer = (length > IFPGA_RSU_DATA_BLK_SIZE) ? IFPGA_RSU_DATA_BLK_SIZE : length; - lseek(fd, offset, SEEK_SET); + if (lseek(fd, offset, SEEK_SET) < 0) { + dev_err(smgr, "Failed to seek in \'%s\' [e:%s]\n", + image, strerror(errno)); + ret = -EIO; + goto end; + } read_size = read(fd, buf, to_transfer); if (read_size < 0) { dev_err(smgr, "Failed to read from \'%s\' [e:%s]\n", -- 2.20.1