Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2401033lqp; Sun, 24 Mar 2024 17:57:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX0oXyzeufm5NnAbKL0gGd0Ok/v8Je/xvWvnIHM96WajhrjNG9wmvJXFHxFBj7mQH0xpSUcryh6oF0G++A/CJFUIbK+SC1whK3+vUkmeg== X-Google-Smtp-Source: AGHT+IEfGQJaFDHTQGyerOmSY11QtIWjbqTX+JMQrPSuY+i3jwAYR5jH/TjbU4/PusJ29l+krUDp X-Received: by 2002:a17:90b:695:b0:29b:b248:18a6 with SMTP id m21-20020a17090b069500b0029bb24818a6mr4011038pjz.31.1711328235487; Sun, 24 Mar 2024 17:57:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328235; cv=pass; d=google.com; s=arc-20160816; b=PaUKxDEIEjpZeyCuXt9Dv6bJsmivE08VcVAFNJJ7iK/ZbtMEkWO8jA93+1wfYFmGP0 rbxY9dcENJE02WYGEHmMqh8MjC7VHKSXNJYO+/5GsjRy8MRBAeMY4NDBE8b027aLLihi sM0DPC0erUcLnFBYrRVQ1bGPDFcK0tj0QcE+rgtRE4hymJz+O3gZH0OUQPOcY1yHi/3C Im5RpVcqmAF35qVEFUcBQYRkUXvhj+/9FwMdD74K3Jp2HVU/ygQZ1oW5pvKQNFqwXGfz zFumr+7BnqlS/J+/m1uSkl7HGlJd/xnSgwDqfAp7ggktI/S1WSpumrAi6cyT5qzsiyRa mFPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lUTbZFO130R9z+xDLV6c4JAICW8HPV+1TNMvp9rdznc=; fh=LnwZRgQeaUxrkw01P1WUzagoTrs/7781l6iBpdLSGMs=; b=epdrWg3MfcUSVCASMri7WBnjF7p4Szjs9qysBt9uVNJS1HuGYBqqWFhWdR3STBv+r9 gO6ayTHDU501Kqb2k6zjfjH4Gs8s0rsqtTnwa9HENl6nAMS6EJVVQbrP5/s0nc28osmH MX+I2IlFRICb4kezFxLUMn5hwrIMzo4NyG/kUC5IxmOde4d4HDlu3T9zZClki3scTkNH /XdoYmY9vWbsjbd+LTHDsbi7zuYMvoaPRFWxjwstdr9zJvIn3I+AqtcunJznEY0bGaLD QXrszyRAfEHia0L1I0Uypu2wb568SFtfPtIiGO/qViK8M3AkM07ymHrdFJte+UfYedZf DyzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MtJSih5G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d6-20020a17090ab30600b0029ff777c440si10366817pjr.7.2024.03.24.17.57.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MtJSih5G; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113515-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 91173284DA7 for ; Mon, 25 Mar 2024 00:54:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 781B81BD03D; Sun, 24 Mar 2024 22:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MtJSih5G" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88A181BB74B; Sun, 24 Mar 2024 22:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320316; cv=none; b=cPA0cxPJkGYUqyrI+vayvSdlKfUxE1Wj4BNhmezGqn+JyUbz2oFZ60Xpv5m+uwc0zM+wVCDYvslSZn8dUH4ZRhoYkL6WUbp081/z5ncyyE56x+RiDZTvwAarSxGwV+7zQsJbAL2vpacdwAs4OGKaCJaRDkbFMwMkru2lyDaQGOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320316; c=relaxed/simple; bh=pRFSzQtLhCFk2XS/KpLm33y704/cqDGYsr0aJwn7PQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ol7GEoGHvXm/ekgNhZbv6ygBhgTfLh1vxeAh7cp1pR5WMN0Pqx0HE+OsS3Rj+M3FSMplWsDLajZdoHbxey03NQsPqaMbHdx/mg7GVwe7W28TgsXB1gpiNQdCj3p5sQNrhZbn16e9DbbZkHDM8tTf7JNYvtQdNZ9FvQCOvFfqCQ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MtJSih5G; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67C1FC433A6; Sun, 24 Mar 2024 22:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320316; bh=pRFSzQtLhCFk2XS/KpLm33y704/cqDGYsr0aJwn7PQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MtJSih5Ge5smdn+mHDm3Z+od0QQ9mYLSHK9Qf958nkOe5HCU9E0n9Dvjn1ow21Bjp AkVYV++2zzytSPZ03aCnHgV2wlDT5CP7xS4haEFBuhF8KcXYHWQQJwg6o3SDWfVoEu DlQy5DC8B250yO42D1Pgz5RPQJmc7BJ0XdQbvZM6EvNnDEFUCD63yy0TcAaSuaYblB f0DuEgX0/DZNkmBuaoSAq0BltpzyaX55ihiqPLVSKdbmSDgXVp6rKFGbeVWEfBBZ7K nHc3o30+8nms9dyom3bZXCltWj8BpVLciQgNVcPVCfaFLdkOPy8/uUYQkxGNcJzt01 0MTbEQM3T6Pzw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Matti Vaittinen , Subhajit Ghosh , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.8 624/715] iio: gts-helper: Fix division loop Date: Sun, 24 Mar 2024 18:33:23 -0400 Message-ID: <20240324223455.1342824-625-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Matti Vaittinen [ Upstream commit bb76cc45dcdfcd962a5994b8fe19ab74fc6c3c3a ] The loop based 64bit division may run for a long time when dividend is a lot bigger than the divider. Replace the division loop by the div64_u64() which implementation may be significantly faster. Tested-by: Subhajit Ghosh Signed-off-by: Matti Vaittinen Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") Link: https://lore.kernel.org/r/Zcn-6e-0-nh2WcfU@drtxq0yyyyyyyyyyyyyby-3.rev.dnainternet.fi Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/industrialio-gts-helper.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 7653261d2dc2b..b51eb6cb766f3 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -34,24 +34,11 @@ static int iio_gts_get_gain(const u64 max, const u64 scale) { u64 full = max; - int tmp = 1; if (scale > full || !scale) return -EINVAL; - if (U64_MAX - full < scale) { - /* Risk of overflow */ - if (full - scale < scale) - return 1; - - full -= scale; - tmp++; - } - - while (full > scale * (u64)tmp) - tmp++; - - return tmp; + return div64_u64(full, scale); } /** -- 2.43.0