Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4802318pxv; Tue, 27 Jul 2021 17:22:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoZ8P/Dnl5wOhzesEWdbfUwsWUQ5jMDqDQG2h1tVS9EXkuKgSoBxEt8jhUgrGCMtC6CnyC X-Received: by 2002:a92:d848:: with SMTP id h8mr18731490ilq.282.1627431768860; Tue, 27 Jul 2021 17:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627431768; cv=none; d=google.com; s=arc-20160816; b=NOX5Ru8zx1yABezkcTMLscSH20BguvNfBd/gGjGK8FLps7eJBHe8aGtWb3I6KcUsYi eYtZXl5Iyqzsp9lHXCI1kzU3Bhcw7g+Ozu2DKSPz0CO+9QXHgJys4uGS7CtLrVMJ96YS orX3ky/d4jr891uRN3wAUCTZzRehW57IkRyILhgAfdn8klHUHtsm4r+ye5au9hb83rj0 RUi4jDFo2uOpuz8rDGtweeVRDGtY0gK6I7UmsZwUghOOyTq5rwTzK6119DH6Pe26EpU3 zOG4IOZQrliyhbiuI1snjPLQ/CGlDykXfM1MwA+Kgc9oqkE4gIfOhXfkWq1R+GrXbIG4 TLQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:from:subject:cc:to :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=ieU8fOn6s7zZr4BKBCLnzcFzUpNY4Uo3GJhrUvPuu4g=; b=wlAoCU5LLKooBKjDB08ydW+DX59XXcQFDxCN+FotSm77U6PmUESmcDAtgZrWtEi8Bg w2st3txoZc8VpebpxwKaEETHmESucz6CymmXNTINu/VvBvWEc8T9NnlaiMrw8nuDvwuy tv6oONfHs0+NcrJZnK9XMvAXwtRZSPr+zYLc0cqhnL6lk6HPERL0NKoRkXK01binPpO+ bmTRgtI0sYiug2gjCwdDF1xsnxCCioPWQj+tm9GL82GvDZwvWgg3Bgw0QZ4gHYnqP5sk /XEb9ESD/TLz44mTKRNsHyH6zxlErs/IgqTljTEQOV0QwBJdgqyjnJbejEB+NbElkdpr XVPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AIAsv0Al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id r17si5374808iov.104.2021.07.27.17.22.37; Tue, 27 Jul 2021 17:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AIAsv0Al; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232989AbhG1AVw (ORCPT + 99 others); Tue, 27 Jul 2021 20:21:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232778AbhG1AVw (ORCPT ); Tue, 27 Jul 2021 20:21:52 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75AB3C061757; Tue, 27 Jul 2021 17:21:50 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id w10so172801qtj.3; Tue, 27 Jul 2021 17:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:content-transfer-encoding:date:message-id:to:cc :subject:from:references:in-reply-to; bh=ieU8fOn6s7zZr4BKBCLnzcFzUpNY4Uo3GJhrUvPuu4g=; b=AIAsv0AlWgs1k360wEg3aMEqUQrT1BKCRb290p2lu9WwvRCNh8hLmPiCraFUhPzjpl 1x+VmTtHpsY3djNoRPKuN2wg2iTH+P1cemMuJ4l1NduNzvtqK3ZObQSRYPKLNFocWL6D 8KekdovqCNPjQnModVah6v34yWwtKKuw28wzksIUUYCuOeK/i1ev2Kb73GVkaazBuK3M MYsBN0P2aNP6exOM5Wt256oBnvqIXwaRz/r1c7aitxsxglGTlG2v7GVkJ3U9FM4Zp8RP 2iWh5NgQetBTtUsY3e6+4XpZUp8wmGkZf4JXZm5YymNQzSMmnUClKd40KUyduLXGu5Rf 5u0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding:date :message-id:to:cc:subject:from:references:in-reply-to; bh=ieU8fOn6s7zZr4BKBCLnzcFzUpNY4Uo3GJhrUvPuu4g=; b=K8ZaK1roKcI8FlN7hgX21KnEfa6N7LQQZvHxelWYJ6Z6H11XP0EpwMsKxmxu/p3gkr Pxi0/A5yTvhRCBkAN/70uzou/aUuhyySOAsgA1miVousVrVHzbdlQG8gpIaqbsJOO81l hrQB3LC7Ltkfi3ajr8T+DwdZlkOoapiWx6PBBlbP4uUgSm4/LsEXOUkOhKwlRNlnPW3y EPVgN6cMtYEIT3VfkK52rKZyazpafuoqPOOs7/mggjE9nsmBQQsyMWgZK5JXpR4YvM4K jTUhKcy0Kh+QtAjS5aizWEyT7aD0nBl6pvsX0BU3xhNMIG4FzyjIciVHrrPez8fPKvse Hszw== X-Gm-Message-State: AOAM533BgqWyeDTIg7HI8DbiN49DwmC1/Cg0HMvNQKLIT4Ws2KIhWiyR mgVrjZ4eBf2ouI7/UvmAL9I= X-Received: by 2002:ac8:73c2:: with SMTP id v2mr22147267qtp.86.1627431709652; Tue, 27 Jul 2021 17:21:49 -0700 (PDT) Received: from localhost (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id a21sm2533000qkk.74.2021.07.27.17.21.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jul 2021 17:21:49 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 27 Jul 2021 20:21:48 -0400 Message-Id: To: "Peter Rosin" , , , Cc: , , , Subject: Re: [PATCH v6 05/13] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support From: "Liam Beguin" References: <20210721030613.3105327-1-liambeguin@gmail.com> <20210721030613.3105327-6-liambeguin@gmail.com> In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri Jul 23, 2021 at 5:16 PM EDT, Peter Rosin wrote: > On 2021-07-21 05:06, Liam Beguin wrote: > > From: Liam Beguin > >=20 > > Some ADCs use IIO_VAL_INT_PLUS_{NANO,MICRO} scale types. > > Add support for these to allow using the iio-rescaler with them. > >=20 > > Signed-off-by: Liam Beguin > > --- > > drivers/iio/afe/iio-rescale.c | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > >=20 > > diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescal= e.c > > index d0669fd8eac5..2b73047365cc 100644 > > --- a/drivers/iio/afe/iio-rescale.c > > +++ b/drivers/iio/afe/iio-rescale.c > > @@ -41,6 +41,20 @@ int rescale_process_scale(struct rescale *rescale, i= nt scale_type, > > do_div(tmp, 1000000000LL); > > *val =3D tmp; > > return scale_type; > > + case IIO_VAL_INT_PLUS_NANO: > > + tmp =3D ((s64)*val * 1000000000LL + *val2) * rescale->numerator; > > + tmp =3D div_s64(tmp, rescale->denominator); > > + > > + *val =3D div_s64(tmp, 1000000000LL); > > + *val2 =3D tmp - *val * 1000000000LL; > > + return scale_type; Hi Peter, > > Hi! > > My objection from v5 still stands. Did you forget or did you simply send > the > wrong patch? Apologies, again I didn't mean to make it seem like I ignored your comments= . I tried your suggestion, but had issues when *val2 would overflow into the integer part. Even though what I has was more prone to integer overflow with the first multiplication, I thought it was still a valid solution as it passed the tests. > > Untested suggestion, this time handling negative values and > canonicalizing any > overflow from the fraction calculation. > > neg =3D *val < 0 || *val2 < 0; > tmp =3D (s64)abs(*val) * rescale->numerator; > rem =3D do_div(tmp, rescale->denominator); > *val =3D tmp; > tmp =3D rem * 1000000000LL + (s64)abs(*val2) * rescale->numerator; > do_div(tmp, rescale->denominator); > *val2 =3D do_div(tmp, 1000000000LL); > *val +=3D tmp; > if (neg) { > if (*val < 0) > *val =3D -*val; > else > *val2 =3D -*val; I'll look into this suggestion. > } > > > + case IIO_VAL_INT_PLUS_MICRO: > > + tmp =3D ((s64)*val * 1000000LL + *val2) * rescale->numerator; > > + tmp =3D div_s64(tmp, rescale->denominator); > > + > > + *val =3D div_s64(tmp, 1000000); > > Why do you not have the LL suffix here? Doesnt' LL make it into a 64 bit integer? I left it out because the second parameter of div_s64() should be s32. Thanks, Liam > > Cheers, > Peter > > > + *val2 =3D tmp - *val * 1000000; > > + return scale_type; > > default: > > return -EOPNOTSUPP; > > } > >=20