Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1216275ybf; Thu, 27 Feb 2020 06:58:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwt32p63rDkSkgR3b89V8MMPF8Pcm59fK5t4tyKLKq5Mv5lGkyd9yGNdnd9b8zaYF8GHFdm X-Received: by 2002:aca:4a0b:: with SMTP id x11mr3530136oia.37.1582815512904; Thu, 27 Feb 2020 06:58:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582815512; cv=none; d=google.com; s=arc-20160816; b=vyKYlXpXU1a1HgvOWpBkeH7D/QVwt8QNpreyUI8VVQXr9iymNgtGUmY92f2AUjFtxp N/L8kxsaEXDZsssvA/2bEU22ec7S/9L5xlhpIfw4VoZPAluvUGRDOP3yjgb6NL2FZxhq Ro3QU3rjSJtTtPlSUhCunoRA84AK/5ADJrOoOYDGiPNoSyrJQk6f9WBnqj+Opa1BksPO 2uxEkpVG9dYIjoHA4vNyN+iiOv9rMIY+Jy4/iHjyRBp5eFe2Nomyyxr38i5hOqkVG4lZ pPzxcRLsMjKVhMzcQMirRvAYCFRVuMiCHDlwDiSk0vsXCpx8esXQ2oOWsj2ocBK2y5YC aVZg== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=c8UJCHjiQkoyahVk3JVpGT7p90RFMuXW7y1DGNJVn3I=; b=iZyCIlOkEikseKOAYEVWBKhojLz8f8F4UUMrzNDOMVYrD8oAxwoz0BBLIl9Eylp7T0 7JDwtcMIfnalkw/8G8j9pYVghzYGziJg4BUJcx33ZMG6QiH6HdPZ9f7Q7/VwN33J6+79 ReXuC0xJEsTWMbtAen82CaEOk2RD85xE456+6ozK6vcnVahrLK9/NIDCAgTxPIo6FlGr kzh1BoRw7w30VpN9A7miV99uJROcUxuG38uYA4/kiDWqIlry9duYLi7wR0poo+NVZPj9 UyLeuM+GYrLA886oLOiQNXjupOafbtliZ/ZuDKN8RUCJIliFNHR1q49QHNU58Tl20IP4 H2GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=byT2rBha; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si1749802otm.135.2020.02.27.06.58.20; Thu, 27 Feb 2020 06:58:32 -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; dkim=pass header.i=@linaro.org header.s=google header.b=byT2rBha; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732652AbgB0O5s (ORCPT + 99 others); Thu, 27 Feb 2020 09:57:48 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45155 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730338AbgB0O5r (ORCPT ); Thu, 27 Feb 2020 09:57:47 -0500 Received: by mail-wr1-f65.google.com with SMTP id v2so3683227wrp.12 for ; Thu, 27 Feb 2020 06:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=c8UJCHjiQkoyahVk3JVpGT7p90RFMuXW7y1DGNJVn3I=; b=byT2rBhaJ3NpZXKQ3xNyKgwH/jTsZDf0x3JScBZse8RZ9ksFtO/1/rzbmUu0CFRSmu UdjxqFPEVzG5/nlQN1mO3unL4TpB2ZWZqMmJ1QFXtg0gtHTDJmuH5Mr9BHs1Z27Lz8kL uNlFPb6j5UW2b9rOFGC2vB0UPG4BqkPa/9nbKFUK4OLlUK/pY6kMcaGVXtUMgczw0Kp6 oAm41AQENKBtmKvcKzZCOGkW797Vm6p0Mh+Z9k7y+u3Fd4p0Ai6LFLrNKSdom9zxuj/A QU7eFBjQf0U6mgt31hcNhrgdDBHWHjTyZwkPPZmLd1Qrq5BEShppzQjd8edcXAQXb6PS SaYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=c8UJCHjiQkoyahVk3JVpGT7p90RFMuXW7y1DGNJVn3I=; b=JGCqSL/r68umICggsKkOzmPIV1JyhYAd5LywlI9rj9gqAhLTBBvZZKPJEAPKtmyGWw w3DjvhAOc4PQHLVGOCiubc7FhCTmSou+y+lfKQa8F7suokDrdCwQ/5KrRfjhkEPNSJ8U 8bxa0FzMGxZmeMl20v8NTYJLXxCLnjVVA4GzP4Hasr7lovPR4KiCXeYcq5OOnIGPJQgW d0EPBj9Wo+pwbB31eR3Rp/5eYOJJxTQkL+lBAZO+HVVhn7pV9qFO6QBigZrQWSKMAPRV KFz9n3evx2I7+Ksf892Mx31HR5cjYCx2Gx9Too5Bv3DR+nuP3FGHQW0gi5KDz+ao6FbV 0DFg== X-Gm-Message-State: APjAAAWgHiaSab+NwaK0jAsHlN+vcrzGItTBAYvT+KXO/jU4boGEHqkf A8+T9NvOIVhcYAMAF1FiNHM0cA== X-Received: by 2002:adf:f892:: with SMTP id u18mr5040913wrp.328.1582815463904; Thu, 27 Feb 2020 06:57:43 -0800 (PST) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id h15sm1262654wrr.73.2020.02.27.06.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 06:57:43 -0800 (PST) Date: Thu, 27 Feb 2020 14:57:41 +0000 From: Daniel Thompson To: Colin King Cc: Lee Jones , Jingoo Han , Bartlomiej Zolnierkiewicz , Gyungoh Yoo , Bryan Wu , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][V2] backlight: sky81452: insure while loop does not allow negative array indexing Message-ID: <20200227145741.v3r4qzkfsrwpy33h@holly.lan> References: <20200226195826.6567-1-colin.king@canonical.com> <20200227114623.vaevrdwiduxa2mqs@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200227114623.vaevrdwiduxa2mqs@holly.lan> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 11:46:23AM +0000, Daniel Thompson wrote: > On Wed, Feb 26, 2020 at 07:58:26PM +0000, Colin King wrote: > > From: Colin Ian King > > > > In the unlikely event that num_entry is zero, the while loop > > pre-decrements num_entry to cause negative array indexing into the > > array sources. Fix this by iterating only if num_entry >= 0. > > > > Addresses-Coverity: ("Out-of-bounds read") > > Fixes: f705806c9f35 ("backlight: Add support Skyworks SKY81452 backlight driver") > > Signed-off-by: Colin Ian King > > --- > > > > V2: fix typo in commit subject line > > Isn't the correct spelling "ensure"? > > > > --- > > drivers/video/backlight/sky81452-backlight.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c > > index 2355f00f5773..f456930ce78e 100644 > > --- a/drivers/video/backlight/sky81452-backlight.c > > +++ b/drivers/video/backlight/sky81452-backlight.c > > @@ -200,7 +200,7 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt( > > } > > > > pdata->enable = 0; > > - while (--num_entry) > > + while (--num_entry >= 0) > > pdata->enable |= (1 << sources[num_entry]); > > This look still looks buggy to me (so I'd second Walter's request to > change it to a for loop). If the code genuinely does not contain a > bug then it probably needs a prominent comment explaining why it is > correct not to honour sources[0]! Ignore the "still looks buggy". A mental mis-step when switching contexts... I think my English is still correct though ;-) Daniel.