Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1724794pxb; Fri, 20 Aug 2021 12:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4IRyY547t1naXHEv//QIXkS/XxJj2ceEJz1Y1yBZVOsRgfI9jd1VJag/4o0VbUuV7JNIO X-Received: by 2002:a05:6402:36b:: with SMTP id s11mr24981555edw.235.1629487225443; Fri, 20 Aug 2021 12:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629487225; cv=none; d=google.com; s=arc-20160816; b=fOGN1cenp3+/VYvjAt9XsgR0+KzIoE3pTfVMWIp+vNw+nxD/CsiOETomqoSbfQibkY xcenmSC4Q3CENR8TAc9soUDrIjkddvyH+b7eFi4baZFSPSB2PLZCi1D9JkCWHwmqeGau QvpW4IAY3FWtuV7TY/1aSyy4n60C5v5z07gru2cUtQ5Vqgx/WvljUIAuvzAxGoTKuWwy hjvJpuIyTimt2DadS1ak/uXYhJ+oo3Ik+46oexcexTMcXH1CT937EeNgtHGlQp+pZAu+ 3zDsxWQSWaVp6vfn4pKDMuUKd/JXc5s60Q4fjVq4728IqQjP9otswJcJCsZ+owCo1E02 HvQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=R+zgKUXTnho1DuYnz2N4IQ26TfKFFIYe0e2gWK71jNo=; b=z7fSYv/DDW41tCrVrvt04t7UpNcCNnRYqFp2AMxBNEeB2bsrg+2F9B4DhLGLzbA2lk 1NJULBH/IFfdyQukpWLAC/QhM3Ia9zPkxHwoQKJE/qtxO00qNVXmsRYb93m1j7jJIgXS KXdkgQq9puZsNhX8zgR6Wx/KEXFpNnmXO804rOy8fYgCzKLHcQPG14V/7i4ctB+UdVtE RWQ4+LpN/29XjQV8Ci/WoB0NlGK7XkMMcq8FNixbEI87742ayB2VXl2WNgRv2zdpCeS9 xR9YVogsPQ5Uc7+Kj4YVofxKheUieL76M3Q2uH7DAmB1VcIYWuha5wf/9MWmc8DginYB I2iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SVDHAG5e; 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 bf22si7273789edb.311.2021.08.20.12.20.01; Fri, 20 Aug 2021 12:20:25 -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=SVDHAG5e; 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 S239336AbhHTTSy (ORCPT + 99 others); Fri, 20 Aug 2021 15:18:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238427AbhHTTSm (ORCPT ); Fri, 20 Aug 2021 15:18:42 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E8CC0617AD; Fri, 20 Aug 2021 12:18:00 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id t190so11935526qke.7; Fri, 20 Aug 2021 12:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R+zgKUXTnho1DuYnz2N4IQ26TfKFFIYe0e2gWK71jNo=; b=SVDHAG5esKb79+7OfCI/tq1W+FWERAgwfbL8+y1Rig9RZBLXFyO51oAqUpTaQ0iDuH oHnZioX1bwoVAPA5ZxnHt57dsncxgvevEcl/OXDkyXU3iKkqJxf2LCqq+vup/k+5B4XJ BhZdhlDXEu2I3nmBmi9r5nzXPr6+4uBf+F8jmAcoHaqs5ykiAu4kaF85HjNuEukz0T/1 TTCUsWHKzZ0fG0strInWQu3nvTTyiSaYp4HcfleUMlE8nK/L280FAfHTzYA0ny6U3QQD WE6pIzb4SCMzT27CopxB2gRi8XwGJvw2xh7rZeQ6Nnx9t3Dpogx+afAS1GW30e8Ifssd bMgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R+zgKUXTnho1DuYnz2N4IQ26TfKFFIYe0e2gWK71jNo=; b=hpzbDTZT9M7A2kRj6xjdG+A/adMMUtTBpyupBMenxFrR+04F+fT9ZubpP7eDfPT9Uu EezD4WpJjLq5s1+uATBpB6SlYLyOTsrLFYt9mmkO3BQojeL1knJqx3Rll3tFdCNePlJM fiRtDDR0Ax0SC9nuWdAGNawg5W/TuWqZXJoN2slnHQVfn9J34QTayrFwzAze3TSclE46 RcYtNYc1HcsSre6lz1oCUFJ3WDnPCT0EXWeZsZRjXO3zBI1xoL/PUT3F+YBdLqOnn7Rb EMEKzC6SlBmteVo8gOcNTlNAeVIZJC5EUUvmBckYpgbjKrGEmmENZ59FxwQCfnKGrlcQ rsNw== X-Gm-Message-State: AOAM532+gdz4iFsaHApOtWjDNxFcmozpZ9NKVHte1zFPkOTL7ehRq4jB a+m2x7ofP/u3vZN6yLoK0RI= X-Received: by 2002:a37:6103:: with SMTP id v3mr10319950qkb.12.1629487079253; Fri, 20 Aug 2021 12:17:59 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id o6sm3603869qkp.111.2021.08.20.12.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 12:17:58 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v8 07/14] iio: afe: rescale: use s64 for temporary scale calculations Date: Fri, 20 Aug 2021 15:17:07 -0400 Message-Id: <20210820191714.69898-8-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210820191714.69898-1-liambeguin@gmail.com> References: <20210820191714.69898-1-liambeguin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Beguin All four scaling coefficients can take signed values. Make tmp a signed 64-bit integer and switch to div_s64() to preserve signs during 64-bit divisions. Signed-off-by: Liam Beguin --- drivers/iio/afe/iio-rescale.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 48a8096f68ca..809e966f7058 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -21,7 +21,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, int *val, int *val2) { - unsigned long long tmp; + s64 tmp; s32 rem; u32 mult; u32 neg; @@ -38,10 +38,10 @@ int rescale_process_scale(struct rescale *rescale, int scale_type, *val2 = rescale->denominator; return IIO_VAL_FRACTIONAL; case IIO_VAL_FRACTIONAL_LOG2: - tmp = *val * 1000000000LL; - do_div(tmp, rescale->denominator); + tmp = (s64)*val * 1000000000LL; + tmp = div_s64(tmp, rescale->denominator); tmp *= rescale->numerator; - do_div(tmp, 1000000000LL); + tmp = div_s64(tmp, 1000000000LL); *val = tmp; return scale_type; case IIO_VAL_INT_PLUS_NANO: -- 2.32.0.452.g940fe202adcb