From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B00D1EB64DB for ; Thu, 15 Jun 2023 11:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344289AbjFOLlb (ORCPT ); Thu, 15 Jun 2023 07:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344121AbjFOLka (ORCPT ); Thu, 15 Jun 2023 07:40:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2042E30DB; Thu, 15 Jun 2023 04:38:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 008156397A; Thu, 15 Jun 2023 11:38:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACA4EC433C0; Thu, 15 Jun 2023 11:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686829137; bh=fUtNKqyMngEHM5/vMKaW5HuXnP15G89bWJgenDilklU=; h=From:To:Cc:Subject:Date:From; b=otIzIKybUTSEwouGYeGkAEenBSqYhXBoQtE7QeA9iKL1F7ED5R70w5nWa1eHp3pNT qzyUrfeDkoEK0mTbglxFXKoxHO4zavxtGeRl6jWdd56intzABLHQjT4mUJBtA/bvWB UlE8M2xZEd99SrgRi9NUun2JDDltxln+3jUY+cCWTLgLsG2qB3bI230XLsK2Rf3G4h k/EvP7mwx3AisvT4yAvC1gAZhPl6WzOkgOj3Mts1eujfPndVjqfP1A6BpDg7O7EcN4 da7BQJSdxpm64QdioB3b6eDRefqn+9scWpicJT5gtvh9V8GfwxCrJQl4ma7Hkt+8zI vFjLpARdWFxfA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jim Wylder , Sasha Levin , broonie@kernel.org, gregkh@linuxfoundation.org Subject: [PATCH AUTOSEL 5.15 01/10] regmap: Account for register length when chunking Date: Thu, 15 Jun 2023 07:38:45 -0400 Message-Id: <20230615113854.649370-1-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.117 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jim Wylder [ Upstream commit 3981514180c987a79ea98f0ae06a7cbf58a9ac0f ] Currently, when regmap_raw_write() splits the data, it uses the max_raw_write value defined for the bus. For any bus that includes the target register address in the max_raw_write value, the chunked transmission will always exceed the maximum transmission length. To avoid this problem, subtract the length of the register and the padding from the maximum transmission. Signed-off-by: Jim Wylder --- drivers/base/regmap/regmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index f7811641ed5ae..05410c69a3da6 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2041,6 +2041,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, size_t val_count = val_len / val_bytes; size_t chunk_count, chunk_bytes; size_t chunk_regs = val_count; + size_t max_data = map->max_raw_write - map->format.reg_bytes - + map->format.pad_bytes; int ret, i; if (!val_count) @@ -2048,8 +2050,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, if (map->use_single_write) chunk_regs = 1; - else if (map->max_raw_write && val_len > map->max_raw_write) - chunk_regs = map->max_raw_write / val_bytes; + else if (map->max_raw_write && val_len > max_data) + chunk_regs = max_data / val_bytes; chunk_count = val_count / chunk_regs; chunk_bytes = chunk_regs * val_bytes; -- 2.39.2