From nobody Sun Feb 8 06:54:46 2026 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 CB881AD5C for ; Wed, 13 Mar 2024 08:47:13 +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=1710319633; cv=none; b=SyAeoGiUkYzOMZFWdhwdop9nuJV+6B8ropHa4I/E/Cu9cEgL5cLk8y+09NxnHgKCi9fyxfcS8K1WFWgUBJHnG65D4/KcqnL/hqIBfqdg9BmUYnnpX6HuTqPml9RAhTvNsnO/oHtGrORJu0hR67wXZgk710iHsmv0gum/oy/OhCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710319633; c=relaxed/simple; bh=yakn8DcYyX6FHUb9D/6Aegg8RoUb6WoaYCsMozwxIKw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lVIDcKQMtcIQycVY9xymrrjKQoJYuJybGvbOzvB/raK4dcHAWCOKGJeh/xr+NCf1z2mF4ZM2pMALaeZGDSxx/cF4M0iuLwWtuvi0Qvg5vHNrkfrM6d9+7lPSPHygWmjdAFRETweWEyFMY2k/jhmNeFY4gqsxbTtEjkxVwNVuN40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zy4eA+ZO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zy4eA+ZO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A3BEC433C7; Wed, 13 Mar 2024 08:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710319633; bh=yakn8DcYyX6FHUb9D/6Aegg8RoUb6WoaYCsMozwxIKw=; h=From:To:Cc:Subject:Date:From; b=Zy4eA+ZOxcbi0qOUZY7hjDjyCYobz5eb5R0q4k/kV9pzxxDR6bhSb0CHxMMB4bbY8 Abm7lYB8ciTbbMqd0TxHS5cTej35LSdDsvBGTRtIG7gK97XiWxE4Ic6DKv+yxvLHed 0gkV/OJr/KOQld5dmGNwO40uY1e6BrCRCkq7FugPr2T58SK7hNH7k5cm63BsfC9UqE EaoQHWs4dHszp+yioksWs3p3TjUkLG5XNxj2sRCC+59QO2eRK0PyrbP0SZPEGzxbCl hRqnsXCctrInJvM3UxF8cmnL354M+9H9UQfJHcl7wNgvJTxMMk5aiKKrpEuNw8IW9C Wdo4RA9WPWQfQ== From: Arnd Bergmann To: Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Daniel Golle , Zhihao Cheng Cc: Arnd Bergmann , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] mtd: ubi: avoid expensive do_div() on 32-bit machines Date: Wed, 13 Mar 2024 09:46:52 +0100 Message-Id: <20240313084707.3292300-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnd Bergmann The use of do_div() in ubi_nvmem_reg_read() makes calling it on 32-bit machines rather expensive. Since the 'from' variable is known to be a 32-bit quantity, it is clearly never needed and can be optimized into a regular division operation. Fixes: b8a77b9a5f9c ("mtd: ubi: fix NVMEM over UBI volumes on 32-bit system= s") Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes") Signed-off-by: Arnd Bergmann Reviewed-by: Zhihao Cheng --- drivers/mtd/ubi/nvmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c index 8aeb9c428e51..a94a1a9aaec1 100644 --- a/drivers/mtd/ubi/nvmem.c +++ b/drivers/mtd/ubi/nvmem.c @@ -6,7 +6,6 @@ /* UBI NVMEM provider */ #include "ubi.h" #include -#include =20 /* List of all NVMEM devices */ static LIST_HEAD(nvmem_devices); @@ -27,14 +26,15 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int = from, struct ubi_nvmem *unv =3D priv; struct ubi_volume_desc *desc; uint32_t offs; - uint64_t lnum =3D from; + uint32_t lnum; int err =3D 0; =20 desc =3D ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY); if (IS_ERR(desc)) return PTR_ERR(desc); =20 - offs =3D do_div(lnum, unv->usable_leb_size); + offs =3D from % unv->usable_leb_size; + lnum =3D from / unv->usable_leb_size; while (bytes_left) { to_read =3D unv->usable_leb_size - offs; =20 --=20 2.39.2