Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1004657ybz; Sat, 25 Apr 2020 08:54:18 -0700 (PDT) X-Google-Smtp-Source: APiQypI2U7qoSSYK3C/4R5Jqz/V+dllVnEVg8vvselKeoHjiKxA/cAkvg6tys5ob+/LehFk+7Iux X-Received: by 2002:a05:6402:17e3:: with SMTP id t3mr12220927edy.203.1587830058732; Sat, 25 Apr 2020 08:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587830058; cv=none; d=google.com; s=arc-20160816; b=UjgdFPxIy0UOB1K3eqzOldIRMN4K20H6xPi9f5+dkhuruRJpFQiTckjIBleaTL7UmR eBcD2FFmQsmDCEqiCG6FmDSNkT1GWeVWmSFnUH51MlA1ZVTHbW0F3QYhkedHZWvNaoXk Zddga2gAKC0GdMZqvbIqJQ5v4FDlZOHuMzucrjg2OHQS/fXKUqzm2RqY+pu2/z/ZO/oh G2KTO4LNzegPQtrEL42g6JHguPS3rDn+pMUY/Nksfl0ZpVCyFCOJ5t6i/jhsnf2VlGSl mBCOjbCFeYb9Q5DzvLs3qE+/wSuW4TE2vZEHU0xW6grmT5DV/dXUk1sQCkgTh5bU26sQ OLJw== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Ym0GuE6UBWGEvJW9mH76OfRAUgpFXUZtk4Bjh1icz04=; b=X68AYvEZQXWBFYNlpliQH2an5HQWJ+Lk9jYegbyiFKfGZbQGnhFR7wfps9lXoSKfVC Z/GsoRS1StIFUSsnAjBU8Ds22nPSIbSJrT1ZSaFmViGjyfSXL3y9x7y1aTp21vb1eK6I uI0bng1YbhAk3TYX8wJ1HzV592amKLJdlFA2VKH156Ebzd7Y5K5gFuKc5RcTruMAmFhf OwucQFs00WlejDDLLS/f1Ki/Q+CjiOvwZ+kBtUPflZMUo3FnSO9v05V884hf6CiMriHG hW+FMtyBdzPWywD4sdSQD1U35jbATqryyR2JyEX1P7JP7E+e3cv5m2AiHby1OqTK8mEN 7Czw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jd99gAHJ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si5842446ejt.101.2020.04.25.08.53.54; Sat, 25 Apr 2020 08:54:18 -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=@kernel.org header.s=default header.b=Jd99gAHJ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726128AbgDYPw2 (ORCPT + 99 others); Sat, 25 Apr 2020 11:52:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:56040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbgDYPw2 (ORCPT ); Sat, 25 Apr 2020 11:52:28 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3416520748; Sat, 25 Apr 2020 15:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587829947; bh=sSzcBJpJQDV6XFyy+Mxe6whwFoOrRKDwYzXXoWKA+Eg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Jd99gAHJsOwVZSzFyax2jkh18W+fjYSLNqtyhqF2PT7QyXptbdMHX6llBbNoltt+P zZ7osfqjIMzLYdErQie9d8YJoB/g7j1ykdNjFo5uuI+85ZI2uVKn4vNmWIRh2sZEzX NdCwAs/BcJQozbd4UlHatGkMwKxhVhhIwSp6gyzw= Date: Sat, 25 Apr 2020 16:52:23 +0100 From: Jonathan Cameron To: Andy Shevchenko Cc: Mathieu Othacehe , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , linux-iio , Linux Kernel Mailing List Subject: Re: [PATCH v4 3/4] iio: vcnl4000: Add sampling frequency support for VCNL4010/20. Message-ID: <20200425165223.0fc0e930@archlinux> In-Reply-To: References: <20200421075532.19192-1-m.othacehe@gmail.com> <20200421075532.19192-4-m.othacehe@gmail.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 21 Apr 2020 15:22:11 +0300 Andy Shevchenko wrote: > On Tue, Apr 21, 2020 at 10:56 AM Mathieu Othacehe wrote: > > > > Add sampling frequency support for proximity data on VCNL4010 and VCNL4020 > > chips. > > Couple of nitpicks below. > > ... > > > +static const int vcnl4010_prox_sampling_frequency[][2] = { > > + {1, 950000}, > > + {3, 906250}, > > + {7, 812500}, > > + {16, 625000}, > > + {31, 250000}, > > + {62, 500000}, > > + {125, 0}, > > > + {250, 0} > > Leave comma here, potentially helpful if it will be extended. Hi Andy, Doesn't particularly matter either way, but given this is a list of the values supported by the device, very unlikely it will be extended. Games like trying to share the first part of a longer array between multiple device types might occur, but those are usually really ugly. Jonathan > > > +}; > > ... > > > +static int vcnl4010_write_proxy_samp_freq(struct vcnl4000_data *data, int val, > > + int val2) > > +{ > > + int i; > > + const int len = ARRAY_SIZE(vcnl4010_prox_sampling_frequency); > > + > > + for (i = 0; i < len; i++) { > > + if (val <= vcnl4010_prox_sampling_frequency[i][0]) > > + break; > > + } > > + > > + if (i == len) > > + return -EINVAL; > > I would refactor this > > unsigned int i = ARRAY_SIZE(vcnl4010_prox_sampling_frequency); > > do { > if (val > vcnl4010_prox_sampling_frequency[i][0]) > break; > } while (--i); > > You won't need to go full array to return error in this case. > > > + return i2c_smbus_write_byte_data(data->client, VCNL4010_PROX_RATE, i); > > +} >