Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp558669lqr; Wed, 5 Jun 2024 14:02:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsM7cHqO7ZXCu29t7J2lyq171r1ABeyy+qUwRdTYMDt7pk7qi2zoLU2NvQBMFQ9rR9qUiliUq5wHI04iQiKUxu4Pva7ynRZmlzgJHJPA== X-Google-Smtp-Source: AGHT+IExu3o65XFo8wVU79iKD2g7iarVuDFNg8+n1EpOiiHLpa2JI3vaSdm99ydC5Z12Njs3J8Gm X-Received: by 2002:ac2:5f9a:0:b0:52b:913d:1c62 with SMTP id 2adb3069b0e04-52bab510184mr2666725e87.69.1717621371859; Wed, 05 Jun 2024 14:02:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717621371; cv=pass; d=google.com; s=arc-20160816; b=uznIEP2s7tmT7aSAhCtV0wnLHb6THwGBleJDZcg9+KZyfWOdOMV8/39oaVj/moKMTg 5kS3gBxfViBY46lFv+r2FGVmkIKLiFltmAOMs5b8+DctGi94NmGzJAdLakUqZy4TFX3a H5Tg0PGa8FgEqSL007UkVw2u/SCPEMReuROLhc0whIc51qIdKblXMUjtlHhqwy9l00TG 6JeK8kpSBtmiT+md50jjFjY6XPKFjKGaK4ux2BVJDDDvFIU/J14/MmLaY+APnDSfcFC/ HyEMYGIKk91/r7zE4MWdW1DokhukRk7za616YKSw+C9dAuzr9ksMJ4CCfBZlVieHwykh 8bmQ== 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:message-id:date:subject:cc:to :from; bh=74P5xdyEF7Y/uDbCyNcuFvTTy2khMbPkKOYTbBWDQT8=; fh=vHc97QGXAmiK9uPLuZyEisishOXSY4cCRWEa8qfFhXI=; b=fpOrKp7ZmkR6P58xAQi7OHW+Ccp5ic4Rifit6ydDjHoRd5YqcG52mChyWq+Gm1+dk9 kxEaBVXDUHbr25/4X+stktJo6nftiQ/gu/OH98XT3EAFK6iRsPAQAH8/I0yJ52Wk/ElR lQztVCDCn40XwWAPyI2Nksl7DVpE1pxDHMzQM1NcfY/XYNB2fpDpKEZjb14E9Y/N4YNf +RJuIEvQovkrpifjLwHw6p+r1Wo8vKaAfICp3ALHvTblJKum/kNc6hLjIpMjZJKDPrwJ wIsnvaCVgzIPRRV5r/iYc5GM26QTyfTC1JrhnmEDvn6oCn7lS//Ad1duQFJb1xy3ukcm zOyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-203213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6aa2f6b2a6si97106066b.489.2024.06.05.14.02.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:02:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-203213-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 986A71F2512C for ; Wed, 5 Jun 2024 20:54:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8080415F3FB; Wed, 5 Jun 2024 20:53:21 +0000 (UTC) Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) (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 7794D158862 for ; Wed, 5 Jun 2024 20:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.84 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717620801; cv=none; b=Gkbf+BnAEY5ufK8oym16+GhUvouPpDvJk6cscdXTNwV3pGaImxF9g9iAVBIHEvmmnaoR0g8G2HcBbtPA9ydUxFn+IhontfCgy3R1/jkRvbshpFVN8OBuKBQw8f5kIE15jFPb9f4U+BCEjgkBtNl9BP0KguZqGIZ/lyqg+DpDJlU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717620801; c=relaxed/simple; bh=8eVwxBuuPV0HMr0wLVyfEieEVTEwhmYmsEtJES1P7l8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Joc2JV6YiPXiJsXD5EOvzVFp8UY0gK7rXTqZk5w0bHQwsetwrrUudqdLDNXrzYtD0JS2niuNIWm1myPDowkgQOZWH0YfOpz+dT8NLn/KCV8GO8SjOnSiEXFeQrtrSvNW2imMzgy9Hy7EBg5/HpUvUXbCdbFZhdFVr9EZ33vDMlQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-26-230.elisa-laajakaista.fi [88.113.26.230]) by fgw23.mail.saunalahti.fi (Halon) with ESMTP id a22c60ea-237d-11ef-80de-005056bdfda7; Wed, 05 Jun 2024 23:53:17 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-kernel@vger.kernel.org Cc: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH v1 1/1] regmap: spi: Fix potential off-by-one when calculating reserved size Date: Wed, 5 Jun 2024 23:53:15 +0300 Message-ID: <20240605205315.19132-1-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If we ever meet a hardware that uses weird register bits and padding, we may end up in off-by-one error since x/8 + y/8 might not be equal to (x + y)/8 in some cases. bits pad x/8+y/8 (x+y)/8 4..7 0..3 0 0 // x + y from 4 up to 7 4..7 4..7 0 1 // x + y from 8 up to 11 4..7 8..11 1 1 // x + y from 12 up to 15 8..15 0..7 1 1 // x + y from 8 up to 15 8..15 8..15 2 2 // x + y from 16 up to 23 Fix this by using (x+y)/8. Signed-off-by: Andy Shevchenko --- drivers/base/regmap/regmap-spi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index 094cf2a2ca3c..14b1d88997cb 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c @@ -122,8 +122,7 @@ static const struct regmap_bus *regmap_get_spi_bus(struct spi_device *spi, return ERR_PTR(-ENOMEM); max_msg_size = spi_max_message_size(spi); - reg_reserve_size = config->reg_bits / BITS_PER_BYTE - + config->pad_bits / BITS_PER_BYTE; + reg_reserve_size = (config->reg_bits + config->pad_bits) / BITS_PER_BYTE; if (max_size + reg_reserve_size > max_msg_size) max_size -= reg_reserve_size; -- 2.45.2