Received: by 10.192.165.148 with SMTP id m20csp3088197imm; Sun, 22 Apr 2018 23:45:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dUdvMXvKayvS5oNyRSNzDFgueV1buoEbNV3l7/gfr4BRJAmKA6hy1vsuT74Zeye2Mq+FE X-Received: by 2002:a17:902:b187:: with SMTP id s7-v6mr19915329plr.170.1524465952447; Sun, 22 Apr 2018 23:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524465952; cv=none; d=google.com; s=arc-20160816; b=Cbl9K2daF70WMuTN7NcbbVoFgYGdR5AKTPggDnPh7ArFJeXC2VBMBDxO5cZOmYA9Uy 4W8Qgl+u/nWKZTwdy6rYu4iSPN91KYJdVFVtE1ma3/UOI3E8lDpSVxfQKEdanMPTWspu GFpUiUY0tERfQmiA4UdPRxaavkdaBw/JWgTMC01HOYqpdJQqPetA58wSIV8Alluf+Ddi 12M93B2qKTvpPccuPbo8hNU1R266Fo47KQBQpFX9A0CN4k5ipnmY5INTh8oBDNFAKFrI 4kNDyIiougbsQiApGNv9psJlySOxzZ7HWiXVPJiRN2REQFRIWljHD0WCOeaw+vq0/fPn eO8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=SLAWNIUatPF91/dk9lZH7vEyW3A9VKytLGSvIf1dvnc=; b=fzhs+aZiz7LrTD6cfOUWwtMG5EloD/SY05ov71CjsIuQv9S1Zlt55kyEXGgY5bRvk7 qKgT9nNd8ddnfyHd9Mwj5S/x8WuTDz4PFoG+2zDuTBU1JYcdLL0hDCrtOEBEBMP73vT6 REveMyS0GFvxWDJuflVWAOLEy/qX4Kp7NDy2StxIKImoWE6VDH/XPhCXopD6QkhpXO22 oCrn0uPURGV7ULAI4IAjoNk0wSpL3VZizyfNOrNG15gI2Szul1H0tRcrWDHRBZWqjxFH 1xXrj53y3oTiXqUtD+2XobuH27Z9ZgCH7WlQH8iE152ZLuNotG1VogTBq2cXKVWhYU+N gEQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MTtaC1nr; 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 92-v6si11015264pli.354.2018.04.22.23.45.38; Sun, 22 Apr 2018 23:45:52 -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; dkim=pass header.i=@linaro.org header.s=google header.b=MTtaC1nr; 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 S1754148AbeDWGoZ (ORCPT + 99 others); Mon, 23 Apr 2018 02:44:25 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34153 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbeDWGoV (ORCPT ); Mon, 23 Apr 2018 02:44:21 -0400 Received: by mail-wr0-f195.google.com with SMTP id p18-v6so18713225wrm.1 for ; Sun, 22 Apr 2018 23:44:20 -0700 (PDT) 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:content-transfer-encoding:in-reply-to :user-agent; bh=SLAWNIUatPF91/dk9lZH7vEyW3A9VKytLGSvIf1dvnc=; b=MTtaC1nruX4mS/FRDdGKEDXcmwCyHrQxqCbM7dxXSPWDeZ44mvq8AgMY3Oz3VCd2Xc 8vw1Pm7Uha7IkLQsToB3fmKdRSP0tgA3hK1dnfRLWC0yI/0UsdfP7y4csatFIiqFum/8 MJhuswEp5Nf61dBiSCpwT6/ZK8qhIdc+v4uMk= 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:content-transfer-encoding :in-reply-to:user-agent; bh=SLAWNIUatPF91/dk9lZH7vEyW3A9VKytLGSvIf1dvnc=; b=uV/Dc+qYoK7VSE9xxrxJh/gaGRhJ+zkDzl7DkqHvbchz+rhswpF3uXo3tMUMKex3Np NSel65CSDDbgXSoN+yRm5YTv2XHwb3zygMnAttA1hksnR8ZI+8KPA4WFkg/R1v6eqsWA M3m0F6S01sv2uQq7EH2vuRdqzTE1upTfUP/GviSMejBc8e92Zvc9IRVu/TpiIxNqGaMo AD8EdtooyuU6qrpTFBUjoA9DohjsI/SixmVtv1VEpri8dOAqokTWGUQNn3yHezjz3xPr 6WFieBtuM9n5+M5hx4tf5Fzz20H6DzPShaErTp3/1b0v6kQc6gTW+amEPLko46myaEHE zGDw== X-Gm-Message-State: ALQs6tAVckPnVoXMZkXcS+2zYhY22JelGJUDwmUJE9kSJwbmbnhWtE3e /W2tBRI4qvS9xmzHSZu6MMkcsLHPavQ= X-Received: by 10.80.207.136 with SMTP id h8mr27240596edk.40.1524465860140; Sun, 22 Apr 2018 23:44:20 -0700 (PDT) Received: from dell ([2.27.167.55]) by smtp.gmail.com with ESMTPSA id y53sm6696811edb.17.2018.04.22.23.44.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Apr 2018 23:44:19 -0700 (PDT) Date: Mon, 23 Apr 2018 07:44:17 +0100 From: Lee Jones To: Dan Carpenter Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH v2] mfd: tps65911-comparator: Fix an off by one bug Message-ID: <20180423064417.2e2ng3su23w4i7hx@dell> References: <20180420083909.66a6t63s5q6vpwp7@dell> <20180420090910.GA26071@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180420090910.GA26071@mwanda> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Apr 2018, Dan Carpenter wrote: > The COMP1 and COMP2 elements are in 0 and 1 respectively so this code is > accessing the wrong elements and one space beyond the end of the array. > We should be using "id - 1" instead. > > The "id" variable is never COMP (0) so that code can be removed. > > Fixes: 6851ad3ab346 ("TPS65911: Comparator: Add comparator driver") > Signed-off-by: Dan Carpenter > --- > v2: we can fix the bug and save memory. Looks like it's as we feared: http://www.ti.com/lit/ds/symlink/tps65911.pdf (page 52) There are only 2 comparators 1 and 2. > diff --git a/drivers/mfd/tps65911-comparator.c b/drivers/mfd/tps65911-comparator.c > index c0789f81a1c5..887409c3938d 100644 > --- a/drivers/mfd/tps65911-comparator.c > +++ b/drivers/mfd/tps65911-comparator.c > @@ -22,7 +22,6 @@ > #include > #include > > -#define COMP 0 > #define COMP1 1 > #define COMP2 2 Sorry, but I think these defines should describe the indexes into the supplied struct directly, especially as in this case it is their only reason for being. I completely agree with you that defining something that is named '1' as '0' is not ideal, but IMHO it's better than jumping through hoops using arithmetic in array indexes. > @@ -58,14 +57,11 @@ static struct comparator tps_comparators[] = { > > static int comp_threshold_set(struct tps65910 *tps65910, int id, int voltage) > { > - struct comparator tps_comp = tps_comparators[id]; > + struct comparator tps_comp = tps_comparators[id - 1]; > int curr_voltage = 0; > int ret; > u8 index = 0, val; > > - if (id == COMP) > - return 0; > - > while (curr_voltage < tps_comp.uV_max) { > curr_voltage = tps_comp.vsel_table[index]; > if (curr_voltage >= voltage) > @@ -85,13 +81,10 @@ static int comp_threshold_set(struct tps65910 *tps65910, int id, int voltage) > > static int comp_threshold_get(struct tps65910 *tps65910, int id) > { > - struct comparator tps_comp = tps_comparators[id]; > + struct comparator tps_comp = tps_comparators[id - 1]; > int ret; > u8 val; > > - if (id == COMP) > - return 0; > - > ret = tps65910->read(tps65910, tps_comp.reg, 1, &val); > if (ret < 0) > return ret; -- Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog