Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1121191rdb; Fri, 16 Feb 2024 06:08:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUaI4CRQuYxx+mw3moiA47AB+A+Hna1MbsqRN3ftZPmY0svcjalC++MqGY2X/Sb/VCchVxVQgfsWZwiCfDvcHb9yhhNJoXktr5Bfgv3HA== X-Google-Smtp-Source: AGHT+IGd4tFl1rHlJvDWxfg9lTYtif8uBcs3rgKigQ7qjvcpYufJ2B+Fk+2vgt8T82Z+NsLygZl3 X-Received: by 2002:a05:6a20:b7aa:b0:19e:c777:5c60 with SMTP id fh42-20020a056a20b7aa00b0019ec7775c60mr3768667pzb.21.1708092481140; Fri, 16 Feb 2024 06:08:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708092481; cv=pass; d=google.com; s=arc-20160816; b=SrVSQkpRP6JGPomdEGf08Hi4MdmkXZjAPjZVklyuiWyWj2IgtsZcEVrCyj+BAOhKbs 8yoepd+XiwWHEMFG3wn9n8eDMxkVSmJ3LwelxltbMy5S5UnxB7FcAA4JxU1DXZdDvvr5 UTci1Zq0/1ojv1pK+nu5OKmwxKkRlTl+lq5eEqWo0/kK8q4i0U7+069K3/AOojuNdMmO gkK1zZqtqk7fgCqIVtlFTLAMqmuh9DrSIx4bzjh3FHw+4VtX9vjRBdeW9b2NXHqG1aip hUrOJjNsVewjIoZqd+4NMuq4NlfoO1ZDm2nwCZd+YOB8aEuBxANTObcAZIx6QJF0oIyk XA+A== 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 :subject:cc:to:from:date:dkim-signature; bh=I+VVUSuJOM5XAhNfDvnkCADWBl///T9nUHRJqPSqsrc=; fh=2gavsaVXxsTEYzi3w13mpVQG92fhnopbxvBwXJ5+rac=; b=aYk/fap3xdu2e+RQ35VUHIeXB0aIO0MtHqT3zbTWgvavB9W5KZguVap94xuWg9MpFk fXAp75drllPA6dhgOYim0XHk1WL77Ce+eDkRHeRh2I4TR/p8k+XezoiWwvVgstYC9GLO v9ASMPwii1aRnijlJJ5w+z8qxvKnn6ocPrejbzipMUEM9N1vXd7JyIJlLf9dW7K+vszX k+gR2AzaN32LhIkHjK01AAjZX8nmLS6zZ+GJHPekcIXdFU05jQ3nTG/4KEd8uAoGvbZC LwUNqySBM6Ua+vMxG0mJthzg2/DVZ8/pgg4AkeuQLeIgWr/Z6yUPoK3GnHuxF7dVyEZM YOwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OK6FDq9M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68678-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o19-20020a637313000000b005dc4912432csi3115807pgc.577.2024.02.16.06.08.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 06:08:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68678-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OK6FDq9M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-68678-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68678-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C8CA5B261D2 for ; Fri, 16 Feb 2024 13:58:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B1AE12C53D; Fri, 16 Feb 2024 13:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OK6FDq9M" 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 4F21812BEA5; Fri, 16 Feb 2024 13:58:24 +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=1708091905; cv=none; b=IzYjzDZqxZPm+phJlXWJtMDAp6scWcxFqJ70jKHt7riSjFvWlHTwMthmzqSOMhr5Rzu+C6MAoYE2c8IhWc24jIYWewxCNz2xF54FY9QIPbE5mtoQlOs1V1LCLaipS2YapD5GJw14ZXncLe+kDK+4cvy+Nu+MpqTu0Ddjv+8c6P8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708091905; c=relaxed/simple; bh=CB4g2cCQgiWIC67i2T4tPOsa8k0vlzMP7TVNg5Oz1j0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UsETvJAPxoGYsb+SGcE+B70gYejNl6vZ8/cKZ72hQItyaGN87wbBB0NsqNXECVQKFXDy3ql3iPq75LcMWenRPbTkfMvH1NnkOmokIfcnPKo/Ca+99neRxmp/x7xVSAHVb0c8aN0byDHOIxYVnfnkf6bucUClBcQ5y5fGnzwszwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OK6FDq9M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 059D3C43390; Fri, 16 Feb 2024 13:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708091904; bh=CB4g2cCQgiWIC67i2T4tPOsa8k0vlzMP7TVNg5Oz1j0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OK6FDq9MAY2HkAu8eJYLHeP1oEYKKgwKmwlZtUdkddD5wg3cTXrlDcJ7Vc5NknZkL 0WNZbEyZORYkCs15IgQz0jJtCsevneOIyksZzepmPHoA1MUo3XafKc9RmWAL/ORHJJ qBoUfRJF3/iyO+hpqSEcJ4STBX6RFDCeGtdzBsVW5rCNQbbufyepzcG4BbiWNfj1TC WV8lYFOy02aHz7IsofjHhYfs/8+6LHLDvYw4YavFgcr0MnnUWwzzRofcGUsHRsXt8Q sih2MhPmf/LtBnYITHTWTGIIt3RESfARRtWd0mDGqq66oB9aCdaMMJikhTO/PWhtq/ W/c89UIesdFcw== Date: Fri, 16 Feb 2024 13:58:12 +0000 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , linux-kernel@vger.kernel.org, David Laight , Subhajit Ghosh , linux-iio@vger.kernel.org Subject: Re: [RESEND PATCH v2] iio: gts-helper: Fix division loop Message-ID: <20240216135812.07c9b769@jic23-huawei> In-Reply-To: References: X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 12 Feb 2024 13:20:09 +0200 Matti Vaittinen wrote: > 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. > > Signed-off-by: Matti Vaittinen > Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers") > > --- > This is a resend. Only change is the base which is now the v6.8-rc4 and > not the v6.8-rc1 Given I'm not rushing this in, it is going via my togreg tree, so the rebase wasn't really helpful (thankfully didn't stop it applying). Would have been fine to send a ping response to the first posting of it. I was leaving some time for David or Subhajit to have time to take another look, but guess they are either happy with this or busy. Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons. Jonathan > > This change was earlier applied and reverted as it confusingly lacked of > the removal of the overflow check (which is only needed when we do > looping "while (full > scale * (u64)tmp)". As this loop got removed, the > check got also obsolete and leaving it to the code caused some > confusion. > > So, I marked this as a v2, where v1 is the reverted change discussed > here: > https://lore.kernel.org/linux-iio/ZZZ7pJBGkTdFFqiY@dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi/ > > Revision history: > v1 => v2: > - Drop the obsolete overflow check > - Rebased on top of the v6.8-rc4 > > iio: gts: loop fix fix > --- > 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 7653261d2dc2..b51eb6cb766f 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); > } > > /** > > base-commit: 841c35169323cd833294798e58b9bf63fa4fa1de