All of lore.kernel.org
 help / color / mirror / Atom feed
* Coverity Scan:dead code on ubi
@ 2016-08-17  3:34 Wang Fangpeng
  0 siblings, 0 replies; only message in thread
From: Wang Fangpeng @ 2016-08-17  3:34 UTC (permalink / raw)
  To: linux-mtd, richard, dedekind1

[-- Attachment #1: Type: text/plain, Size: 1218 bytes --]

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?

[-- Attachment #2: 0001-fix-dead-code-at-drivers-mtd-ubi-io.c.patch --]
[-- Type: text/plain, Size: 812 bytes --]

From 0ad250e4be4a1bd446ec527e201aadc613254141 Mon Sep 17 00:00:00 2001
From: wangfagnpeng <wangfangpeng1@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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-17  3:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-17  3:34 Coverity Scan:dead code on ubi Wang Fangpeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.