From patchwork Wed Aug 17 03:34:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangfangpeng X-Patchwork-Id: 659872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sDZgs2j6wz9t1F for ; Wed, 17 Aug 2016 13:38:17 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZreF-0000Lb-3v; Wed, 17 Aug 2016 03:36:11 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZreA-0007Zu-0q for linux-mtd@lists.infradead.org; Wed, 17 Aug 2016 03:36:09 +0000 Received: from 172.24.1.47 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DLT83383; Wed, 17 Aug 2016 11:34:54 +0800 (CST) Received: from [127.0.0.1] (10.57.45.121) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Wed, 17 Aug 2016 11:34:52 +0800 To: , , From: Wang Fangpeng Subject: =?UTF-8?Q?Coverity_Scan=ef=bc=9adead_code_on_ubi?= Message-ID: <57B3DB5B.3040406@huawei.com> Date: Wed, 17 Aug 2016 11:34:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 X-Originating-IP: [10.57.45.121] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.57B3DB5F.00B7, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: a0f41aa29eff012985eff5db5a55c039 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160816_203606_495191_CD643CF6 X-CRM114-Status: GOOD ( 11.40 ) X-Spam-Score: -5.6 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [119.145.14.65 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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? From 0ad250e4be4a1bd446ec527e201aadc613254141 Mon Sep 17 00:00:00 2001 From: wangfagnpeng 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; }