Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1109561imm; Wed, 1 Aug 2018 10:20:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe2Mm0lGAWNzbKaam5wPkJ83A8BN1J6KLR5e/CkSd1FcKZnnzfEcl+sd4IcZIIDdbg1taVT X-Received: by 2002:a62:cc4d:: with SMTP id a74-v6mr27919734pfg.200.1533144002013; Wed, 01 Aug 2018 10:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533144001; cv=none; d=google.com; s=arc-20160816; b=Ss/u5x/4NVO/GT66YNAixg+B1TI4pkwGlKCsuB595jE1vxTB8qT2jhIWqw0HBsKJji FjRR2yoX8+qJmdwJy6ONSh2MdqYrbV4a+7f8WcmzVr+VXx2V6RJ/7saYg4YhbGwpf9Y3 S+4DrpGc0p7W4jPuzW7GYZgRzh71rnd43RdNyXfIQ/1j0k4sOEdXBTWcTtFJkiPR+Ts0 QqIzBO0v9wdYeDUKLi3tOgAee/de8hnHjr1TU5yssqZ0eaMfWADrEOaH9HHUKKBhlQ+s 0rVeYL9ZxcAzECIH04o7m5HVJdw+I5/2sZ1juOgk+CCfda2agrgxt45qJCc2igt0GTHh Cwvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TjsUzNHm8OmtfjYfgAqgidrR8RXFG7NQBk028MRDvow=; b=cKOs2FcWwj2eu+HLQwWlU4NfKttD+IDQsNdUToiCKkr4aI+/asXXaa/4tnKb/pZX7V oC9R7yJm/Sz0r4tGOARObMDNJ2Hb/eREU+UqycslsVlzMPRlz2bS9WBkfG3UeUIR5wwr BoY+do4oEKG+15Nph2yQzFEjMB9V1GO/OGrs2dp0Fa7jHtyhm5vVRcT4BwEZhREsLh6o xizYi8OSOkdtHouH0FmJWAaTqea309PvMdQYwMA8LcsuuNFIT9o0CDdhbPCw0Jeu7LcE q+UJBzc4T1OJuGc/zupRoBB20qx+GUAqnwEkUyJNsE4mCNAbgsW8iQxx2TuKNqeCdVy6 2TXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x32-v6si15189933pld.330.2018.08.01.10.19.47; Wed, 01 Aug 2018 10:20:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404923AbeHATE7 (ORCPT + 99 others); Wed, 1 Aug 2018 15:04:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47098 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404205AbeHATE6 (ORCPT ); Wed, 1 Aug 2018 15:04:58 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B4C38CCC; Wed, 1 Aug 2018 17:18:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.14 130/246] media: smiapp: fix timeout checking in smiapp_read_nvm Date: Wed, 1 Aug 2018 18:50:40 +0200 Message-Id: <20180801165017.950180657@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King [ Upstream commit 7a2148dfda8001c983f0effd9afd8a7fa58e99c4 ] The current code decrements the timeout counter i and the end of each loop i is incremented, so the check for timeout will always be false and hence the timeout mechanism is just a dead code path. Potentially, if the RD_READY bit is not set, we could end up in an infinite loop. Fix this so the timeout starts from 1000 and decrements to zero, if at the end of the loop i is zero we have a timeout condition. Detected by CoverityScan, CID#1324008 ("Logically dead code") Fixes: ccfc97bdb5ae ("[media] smiapp: Add driver") Signed-off-by: Colin Ian King Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/i2c/smiapp/smiapp-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) --- a/drivers/media/i2c/smiapp/smiapp-core.c +++ b/drivers/media/i2c/smiapp/smiapp-core.c @@ -1001,7 +1001,7 @@ static int smiapp_read_nvm(struct smiapp if (rval) goto out; - for (i = 0; i < 1000; i++) { + for (i = 1000; i > 0; i--) { rval = smiapp_read( sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s); @@ -1012,11 +1012,10 @@ static int smiapp_read_nvm(struct smiapp if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY) break; - if (--i == 0) { - rval = -ETIMEDOUT; - goto out; - } - + } + if (!i) { + rval = -ETIMEDOUT; + goto out; } for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {