Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2970815ybl; Fri, 20 Dec 2019 01:34:58 -0800 (PST) X-Google-Smtp-Source: APXvYqw7Af7UIVm78k51p+ei7VwD9vizRSgwvF+nKn3I0rMNCbmXBXaOYeRZHy8Fa39pXvhFQdUe X-Received: by 2002:a9d:7b4a:: with SMTP id f10mr14606645oto.4.1576834498671; Fri, 20 Dec 2019 01:34:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576834498; cv=none; d=google.com; s=arc-20160816; b=ocG63ii8K8xv0K9vmz+En9M+46B80er2HEhnhiNYkQJnMqB+V6vR5zJkWsY1K0NJGo a93EBpFnkqWByk5ZYrJKUlZO36Qz6yupBgHG4h+u+1B1ihGd2+zss9M3UWeUNWxeQpfK RqQvqtxTRWMtyrB2fwUYCIt/VzC8mWbchLcgIx7ciZO+EIyVlSA9Suyc0gFuhdln6/i0 g2GkIds4wOSKagtQ8KmE/BAQc14fxFpL5coHkdl4Rv/OF5I1u09sOqD5qV+UKTuq5pP/ M4xw+5n2nVq7EFRTBDOtvpPcIydtc6VSo0aXDNZxx3Z6jtYAkGVKgR4QY997u0YcIRXi /Gpw== 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=hXPvfKvwAwee7RsrZpIamZ8UANcZvc4/7hzUJ9vWG30=; b=f53c/WyFUbRlYPCndELiSxGggYwrcRrTede7neT7DRqJN+d1Gnbh7fJQRUJA3cFfgC LIR9qGTTBUAJLExctwenr7tfKGdTrO27AepJz/kv0r2dnywIJz+7uQ4dzddndtNV0nZE BFZiKeZeHbLULTqGBP5Qb6eOoIJTHjLXRyJnevlZoV/5VcL88wn7+rqcG0FLCqLn+AyY +7pEElzsDz68xioV/99iN/dj9LKQwq2lmviVkDbt9z67tqxArXVecRUr969iumTHiNMW 7Ef/r+wx2+k8a+D4D54k85BQQwtyVSXhC4b1FJB8dAbfRW1/Jzk5vXh0L0ZoGGRV1IFE snPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ufnVJ3iP; 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 n85si4458031oig.191.2019.12.20.01.34.46; Fri, 20 Dec 2019 01:34:58 -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=ufnVJ3iP; 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 S1727413AbfLTJc4 (ORCPT + 99 others); Fri, 20 Dec 2019 04:32:56 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34283 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbfLTJc4 (ORCPT ); Fri, 20 Dec 2019 04:32:56 -0500 Received: by mail-pf1-f194.google.com with SMTP id l127so4896139pfl.1; Fri, 20 Dec 2019 01:32:55 -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=hXPvfKvwAwee7RsrZpIamZ8UANcZvc4/7hzUJ9vWG30=; b=ufnVJ3iPxZcZtJ92hsB9jBbHS38GFsw9MyCcx9SHRHdXmWo1pI6ZDU4ZFgZ9JeU7ZS j2irv1vy1DCI/tEIMvh7yIDPtZ4T2IudbrsSUY7w2xI/3TNYdhDJNK4F0fqI2AjK4S1B DZnLX8Uk0BHcXbzLOK9slVuYcpDEF75U/nEREA0vm3SQj7PKE3i2dUru17xsbs7PGUa+ uHOr1Rs58B+A9FuO5Dp9W3nhFJ2wYxY31YasiyNKs/k1RteF/C5jxwRfvHem7LcAOi9t +DDteb1doMFCbUdUvGAAcbhL1yk50HwuVaCqH7+UjW7Kjt6F/GNcQIPX9MVEwJgoIE42 UdBg== 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=hXPvfKvwAwee7RsrZpIamZ8UANcZvc4/7hzUJ9vWG30=; b=HPtTG0JCTxOaBNgAIsfMmf+tNOeaRwFQ7NhINxvzxBhxfSSSuc8V2q5315PjkjKH2E aiKGEWFlL5gaJ4hpBo22WUXTS93EW9ODw+xyWBu/Y2fT1gbtaxlkpCGgp3Jp2O5JwukQ 1dUgYwR31j78hLrdSMAVveGCZQSD6iCqK6JIpixrcxCQ6S/psee2yA9sMZzUE/6Zecmk BXfXig3Tx2il9wo2kW4xaB8eYW+bA2Ku/4VjMVKjJKFWKxr0zBaJ4ZMBS+l909oNGHMd TEqCWnUgUhzGX1/qnOdQJkG5np2HkscRP+oab9xZL/PfRFLuBt0VZI198XqV5WarmnKQ uzYg== X-Gm-Message-State: APjAAAWwpY9dpUzpGVRoG7MhYV++Eq9GUzOuMobX9ujt2jHMyj6Qqqrk 7TNZlSkdmnElOIg4Vgz1rMTmnZc1X5ETp+7G9OA= X-Received: by 2002:a62:1944:: with SMTP id 65mr15366030pfz.151.1576834375318; Fri, 20 Dec 2019 01:32:55 -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: From: Andy Shevchenko Date: Fri, 20 Dec 2019 11:32:42 +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 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. > 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