Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2965855ybl; Fri, 20 Dec 2019 01:28:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxOl4cql6PF2kS82SCXmVmzxEpp01wlDJCxhT0dV5owliY8KWRGXGuhvg8bSQVo3qzCJV3W X-Received: by 2002:a05:6830:596:: with SMTP id c22mr8441457oth.188.1576834137432; Fri, 20 Dec 2019 01:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576834137; cv=none; d=google.com; s=arc-20160816; b=ClzVXYI6uEVfbAbXQq3oA6dmPla3qEPcYcpG18iPjvPqWWzS0DpOq/HlHNzVt024Qw yfb+imjugienHjIk2Opi8xFWADSW75lxUR9z2nUVAMcBzuEqvIef1Hg/UHCbPOGdjPnx xCLUKj632bsmtn7g3oMskc/6G5uMVZGPeVydYbkLjT3HS9nUwsVpfM9D1ttgxzhlG+ut IextwBgXHI23kpg0RpuXkbEOA1CSW8RxirOLGZNwRZRmsxB2GdajjiBHrt68TSZQBOPV Rp0GbefASGdx74BrPxKFdfyDPgXJfIEqaLlqwIBLCni7gOwsx747wyc5EFDhGexgjP59 VkMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UNKiOniHzSKU3M0oT+PWGTepgoOHttWen9RJRN7cbpk=; b=oPqqep+v06itt90ZBBlbJSsczpKSDYpO9wQZ7FjxpjkoNJb1m3FoY8p5EwmBA0KyDG BiA3XD4aqws5UcOR7fb/JmiWx53u2y+w99fS57lnM4Y93g8AqKPxzYy0QIA3f42E4OKp bOJ2mrIjzlRK11roqbZ4XidYT7+uAqDKMjEf7Jo8Fj1+AoTMx3cOZQ+BhZ+GCNK2J0q4 xWvl7TXZIPYi6FOaxlpogG1sO2dV7CaqaeBh881q3rrpOMTfiv8+2XSQG5ax74eg4cRa yCSCmUugP8VrdbosuyuoGS0q/c9g6Z3MBLgSm81RSZLvL6lS0cQi7l9d180MkyJJsSgR TtlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uH0KpIPu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i185si4671944oia.187.2019.12.20.01.28.45; Fri, 20 Dec 2019 01:28:57 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=uH0KpIPu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727399AbfLTJ1V (ORCPT + 99 others); Fri, 20 Dec 2019 04:27:21 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44449 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727167AbfLTJ1V (ORCPT ); Fri, 20 Dec 2019 04:27:21 -0500 Received: by mail-pf1-f194.google.com with SMTP id 195so4005454pfw.11; Fri, 20 Dec 2019 01:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UNKiOniHzSKU3M0oT+PWGTepgoOHttWen9RJRN7cbpk=; b=uH0KpIPuYsKhauy6uDQhR85oanHO0ONzdFK7YxazqR6sWO9AwuAefTRRLoK/BWBk6Q CTt4LtkBoZ87Na9BXfi97V5YLBsPuD0UV9e5IcniNMOlKjjgRAJ+d2Lasbchk9lQSpSt AAs2v73a9RCHWpbm9qz5q+3kgLG8l6T7DoF4juV+sEM2pwMN1MbyrcmK8cLDy7ApOcxg MerYx4DlqEJ/0awwoKr2crZ/Y9G5pbv01mKyWL93w+w7UB3vKy7uu3CtBMQniuMNb5Qs 81tlO/0iXZy228ouq1IMN4VomlwZBhrAu4N546u3gCQjLb9g36UlQD7q5zBlUcd8URuY fZrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UNKiOniHzSKU3M0oT+PWGTepgoOHttWen9RJRN7cbpk=; b=dFylgAAtfum9DdSMcEdO+1kB383jHG+bgnWGhhNo75iKCNIAjQKrkg8nVr2B6hSlXG mH/szNVRzSzJOcJETrCq4aZZVaRaPjWDy2sDwrn8FKA579IxQzSKiU/R5oCWW5s0Cq3G hYNFWhuBasXp4CxcZ8SV9P4hus8p8eATpvkhgMIqeDBqawjEiNFKsUVmtkyrotVSc9Tg viLSvDBwbluKvRo3RAGD2l/mwVwFyoj6LsqfMOYJP0ioAg1yusmjUqTwY6cNlO0j37i2 7NzufRx6gzmDUPKOFT7vFmZ1lCPzJi7k9t9HL9beu8yQPkZZku9U12z6qinG1cx4W1Hy DTvg== X-Gm-Message-State: APjAAAWn4nUxoNA4JOM/9x/ElUigqHaX03vLl/27EV5dddLk1+TVdzo6 4Hafqp+yU+UKOr58+365azh5gMcp3PtXmckjqfc= X-Received: by 2002:a63:941:: with SMTP id 62mr14407335pgj.203.1576834040029; Fri, 20 Dec 2019 01:27:20 -0800 (PST) MIME-Version: 1.0 References: <20191219041039.23396-1-dan@dlrobertson.com> <20191219041039.23396-3-dan@dlrobertson.com> <20191220043220.GA16415@nessie> In-Reply-To: <20191220043220.GA16415@nessie> From: Andy Shevchenko Date: Fri, 20 Dec 2019 11:27:10 +0200 Message-ID: Subject: Re: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400 To: Dan Robertson Cc: Jonathan Cameron , linux-iio , Peter Meerwald-Stadler , devicetree , Hartmut Knaack , Rob Herring , Mark Rutland , Linux Kernel Mailing List , Randy Dunlap , Joe Perches , Linus Walleij Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 20, 2019 at 6:48 AM Dan Robertson wrote: > On Thu, Dec 19, 2019 at 01:02:28PM +0200, Andy Shevchenko wrote: > > On Thu, Dec 19, 2019 at 6:27 AM Dan Robertson wrote: > > > +static int bma400_set_accel_output_data_rate(struct bma400_data *data, > > > + int hz, int uhz) > > > +{ > > > + unsigned int idx; > > > + unsigned int odr; > > > + unsigned int val; > > > + int ret; > > > + > > > + if (hz >= BMA400_ACC_ODR_MIN_WHOLE_HZ) { > > > + if (uhz || hz % BMA400_ACC_ODR_MIN_WHOLE_HZ) > > > + return -EINVAL; > > > + > > > + val = hz / BMA400_ACC_ODR_MIN_WHOLE_HZ; > > > > Again, AFAICS division may be avoided in both cases (% and / above) > > because of is_power_of_2() check below. > > Can you revisit this? > > Yeah I can update this in the next patchset, but I don't know if it is much more > readable this way. You may describe the algo in the comment. Let's see how it might look like if (uhz) return -EINVAL; idx = __ffs(val); /* We're expecting value to be 2^n * ODR_MIN_WHOLE_HZ */ if ((val >> idx) != BMA400_ACC_ODR_MIN_WHOLE_HZ) retutn -EINVAL; idx += BMA400_ACC_ODR_MIN_RAW + 1; Would it work? > > > + if (!is_power_of_2(val)) > > > + return -EINVAL; > > > + > > > + idx = __ffs(val) + BMA400_ACC_ODR_MIN_RAW + 1; -- With Best Regards, Andy Shevchenko