From patchwork Tue May 1 09:45:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 134750 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp4761518lji; Tue, 1 May 2018 02:46:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZop468v5mAKUBgSvao9uWvPc4LnH+1tbB+eCqnN9UyRECyJ+aoyhtyJZ7tpTv6TkDTkNk/T X-Received: by 2002:a63:b642:: with SMTP id v2-v6mr12594959pgt.158.1525167970370; Tue, 01 May 2018 02:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525167970; cv=none; d=google.com; s=arc-20160816; b=K68oqD/34G8iNXZgS2RJTLqVSnGP8VRV/704fxwqBHSo9ys1zipldC55Zd8OaKZeEJ hZLDg9nJJMksnZDx2nLAzyb3y26ySwPUac+lpqp0GWgZ+wa5I+s8tBqHQk6rqgU71+oL 128SFsYEUj0A9CWzXPUVzqGefrtnGHVcxXV02GZjVZyC40V9RIgrJeFG4AvOFPuuEvTs vVcL+Z0ZEgmirCmfVO9OEAEMnOgImvAT1q1WbWhOV5VADN2fHscOs1RgJPp3vPYD+Fxi tU9ZfSgIzcukaMn9LIpkeKtICmd8qMNrstfHwI9lR/SqO5RBAj/llNDdSrluZu1vZ/x0 sK5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=FtW/j5iIZMRTEOQc9fnBEbfzsbruWVztV4piA11LnLU=; b=SOXxx66mLrR5eTOTPB5V5qAJka6VhGbDGdJtK0Xb9sfSXOkNnEHZ2CRc9GsFNmqsKR pfmm1zL2kwbIIFdnnqDMODOdaWagbBopzF8sK0QJiFJTaMZ9NDGgL5nf0SmLBClDiGEW eDfyXkg1ZBkE0Hfhsmv+V7for/pAGxbKCJTStozWaQWDAP3DD5CtNhx1Z3dIM4psGuBD KdxBIcFINi6reuH3u67zADlDyfpJaS/opac7zdip26uJcgFemRy9TX413lomjt7klG71 XMG0H0BUtDtmCC028JZsBvOeFncJkmZkXT1qtYPweaBMipsoH808hexK3mjcO4Mc5PVD +92w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iszvd7gr; 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 x1si8951668pfm.32.2018.05.01.02.46.10; Tue, 01 May 2018 02:46:10 -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=Iszvd7gr; 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 S1753406AbeEAJqD (ORCPT + 29 others); Tue, 1 May 2018 05:46:03 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37106 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbeEAJqC (ORCPT ); Tue, 1 May 2018 05:46:02 -0400 Received: by mail-wr0-f193.google.com with SMTP id c14-v6so10357946wrd.4 for ; Tue, 01 May 2018 02:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=FtW/j5iIZMRTEOQc9fnBEbfzsbruWVztV4piA11LnLU=; b=Iszvd7gr3Hg7u8I7Hf4WqR31zDtBYHZNqYFrY616FMsbzdC8VS9gC7tFlvww2CgXyo Al/kpBqq4JWy5oA9HFyT+1YFbZI1nNm3M+0smNnt3Q7GxzK7EpzyZLY+SUjuPMPJM5K3 8XpTrLPVuHtu8aA+JORa+WB4RwaANrZdI6kLU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FtW/j5iIZMRTEOQc9fnBEbfzsbruWVztV4piA11LnLU=; b=HhIrHMXE5Rokbs1igTqxc9am11aN0ctTVyEfzoVGr9thZJcK55TrIZnp5jtNdBICXk Htdc0HdcL4JfDgm/6wmFaw+m/dndxHFioqm4bKs1mptiegEfwt3BXzT6/zmz4Ihq467y gV8BQ7VKNruSA0wVGHPqIJqUAxyjnCewqgIDEe9yf41vKLXDw2QFRK5Fpq96r29o3TJ1 cgs6QvlGwb6UaI3/6XWV4cEbpOdNVDVYHhb4KKhUWLTTPdotkOIXp46vSjsMuorlIRiX RzQ+mXOGCJL+iIkBkmYj5ZoSd0JJjWYNH8NaceOsRmDpbrvBySOq8D6Ad9sx+18UXJ45 Vmxw== X-Gm-Message-State: ALQs6tCssX2qEugMboH3vobMzafP/ewTCB4sUk/PaaMJVqWijnHftKbH OL4DrM/FdHpjioodIX8jBgzOkw== X-Received: by 2002:adf:dc90:: with SMTP id r16-v6mr10435756wrj.218.1525167961027; Tue, 01 May 2018 02:46:01 -0700 (PDT) Received: from localhost.localdomain ([2.27.167.55]) by smtp.gmail.com with ESMTPSA id z63-v6sm11529243wrb.34.2018.05.01.02.46.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 02:46:00 -0700 (PDT) From: Lee Jones To: dan.carpenter@oracle.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Lee Jones Subject: [PATCH 1/1] mfd: tps65911-comparator: Fix an off by one bug Date: Tue, 1 May 2018 10:45:53 +0100 Message-Id: <20180501094553.31545-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. The "id" variable is never COMP (0) so that code can be removed. Fixes: 6851ad3ab346 ("TPS65911: Comparator: Add comparator driver") Reported-by: Dan Carpenter Signed-off-by: Lee Jones --- History: Dan was the originator of this patch and the author of the commit log, but produced 2 code solutions which I wasn't happy with. The first submission [0] introduced a COMP device, which after a quick check of the datasheet [1] appeared to be fictitious. A subsequent submission [2] conducted arithmetic in array indexes. It is my belief that the correct solution is to roll which the situation the hardware engineers presented us with and define COMP1 at position 0 and COMP2 at position 1 such that we can use the simplest code possible to select them. Dan wasn't happy to put his name to this, which I completely understand. Calling SOMETHING1 0 (zero) is a little unnatural. However, since I have no shame, I offered to submit it. [0] https://lkml.org/lkml/2018/4/19/449 [1] http://www.ti.com/lit/ds/symlink/tps65911.pdf (page 52) [2] https://lkml.org/lkml/2018/4/20/204 drivers/mfd/tps65911-comparator.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) -- 2.17.0 diff --git a/drivers/mfd/tps65911-comparator.c b/drivers/mfd/tps65911-comparator.c index d223857fb4ad..33591767fb9b 100644 --- a/drivers/mfd/tps65911-comparator.c +++ b/drivers/mfd/tps65911-comparator.c @@ -22,9 +22,8 @@ #include #include -#define COMP 0 -#define COMP1 1 -#define COMP2 2 +#define COMP1 0 +#define COMP2 1 /* Comparator 1 voltage selection table in millivolts */ static const u16 COMP_VSEL_TABLE[] = { @@ -63,9 +62,6 @@ static int comp_threshold_set(struct tps65910 *tps65910, int id, int voltage) 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) @@ -89,9 +85,6 @@ static int comp_threshold_get(struct tps65910 *tps65910, int id) unsigned int val; int ret; - if (id == COMP) - return 0; - ret = tps65910_reg_read(tps65910, tps_comp.reg, &val); if (ret < 0) return ret;