Coverity Scan:dead code on ubi

Wang Fangpeng wangfangpeng1 at huawei.com
Tue Aug 16 20:34:51 PDT 2016


Hi, folks,

Coverity Scan reports dead code on Linux/drivers/mtd/ubi/io.c:956-957 (kernel-4.7)

945                 if (data_size == 0) {
946                         ubi_err(ubi, "zero data_size");
947                         goto bad;
948                 }
949                 if (lnum < used_ebs - 1) {
950                         if (data_size != usable_leb_size) {
951                                 ubi_err(ubi, "bad data_size");
952                                 goto bad;
953                         }
954                 } else if (lnum == used_ebs - 1) {
955                         if (data_size == 0) {
956                                 ubi_err(ubi, "bad data_size at last LEB");
957                                 goto bad;
958                         }
959                 } else {
960                         ubi_err(ubi, "too high lnum");
961                         goto bad;
962                 }

The data_size argument has been checked(data_size == 0) at line 945 and goto bad if true.
At line 955, check it again. but the value of "data_size" must be at least 1, cannot be
equal to 0.  So, execution cannot reach line 956-957. it is dead code.

Can we fix this situation by the attach patch?
-------------- next part --------------
From 0ad250e4be4a1bd446ec527e201aadc613254141 Mon Sep 17 00:00:00 2001
From: wangfagnpeng <wangfangpeng1 at huawei.com>
Date: Wed, 17 Aug 2016 11:36:55 +0800
Subject: [PATCH] fix dead code at drivers/mtd/ubi/io.c

---
 drivers/mtd/ubi/io.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index bf79def..5d6c416 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -951,12 +951,7 @@ static int validate_vid_hdr(const struct ubi_device *ubi,
 				ubi_err("bad data_size");
 				goto bad;
 			}
-		} else if (lnum == used_ebs - 1) {
-			if (data_size == 0) {
-				ubi_err("bad data_size at last LEB");
-				goto bad;
-			}
-		} else {
+		} else if (lnum > used_ebs - 1) {
 			ubi_err("too high lnum");
 			goto bad;
 		}
-- 
1.7.7



More information about the linux-mtd mailing list