From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C708C43603 for ; Fri, 20 Dec 2019 15:43:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4817E21655 for ; Fri, 20 Dec 2019 15:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727402AbfLTPnu (ORCPT ); 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: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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