Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3340670ybl; Fri, 20 Dec 2019 07:44:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwcox8vuBYAQSrqWNDeUSVyAZmYSWoqMFXYRnshM2tu/XXt84ytQDKG6FlxyD3J+IRC89Sm X-Received: by 2002:a9d:7357:: with SMTP id l23mr15208138otk.10.1576856678918; Fri, 20 Dec 2019 07:44:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1576856678; cv=pass; d=google.com; s=arc-20160816; b=uuY5G1OGiR2n32qZ7wBXCbl7xkwJLGegOCM8YPcIj6gbDWIS+p0n0WXj2B36Cza0ym UD1YwQAEZSheGypj4trQwkQMsDFlYEaDFxGdwfQ2Bf3W2yx/7Ks04XNE5wv/TPZVWFRo C4Tq85al+7nSkWLL8M45rwf+PU9mtnCkSYFlgEca1hv6E6TVLv7bFFNO8K5zxc5QapCn fjUIhXDHZHocsq+ZywnxWtjhq1e451SRMqtLiPMPq3WwzQS1MdP2YqpSaxq+2LFlPSDq GMX64a0L+NNxj3y5i+A2b7lPYC1pk6icioTqPB9aPXmqHhlVIBnAOWm/7K57fd+/O6H6 FaxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ELXCfpLFeQLNeL9QjnCCUngKGgfk8dL/TAnQ4db+uqs=; b=s9osRtz+hbsfglvSSjCgRrYTIvVkosPoWktin6sBXUVaG51ZoYptbhgf2q/ShZIKWs IKp4Dr66ODRlCZRd7ZgwFSv0j2acHYOpUa6/GGtnY7qkH53B7HT4XCSnLCl/LNMX9Oiu 7AX0ALSjFS17xcJQuUTWD+67YV/n475NdbaA6gf3CCyDWy5jft4IOCggrn3eAu8+CB+Z UYfCTa5gW3FUdOEFtj9qsi+wi9oFmyBiMXVaFQhbepbQbegCn8SLXLHzh0sNBWFFeP4N ddkSfJFNSwn5VjxthJLytn8q8KD8lIps/PG6SuCHzq6cmtJBg/JWCvqQFwlhDFlyEDaX OEsw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=dlrobertson.com dkim=pass dkdomain=dlrobertson.com dmarc=pass fromdomain=dlrobertson.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 l10si5465043otr.159.2019.12.20.07.44.27; Fri, 20 Dec 2019 07:44:38 -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; arc=pass (i=1 spf=pass spfdomain=dlrobertson.com dkim=pass dkdomain=dlrobertson.com dmarc=pass fromdomain=dlrobertson.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 S1727571AbfLTPnu (ORCPT + 99 others); Fri, 20 Dec 2019 10:43:50 -0500 Received: from sender4-op-o11.zoho.com ([136.143.188.11]:17179 "EHLO sender4-op-o11.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727394AbfLTPnu (ORCPT ); Fri, 20 Dec 2019 10:43:50 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1576856617; cv=none; d=zohomail.com; s=zohoarc; b=LMfAddAC147eF5m77yvmXtqBvWmzPz8EeM2CLg/O2oKsihO159fCaKZNAIdl+JtIqPRpT6QwsyZvE2pyPitqWgFoHWSR8mst+1bZmyhjSXSKwrgNv21iyY60GkBMesduxm3HopdH14oWSjK2+ldR/BxnPJZPPfdh03fYjLnt6jw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576856617; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ELXCfpLFeQLNeL9QjnCCUngKGgfk8dL/TAnQ4db+uqs=; b=fdiUXZnwWeK5DxojtYqIUglgxCAUgdU93kUYA4cRBK67fgNvv5ODmXCr6D9pzABvTz/y9QtJklZkX46F3cJlxFh6FIHkIJnG2KUaAFnqa1aaaux3874olKeYVbPgT+feEiHhYSm1hT5r2vndVTy76Wo7x+N50JGwRFnLth9nTlc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=dlrobertson.com; spf=pass smtp.mailfrom=dan@dlrobertson.com; dmarc=pass header.from= header.from= Received: from nessie (pool-173-73-58-202.washdc.fios.verizon.net [173.73.58.202]) by mx.zohomail.com with SMTPS id 1576856616397592.4934687792177; Fri, 20 Dec 2019 07:43:36 -0800 (PST) Date: Fri, 20 Dec 2019 15:28:05 +0000 From: Dan Robertson To: Andy Shevchenko 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 Subject: Re: [PATCH v7 2/3] iio: (bma400) add driver for the BMA400 Message-ID: <20191220152805.GD16415@nessie> References: <20191219041039.23396-1-dan@dlrobertson.com> <20191219041039.23396-3-dan@dlrobertson.com> <20191220043220.GA16415@nessie> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ZohoMailClient: External 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 11:32:42AM +0200, Andy Shevchenko wrote: > On Fri, Dec 20, 2019 at 11:27 AM Andy Shevchenko > wrote: > > 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) > > Okay, this would require trickier conditional for the cases when > MIN_WHOLE_HZ can be divided by 2^k... > Still from performance point of view it might be much faster than division. I think the other checks will ensure we return -EINVAL in those cases. I ran a basic for loop and verified this. Cheers, - Dan