From patchwork Wed Nov 1 14:29:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Wolsieffer X-Patchwork-Id: 160563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp463107vqx; Wed, 1 Nov 2023 07:31:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZWr/6OPYqqAaIceXebH5qKdxS5Ggw7k81ouR2rbbTby38Xj8x8XY4THKn0XEZjqoHmScL X-Received: by 2002:a05:6870:5cc6:b0:1e9:a248:b1b6 with SMTP id et6-20020a0568705cc600b001e9a248b1b6mr18674449oab.35.1698849062112; Wed, 01 Nov 2023 07:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698849062; cv=none; d=google.com; s=arc-20160816; b=oIVn6qRtVV75CYoCO/h6XUPdoozGNiGA8yK5d4GKC7YNVJ5P8OhZxjAw5jkx2l++eJ TMj6jn+hMHjOdPu12+hTYFbp6ewlyTKQXwQGXt57EO7IUCdyaSOOvWVVDCz16PZyuKE+ uXpBIcqJF3xf6SsSthwREeT5b0IkdkbqoCnVfEBFULKe4f3wKSMQII1QT8LbdQxsoyhB hMnVJ3oJOqT6xO/oJ/CngfYOPL5Os5eJjTlqadut8M8lo7EbP6/5uIp8rByeZbhVE8Zo QeVdVw4xIVwJ+ohXkgy9TdGppxKc9D2fBcMuFuVHCsnbYr9kk+whdMl4KUdk6AokWQgP keVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; fh=1rc1XUp1bKzRa92nYuSAN+4xSCYORHajs8tJsNPKYuQ=; b=sN143+BWptGK41PjB6nQSDq4HVk/cS/GEYfFwKm9jWMr4nFoAiccF8pWDsO7GC9rBt O6/AR78eKN2uAbiVF5CqBolJlBiVTF3FxqGtb2zK9QaKz/blWeJnqY4X+cwwuiL755ni OJqzkfkGn4PUAB46Qh9KpYwbBje6diw/yb1N4FjHnHR5BEAto81FY/HZvpC0auy+sxa8 tcTgKBwtcLxQiHn9H60vi4BA0oqXc9lqKIIv3ru9dLqA0ZBanjTLDAbOjxay7wE8Catj YtNQjovfK6My50Zh77pZapnbYcfduOPSLKLVxR7pRkoWVQOI6+1QwfzHlUla6PxhPyE1 TlGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b="G6Sd+dz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s17-20020a632c11000000b005b2d044af30si3055267pgs.480.2023.11.01.07.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:31:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b="G6Sd+dz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4A76A807D3CF; Wed, 1 Nov 2023 07:30:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344339AbjKAOaU (ORCPT + 35 others); Wed, 1 Nov 2023 10:30:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjKAOaT (ORCPT ); Wed, 1 Nov 2023 10:30:19 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06FEDDE for ; Wed, 1 Nov 2023 07:30:14 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3b2f507c03cso3651558b6e.2 for ; Wed, 01 Nov 2023 07:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1698849012; x=1699453812; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; b=G6Sd+dz/ZQVylr954A0qtLFViRQP65xD5rDFu05glJAMZ/q4OYpVDevRDtrzWj06Xq fd275cqaz911SZsp+UYWoF+m/OcmxhNseVRwyi+C+QCxcoAwazY5wggydCQbUbD9LdnH 696KcqJvT2TGhNnQcaXlvfr0CG+jWTK/OVK/9Au1BCddI5usVY9mhvup2E+J5nP/LcKF lxYUlwSyM9obdmyLkSRGS2ex38+SaDiew0z107dPpJ0aWg9QjvLLlY+KcZVYdwdJ5SF8 mliKxjxqDD5nGGXKy31k9jzPawbldu+2gNi3DGlFyWRa2GYLVzQ7xgWiHW+mwJVhyfql D9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698849012; x=1699453812; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; b=r7P0dgj8Wnob3pIgaiv54yIgeLBCepY6wKeTx3xN6uQ/po/uGa8rvkoAfnPagLAQ7p KKVvwcWOw6t6GRKzTvgtONmobsE3ZrViE5jIxx5DQciXM11uJ9yiUnnygsrM8zHwwSo7 MEmMYxhcR86BiQo2S0LTp6l6hN8H2SIdutobRYoWYcbZAEGliSwUhLbVagWjH83HjZAD UEdWll+1n4YSgqA6hW/lZPjuwMPRsNJfwNpdJtjuVQU5f4wfF1w5tgSAztB8odSOd7c/ z0dAGBmFoaWYe5VL/ArnBYP8wpCtLrLulP01YizYoTegYI+z1z4QaC3OG3v9+yVY8hUw kIvg== X-Gm-Message-State: AOJu0YzeFN7On/+0AtcI52Qb0lFaDuY0gXo6gGzZN233s2CKfhnECCUf Cmvs1rcmpUXvsM1Is9nNpYAIHK1ygkYT3b3wu1s= X-Received: by 2002:aca:d10:0:b0:3ae:5c09:73ce with SMTP id 16-20020aca0d10000000b003ae5c0973cemr16363378oin.23.1698849012477; Wed, 01 Nov 2023 07:30:12 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id x11-20020a05620a14ab00b0076f058f5834sm1469260qkj.61.2023.11.01.07.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:30:11 -0700 (PDT) From: Ben Wolsieffer To: linux-kernel@vger.kernel.org Cc: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Ben Whitten , Ben Wolsieffer Subject: [PATCH] regmap: prevent noinc writes from clobbering cache Date: Wed, 1 Nov 2023 10:29:27 -0400 Message-ID: <20231101142926.2722603-2-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 01 Nov 2023 07:30:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781372353952071122 X-GMAIL-MSGID: 1781372353952071122 Currently, noinc writes are cached as if they were standard incrementing writes, overwriting unrelated register values in the cache. Instead, we want to cache the last value written to the register, as is done in the accelerated noinc handler (regmap_noinc_readwrite). Fixes: cdf6b11daa77 ("regmap: Add regmap_noinc_write API") Signed-off-by: Ben Wolsieffer --- drivers/base/regmap/regmap.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 234a84ecde8b..ea6157747199 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1620,17 +1620,19 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, } if (!map->cache_bypass && map->format.parse_val) { - unsigned int ival; + unsigned int ival, offset; int val_bytes = map->format.val_bytes; - for (i = 0; i < val_len / val_bytes; i++) { - ival = map->format.parse_val(val + (i * val_bytes)); - ret = regcache_write(map, - reg + regmap_get_offset(map, i), - ival); + + /* Cache the last written value for noinc writes */ + i = noinc ? val_len - val_bytes : 0; + for (; i < val_len; i += val_bytes) { + ival = map->format.parse_val(val + i); + offset = noinc ? 0 : regmap_get_offset(map, i / val_bytes); + ret = regcache_write(map, reg + offset, ival); if (ret) { dev_err(map->dev, "Error in caching of register: %x ret: %d\n", - reg + regmap_get_offset(map, i), ret); + reg + offset, ret); return ret; } }