Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3768512ybk; Tue, 19 May 2020 12:29:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsvSr8oCiM8GEvStFxfXM9zEnFdcXzvJm+txc1D35Z47meSs+xe0aJGZCK1Nw45frnK7Xf X-Received: by 2002:a05:6402:658:: with SMTP id u24mr389688edx.213.1589916587231; Tue, 19 May 2020 12:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589916587; cv=none; d=google.com; s=arc-20160816; b=DX98BJ+wDDtQmL2NxV2tM/WIVY2YnmaM5JYxv0+KbujGUYph6eXuC9gOUECGJfFVH5 Q5GcQM6voENTag74JQxYDWqIv/uJhKz8EVT3kCsQddyfUc5Wpo1I1f3C6MpUBNVVBE6V NoZzXzOjlagbGFUb4xkSY4ftoip3tr90cl9zeHzNUbukTBkhI4ysyoILiuruT7CUxIjj 30c27cDDDCC4jGZ3xGNvo7/UuQBzWVgFOoD2O03dXZVGnDeJQUrgEUFTjET+81qv9tsL VN1xPGTkwmsMt5oBSIy6Umdtz12d8G3SwcsvNibxssZp+tAtxKQACsXuJdmxhcjD516m RbHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Y26DaIi4n8BuhyRCfCi9TYUz/rg/RaO9Ay8FWNenVqU=; b=EY9nL0EHp7viScJeu3Q4gpcBeO50aFnTfiplpZCokPJEEe+Wpmn3xCL4oaQ3XMQTEZ 6zSK11Q+PJjjfOvtDqLsTs7AVkrfZovfMrDVi43KfFsQEUoskT9Qbq2ZtKpn1iWalQBf LhJlPAZVj4LP3n+sUQSblGfkJXbnWBCWCn622KIigQygPlEvhcuWBDvWY0FjlSoH/w09 /zb2O/N8V8o1ogL4iuleT9fT8Ko9GlsHUFDJHfs46esGY9NDolst5VvuEnVezvCSl6T1 RQ7m6kerzVFZoG7fX/zA3a6xuMMeUrcHgqj0p7MyR3hcuRh5SXmefBqzHf46Rvp0Carw R8SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=irb8JtwC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz18si401193ejb.581.2020.05.19.12.29.21; Tue, 19 May 2020 12:29:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=irb8JtwC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728895AbgESOqr (ORCPT + 99 others); Tue, 19 May 2020 10:46:47 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:38998 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgESOqr (ORCPT ); Tue, 19 May 2020 10:46:47 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04JEkj0G067348; Tue, 19 May 2020 09:46:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1589899605; bh=Y26DaIi4n8BuhyRCfCi9TYUz/rg/RaO9Ay8FWNenVqU=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=irb8JtwCjKFWlQ2PezGVskyGurReb505Tinijlx0BxHuxLxy5bLQKjk6PBaXiARwT c+NRc1DWYuAudvbbceSu8QxhYTkdnHsTUaq/pHQlykQZh/Po0bfiNH98sXKG1YpDU9 5CMe7Kf6bGQJWZYDAO/zs8Scdp1MxoH1AxgQV0E0= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 04JEkjc7109937 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 19 May 2020 09:46:45 -0500 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Tue, 19 May 2020 09:46:44 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Tue, 19 May 2020 09:46:44 -0500 Received: from [10.250.38.163] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04JEkiXO045835; Tue, 19 May 2020 09:46:44 -0500 Subject: Re: [PATCH v7 3/3] power: supply: bq25150 introduce the bq25150 To: Dan Murphy , CC: , , , , , Ricardo Rivera-Matos References: <20200519141916.28282-1-dmurphy@ti.com> <20200519141916.28282-4-dmurphy@ti.com> From: "Andrew F. Davis" Message-ID: <50b9ca3f-36e8-d13b-672c-5e72b6158869@ti.com> Date: Tue, 19 May 2020 10:46:43 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200519141916.28282-4-dmurphy@ti.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/19/20 10:19 AM, Dan Murphy wrote: > +static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val) > +{ > + int i; > + > + if (val > BQ2515X_ILIM_MAX || val < BQ2515X_ILIM_MIN) > + return -EINVAL; Clamp to these limits, not reject. Or better, modify the below loop so it clamps to the highest or lowest value in bq2515x_ilim_lvl_values[], then drop these #defines. > + > + for (i = 0; i < ARRAY_SIZE(bq2515x_ilim_lvl_values); i++) { > + if (val == bq2515x_ilim_lvl_values[i]) > + break; > + > + if (val > bq2515x_ilim_lvl_values[i - 1] && Index out of bounds for the i = 0 case. > + val < bq2515x_ilim_lvl_values[i]) { > + if (val - bq2515x_ilim_lvl_values[i - 1] < > + bq2515x_ilim_lvl_values[i] - val) { You are still missing the case where the value is closer to the [i] element, you check that it is between [i-1] and [i], but only chose [i-1] when it is closer to that than [i] but equal and greater case is missing. Given this sets input current limits, would instead always rounding down be the safer option? Andrew > + i = i - 1; > + break; > + } > + } > + } > + > + return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i); > +}