Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp600323pxb; Tue, 5 Apr 2022 15:31:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya6+JNtlXel6xosNFhydi4134hqnTsPo0xmyXPoxltJHGT9/mxatUl9ifkhoEYvl1X8O+j X-Received: by 2002:a63:df14:0:b0:381:309f:10bc with SMTP id u20-20020a63df14000000b00381309f10bcmr4657211pgg.77.1649197876985; Tue, 05 Apr 2022 15:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649197876; cv=none; d=google.com; s=arc-20160816; b=qrJ3c0MYFBwTSHBy5DafvwuGb9QhTSQOaqAHROP4sCjqyB9w5G1hXEm7d0vZF9ESDU oHsMOI1Hn8mIatER8BeX4zTvJ2uLQUjvQIs87Y83wyhebA+Bk06Mf8SCNUK+Xao2jZMf AqvCpAmYP9nrAF9cfDWqK2VWA/xLMaZR947I7L1wPs8Oc2Q45BBr7L5iKHfsqRhU1rOp 5aSPTKAMjkFwtP1k2BxseZahlGJpaTUy6Qb7U8grveudV2gVW8Kdknm317H/ROaKwQVm 8BMpXG7ooX86dHwdH4eVdudy1TcjB+lKUN2YG7l4uZ9NU/fWPIxoD0QFjoysg1nDF/20 II+Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r1r3YifSxviTQRNlzrHskZhsqg8SotnSmD1Q8iypgxE=; b=al8S2Ys6Klo6mnx8oqIpbQ+aVR/PxTh1+k2usDnBe0ttOlItBU6jWxoHPrCRPze5HI 8gH7EXpLzwtFsvAyDhl+6x1ZFSYrtbC9VeH5iqRubpLrfODEhqb3d9TMV+z0Pr2SzUfz no3ZvUDuYf1cTTtghCp5ZUyBRxOYPOb+e+7ObuSmpYfFJ0LiMTAjAkS09XffMi5xnW6j o9qhcl636WLa6ChdHfRIWJ6clb+e3IRam9tnaVge0x1NLVzFgg3cz1i86LVu7k5li94u 8wfA4Ddr3Xisrza03SVRvylnXFAzG8/XYf1H9ve01E2c5TamMMooXH3t3GInEjBIfj96 EYsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lQK94LR2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g14-20020aa79dce000000b004fb4e9b18f3si12814427pfq.245.2022.04.05.15.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:31:16 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lQK94LR2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7CE6F207A07; Tue, 5 Apr 2022 15:12:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383137AbiDEOR0 (ORCPT + 99 others); Tue, 5 Apr 2022 10:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239437AbiDEJdi (ORCPT ); Tue, 5 Apr 2022 05:33:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FEA135DE8; Tue, 5 Apr 2022 02:21:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2CC8B61574; Tue, 5 Apr 2022 09:21:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A9F6C385A4; Tue, 5 Apr 2022 09:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150517; bh=aEb6bFctWPFgGqy+PW+9mHUKyTN0aHivpB5iy1Ji954=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lQK94LR2HlGqpNbbNycPUNUUhPyMJTnERvUlfEw9+P60J6NQnKAWGp+4WTk/aAUQF Gr6S7LTwHsAvNJfh7ac8VRUasGaaIPvdOk+fM04yW1pyhtGpcB4c+Lp6gUhb1VnmIn QT1y1oyCkjvSAoqRlg2SEs42PTJIa7CxYsabfonA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liam Beguin , Peter Rosin , Andy Shevchenko , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.15 045/913] iio: afe: rescale: use s64 for temporary scale calculations Date: Tue, 5 Apr 2022 09:18:27 +0200 Message-Id: <20220405070341.169270034@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Beguin commit 51593106b608ae4247cc8da928813347da16d025 upstream. 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. Fixes: 8b74816b5a9a ("iio: afe: rescale: new driver") Signed-off-by: Liam Beguin Reviewed-by: Peter Rosin Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220108205319.2046348-5-liambeguin@gmail.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/afe/iio-rescale.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -39,7 +39,7 @@ static int rescale_read_raw(struct iio_d int *val, int *val2, long mask) { struct rescale *rescale = iio_priv(indio_dev); - unsigned long long tmp; + s64 tmp; int ret; switch (mask) { @@ -77,10 +77,10 @@ static int rescale_read_raw(struct iio_d *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 ret; default: