Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3531230ybl; Mon, 12 Aug 2019 01:59:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsxSkJ+oHCEEvgxlepQ5v1eJBkg09dwrOMKj4S7/1+5995avxafnLH1CDhMgHVNtZRdV3f X-Received: by 2002:a17:90a:1b0c:: with SMTP id q12mr22647863pjq.76.1565600391049; Mon, 12 Aug 2019 01:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565600391; cv=none; d=google.com; s=arc-20160816; b=f0J0P0Qqg8Uq577+dXHo+fIZC38VXrq32QeVGyleTk+AgUfdS5G0L3H5pBKI7nm/JX FlGqbD1x6vGH0OsKRP0MxvXLJfeWFBFNveMyGKPYv7ORE85aXKoXAihWJLB91/EFxA39 1xEs+iNS2j5dssgLARsz2gWFOGZ+sIPjfigNepxqTKIMJ0YSh9k2I9K0e/BkoTX1woq3 V0WO3NrHKfygcl9KoKCgHIMjyMOU2ewJ7zjnJ6GdqDeUIlByLbNHq+cYFFNEJVEAJAsR L7J/q6tL0M4tki4ygYA7RdhACL4rIxHS62JVzd8TQ9eJYkrjOICgw8c+gx2/c43U+ZcI 2gWQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=haJeuiCmSjfPYJb0Cmdo4VWSIDJ9tP6uFxCZ3Rg0T0M=; b=Ut17gwKH0QkHti4AGxMHntKLdDuBwDnIZYPILwiuZm4r1Ku/8qidlErwXF1Uivx8qn 6Tg2nHx0N0tzh9ONK25gPZeS1Mvf7eM0KiukXwu1zmXooQxLj+DS4+qcX5SriWEIETN6 +3MoZV0kzcTMEJ6CITVfBPrmbRP1Xdr4x6XXQ4z8e1RwrMmhuWih107EMtsppA/bR5Zr 4c8llOJGq29g7nxgDmCS/v8+QgUOEWFewtUGiDILfybkhu0uSDsAb+kO83wZkAXvEpFg tuWBOm0zYGEbZHHyyuabGKf7nWyYTluFo02sjpB85bELT43+hWRo9D3sIBUXsmUYHElD qAwQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si55898778plz.109.2019.08.12.01.59.35; Mon, 12 Aug 2019 01:59:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727205AbfHLI5o convert rfc822-to-8bit (ORCPT + 99 others); Mon, 12 Aug 2019 04:57:44 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:56574 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727167AbfHLI5n (ORCPT ); Mon, 12 Aug 2019 04:57:43 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9EE8799132131362ED60; Mon, 12 Aug 2019 16:57:33 +0800 (CST) Received: from localhost (10.202.226.61) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Mon, 12 Aug 2019 16:57:30 +0800 Date: Mon, 12 Aug 2019 09:57:17 +0100 From: Jonathan Cameron To: Rodrigo Ribeiro CC: Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Stefan Popa , Hartmut Knaack , "Peter Meerwald-Stadler" , Greg Kroah-Hartman , , , LKML , Subject: Re: [PATCH] staging: iio: accel: adis16240: Improve readability on write_raw function Message-ID: <20190812095717.00002918@huawei.com> In-Reply-To: References: <20190810150058.3509-1-rodrigorsdc@gmail.com> <20190811094322.063ad682@archlinux> Organization: Huawei X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.202.226.61] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 11 Aug 2019 13:47:04 -0300 Rodrigo Ribeiro wrote: > Em dom, 11 de ago de 2019 ?s 05:43, Jonathan Cameron > escreveu: > > > > On Sat, 10 Aug 2019 12:00:58 -0300 > > Rodrigo wrote: > > > > > From: Rodrigo Carvalho > > > > > > Improve readability by using GENMASK macro, changing switch statement > > > by if statement and removing unnecessary local variables. > > > > Hi Jonathan. Thanks for reviewing! > > > From your description it sounds like multiple changes in one patch. > > Always preferable to have one type of change in a patch and more > > small patches. > > > > Based on comments below, I would leave the switch statement alone, > > but put in your GENMASK change as that one is good and gets > > rid of the odd local variable 'bits' as well :) > > > > Thanks, > > > > Jonathan > > > > > > > > > > Signed-off-by: Rodrigo Ribeiro Carvalho > > > --- > > > drivers/staging/iio/accel/adis16240.c | 16 +++++++--------- > > > 1 file changed, 7 insertions(+), 9 deletions(-) > > > > > > diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c > > > index 62f4b3b1b457..68f165501389 100644 > > > --- a/drivers/staging/iio/accel/adis16240.c > > > +++ b/drivers/staging/iio/accel/adis16240.c > > > @@ -309,17 +309,15 @@ static int adis16240_write_raw(struct iio_dev *indio_dev, > > > long mask) > > > { > > > struct adis *st = iio_priv(indio_dev); > > > - int bits = 10; > > > - s16 val16; > > > + int m; > > > u8 addr; > > > > > > - switch (mask) { > > > - case IIO_CHAN_INFO_CALIBBIAS: > > > - val16 = val & ((1 << bits) - 1); > > > - addr = adis16240_addresses[chan->scan_index][0]; > > > - return adis_write_reg_16(st, addr, val16); > > > - } > > > - return -EINVAL; > > > + if (mask != IIO_CHAN_INFO_CALIBBIAS) > > > + return -EINVAL; > > > > Hmm. We generally encourage the use of switch statements in these > > cases because they reduce churn as new features are added. > > > > In this particular case, we don't have any control of sampling frequency > > in the driver, but the hardware appears to support it (table 23 on the > > datasheet). > > On drivers of same kind out of staging (adis16209 and adis16201), sampling > frequency writing are not implemented, even though datasheets suggest a register > writing for this. I can try to implement if it is a good one. I would be a bit nervous about doing so if you don't have hardware, and we can't find anyone who is setup to test the device. Obviously if you can get it tested one way or the other, it would be good to add support. Thanks, J > > > > + > > > + m = GENMASK(9, 0); > > > + addr = adis16240_addresses[chan->scan_index][0]; > > > + return adis_write_reg_16(st, addr, val & m); > > Why the local variable m? Can we not just do > > > > return adis_write_reg_16(st, addr, val & GENMASK(9, 0)); > > > > If anything I think that is a little more readable than your > > version. There is a reasonable argument for just having > > addr inline as well. > > > > return adis_write_reg_16(st, > > adis16240_addresses[chan->scan_index][0], > > val & GENMASK(9, 0)); > > > > However, given I'm suggesting you leave it as a switch statement, it > > will be too long with addr inline. > > > > > } > > > > > > static const struct iio_chan_spec adis16240_channels[] = { > > > > Regards, > Rodrigo