From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 862E7395AC6 for ; Mon, 20 Jul 2026 03:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784518375; cv=none; b=UPEXsJIJIIOfzor7NY9TNcb/9b4gM2PQNLyvYuV+wvISjyv3xg4SH4MVxsqO9m/3YRg/ASM5p/2Agr8g0im64+zSTA9k3CCJIa9S/9stAwOQjYvQ6GR2TlhYNMEZV3K/mqZtnxfhUb5OBaw/HRPklcFJE7ivmya3lAB0ki2QTkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784518375; c=relaxed/simple; bh=MMy/vbVfr3B+dLM0u9wadbYLIA0z/pPtdHxj4yVCYK4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=K1Q+sxzi8m4CNHj6ocXSUTEJE1PRvma8xRq09Sat6bfM80hA72HrunIvo+Yi8WY7itoqUW5Whv8PKdC0y/FtMs5jFKB3gV8Mjertz0buDr2RlyO0JHwIBdBm+KtHrowQUcKIW5X/C2Asc6qF2QFvO8qmkSNl5qULgplBXHmLNOE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gI90P0qy; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gI90P0qy" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-8486ac3f347so2673611b3a.1 for ; Sun, 19 Jul 2026 20:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784518373; x=1785123173; 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:content-type; bh=yCrjcYtOPFBhn0Rr/jxmbqZJ8NIIKaPa+hJYbn3tcVw=; b=gI90P0qyXrPtF8ct4+mgBXLPVvMzV/ikuIyZR5jX2TRrLIANK0Xo/AHXDO597hb4Ro MrninxQc14dREOTXT1zd8NVZhM8c449m6+9l9G/9lF+wwjOefcy2XsYx6ZeNgXvjJMEw owxkf7PlTrGpLnXxc87CgcVHIOYDDhZIOUmED1x4FxJhRr37LZHKiGoVHHdykk89aX9M VL0ctrnA7+HsoycUyMVYZFP1Q4c4vI49JWbh0eNEon+6MVq+RiWQhYwqZxCj59Ey504m z2GLwmUYX3eWDBcRwZ2TV5/Qkri58KTvIq7cb+ZuAXJQ5cqdhvOCL0r1KXP3tV2ykVCM z+aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784518373; x=1785123173; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yCrjcYtOPFBhn0Rr/jxmbqZJ8NIIKaPa+hJYbn3tcVw=; b=nZkJcizBbTEAvgMrAM4dW7z5Yu297F4JgFrK13lhGdmRD6z4O8K3xX/ZgR9Xz0U6L8 TgXwmTGRx8PMmI08budGyy0lqDQ+Tl7XYPdLdgqgIXEqgD49IYXJXb4GWFGX43ODHwux PM8G9qDP8Xia1lX1Mw4SM2kayPG6qkBLC5WZNHSuXyklC0EqtU0fWuJXoUmlOXqzbWuJ eOW3jbfdrJpbiRp7YC8PqYDYWaO7X/oMovpRhnzZRR0XKzHYxZjjtQbHzj5hjp6Y0Zau cBD3WFWemPCrW5YkUfjUL47nvtr/TNmcpb1CZOPIsWUktTohlt2cTFeYn3hDm3Y3VJy+ a9Zw== X-Forwarded-Encrypted: i=1; AHgh+RoIDMjLPjZOXb2Q/n32JvDq9zcbrYfuPFOqBylE1jvb9eSo5V+Eg3Ws6IBkvHl3Iq34oP164pEGo38kWGY=@vger.kernel.org X-Gm-Message-State: AOJu0YxinK/0g4XTgaxZDfwEFP3c2Gkon5EPsh8xWmPtE5miAL2Cclej /jkuGhcUiO3muK9QJ6UdVDrSjoissWng5xn0f+BdIGQEZwuSz3qPwq+KkGYDOw== X-Gm-Gg: AfdE7cno0mHe5FNLmmmTN5vYv6419n+MjfYPM9BQhjAKI5urmvZvpHBGrmAKdsCoPiq X+8OigIzcFV0KkPMaN+w2UVDHEfd3sfYCc6IZ+Xglo8etwppMlTPvjiXlTqXcPaQeN4350032cr dVv2vnNlfPo6loxtzQb1t6cj6slGqiUX/F7YiEb0Dyg1ATORkS5WbyTZz4F7DxIdwT+LyI2j0uY 1jFDgqNYn5rehtmgW7clzMJCOaI3zjHilw5SAbEAYrSaUUDzyRBLqE2GdmRnk1mwo42bncEPB8A g0jCjXO9G9GrDf6XaSEnKaH74WjheSHC2PDnQgtfVfT4tGHATkTmQE/3xNoPGgnMdDRGPQSySnm RrtSGO3LJMjE8pNbCUhrpSlvdq4QxipsSjFX/SuIUrw7S/KuD1+07TAthxm3+LrjgKsQnCkX2QH AMubH1qSj6pOkJOj4gang7mkfiFoc+bVxMgwai X-Received: by 2002:a05:6a00:a91:b0:84a:29af:a0eb with SMTP id d2e1a72fcca58-84c285874dcmr11327626b3a.9.1784518372637; Sun, 19 Jul 2026 20:32:52 -0700 (PDT) Received: from phuc-desktop.. ([183.91.15.56]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84c2af6e9a3sm4811729b3a.41.2026.07.19.20.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 20:32:52 -0700 (PDT) From: phucduc.bui@gmail.com To: Mark Brown , Greg Kroah-Hartman , rafael@kernel.org Cc: Danilo Krummrich , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, bui duc phuc Subject: [PATCH v2 1/2] regcache: Warn if regcache_sync() is called in cache_only mode Date: Mon, 20 Jul 2026 10:32:37 +0700 Message-ID: <20260720033238.52479-1-phucduc.bui@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: bui duc phuc Calling regcache_sync() while cache_only is enabled is invalid API usage, since writes are intentionally kept in the cache and cannot be synchronized to hardware. Document that callers must disable cache_only before calling regcache_sync(), and reject incorrect usage with a WARN_ON() and -EINVAL. Signed-off-by: bui duc phuc --- Changes in v2 : - Check cache_only under the lock. - Update the function comment. drivers/base/regmap/regcache.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 96cdae25b9c4..20e0641d21b2 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -397,6 +397,10 @@ static int rbtree_all(const void *key, const struct rb_node *node) * volatile. In general drivers can choose not to use the provided * syncing functionality if they so require. * + * This pushes cached changes made while cache_only (e.g. suspend) down + * to hardware. The caller must disable cache_only before calling this + * function. + * * Return a negative value on failure, 0 on success. */ int regcache_sync(struct regmap *map) @@ -414,6 +418,12 @@ int regcache_sync(struct regmap *map) BUG_ON(!map->cache_ops); map->lock(map->lock_arg); + + if (WARN_ON(map->cache_only)) { + map->unlock(map->lock_arg); + return -EINVAL; + } + /* Remember the initial bypass state */ bypass = map->cache_bypass; dev_dbg(map->dev, "Syncing %s cache\n", -- 2.43.0