Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3316644imu; Sun, 11 Nov 2018 12:13:15 -0800 (PST) X-Google-Smtp-Source: AJdET5enjnMFWT8UHUJ46NmVRVDdfwNMavUK47kmqPVy/d/41Wqsa6lRjkQ88LgbqXWFAPJr1Oyr X-Received: by 2002:a63:6c4a:: with SMTP id h71-v6mr15016450pgc.326.1541967195559; Sun, 11 Nov 2018 12:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967195; cv=none; d=google.com; s=arc-20160816; b=hqGU3I5bzT9v4y3fRyas8zZSv7iHQ6Nc3OrIGgkWCc1AGsllV9Ar6SUZg+VK3BUjVt DWWtWgbwQUKDye5WlUgcID8WjMrVqOMxSBuJk8OHQzQDyr9WUzWTfdrVANeO7FhhMUlD rxYDWnpHTfqB9/1H75R/0y5K4LZDgQaL7et+XPM2YR20OQrIGWt5gcwUszn7f3R2wjzp RahRXbDS68nszqh/BlIO+Rd+mqI+fiBAs5Yxk8R4FJEtYWnZVipjCDp35kdnK9BGQCIF 01q+WSLzYkZEHPFjVen6es6xWq/CgbfdWT1uO0SWMRxbtwxtkE5+tgVUqAhuBAB4fzce vvQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=SkwN8o0TmDsuKEzhP0PasaMdsFYrmVKapjqu02AxlVs=; b=bCJV22Zr4Oj/NsHamoxVzi//i3LmrRD4eiSE9Kgyu1BBKtEoYvta/oSE07OcJrlJI/ 9+KOrihc9AlD+CFe+Yo8CPvsuIMUiQeV8+8ZdNGS1aqxIYU5vvu6FeXW1o4lOtrSHw1V ptgYXsravssbjApqFFPaylTMSLKmBCz5DolaznDAMaJsDg7zeX6QRkuRI15BS6A8jSc9 O0Jcw2bSrsT+w38fikM+2MLfM1Mb3SkiOr+k1XycWbOaIKvjepZsRgJMrMMl7kpLzkJ1 GDO4wxwCuSvqUMXuLg3N4ELRc0cOQaCYcsYN6PR14Xxa1dD/HP7E8KDXXdOT3QU6XGnP 2JJA== 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 x12-v6si15374298pfn.111.2018.11.11.12.13.00; Sun, 11 Nov 2018 12:13:15 -0800 (PST) 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 S1731334AbeKLGBu (ORCPT + 99 others); Mon, 12 Nov 2018 01:01:50 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52580 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730702AbeKLGBu (ORCPT ); Mon, 12 Nov 2018 01:01:50 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvtA-0000oP-7P; Sun, 11 Nov 2018 19:59:20 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsP-0001Qm-9P; Sun, 11 Nov 2018 19:58:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mauro Carvalho Chehab" , "Sakari Ailus" , "Colin Ian King" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 059/366] media: smiapp: fix timeout checking in smiapp_read_nvm In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 7a2148dfda8001c983f0effd9afd8a7fa58e99c4 upstream. 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: Ben Hutchings --- 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 @@ -899,7 +899,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); @@ -910,11 +910,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++) {