From nobody Mon Feb 9 05:58:51 2026 Received: from polaris.svanheule.net (polaris.svanheule.net [84.16.241.116]) (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 B36C92D0C97 for ; Wed, 22 Oct 2025 20:04:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.241.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761163499; cv=none; b=OEd+p/LK/ONFvIt3qAdX+frgwmZuU67tvfcLtxWhxWv/eiY926gzOdKfjKc1dJs3QnFcYxg0pRqpPHWPAkI2U13yLwhYWn8W2J2Sd8jfcrWzgZ7S11YlxxQzG2TJchq1pEDNTamKQfN1gUwpCrwPwUrfGdPO1+g1uJ9b7E9/PX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761163499; c=relaxed/simple; bh=pKHq4tL/vSPCuT4H2cv/OCDdlZ8gLd53YfR8eqd9WNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eq3isBHF6p5SuzAIU06XwFmDF+N4Se8LjS4hNgYbL2Y/qaqUJcxZ/0qdl6Gx447hOpWxUWDm+oPkp8/GMILrlYm6Old7czTjxGndI/oOkxVjcdR3apirJLl02380cKRrN1S+HzFgBxqWtjytYOUQAlagy6REOkzBJaabDHDFNBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=svanheule.net; spf=pass smtp.mailfrom=svanheule.net; dkim=pass (2048-bit key) header.d=svanheule.net header.i=@svanheule.net header.b=t5Rkj8cm; arc=none smtp.client-ip=84.16.241.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=svanheule.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=svanheule.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=svanheule.net header.i=@svanheule.net header.b="t5Rkj8cm" Received: from terra.vega.svanheule.net (2a02-1812-162c-8f00-1e2d-b404-3319-eba8.ip6.access.telenet.be [IPv6:2a02:1812:162c:8f00:1e2d:b404:3319:eba8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id BB21D68B9A1; Wed, 22 Oct 2025 22:04:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1761163489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sOjs6gmHYhxAucDQWaCaiSvU+FT5q72t/PAw72NC2IY=; b=t5Rkj8cmzSccGreeVgIpstkrRV8lW/XZvqkKkzBzCu13W3hpT0u80n5vmfoaMEKdNeEmPg vHbB1goEpXdYZO3QgLqeOuxoKrlJ+SbYM0324sb7eRVNY2zO9CHjCyN0rM6sc3zy5CUoRw 0H9Y2LNA1rn2su2E+j7oxzKB1gQ1GiWtMp54d3zP4R/Nux4GYXZlobDkKeCrRxbX8bpR14 S3NYSnTQqM9aFeanhAuHKvO42QO15fHyb3fyRSSRUS25SsGUwHM63VBGSo8s4kvT+2+Ulb 91O9Oth/wA2AE1y5qaEIHf2Pzjj4LF932WQDhuUftr/qkfZiThpTvnvL5F34kg== From: Sander Vanheule To: Mark Brown , linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Danilo Krummrich , Sander Vanheule Subject: [PATCH v4 2/2] regmap: warn users about uninitialized flat cache Date: Wed, 22 Oct 2025 22:04:08 +0200 Message-ID: <20251022200408.63027-3-sander@svanheule.net> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022200408.63027-1-sander@svanheule.net> References: <20251022200408.63027-1-sander@svanheule.net> 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" The standard flat cache did not contain any validity info, so the cache was always considered to be entirely valid. Multiple mechanisms exist to initialize the cache on regmap init (defaults, raw defaults, HW init), but not all drivers are using one of these. As a result, their implementation might currently depend on the zero-initialized cache or contain other workarounds. When reading an uninitialized value from the flat cache, warn the user, but maintain the current behavior. This will allow developers to switch to a sparse (flat) cache independently. Signed-off-by: Sander Vanheule --- I've decided to use dev_warn() with __test_and_set_bit() to avoid log flooding from e.g. regmap_update_bits() deciding not to write an updated value. This way the warning is only issued once per invalid register, which will hopefully be a bit more obvious than a single log entry from a dev_warn_once(). Changes since v3: - New patch: emit a warning for the flat cache on suspicious registers --- drivers/base/regmap/regcache-flat.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regc= ache-flat.c index 52ce125a74e1..8802713e0cc6 100644 --- a/drivers/base/regmap/regcache-flat.c +++ b/drivers/base/regmap/regcache-flat.c @@ -90,18 +90,13 @@ static int regcache_flat_read(struct regmap *map, struct regcache_flat_data *cache =3D map->cache; unsigned int index =3D regcache_flat_get_index(map, reg); =20 - *value =3D cache->data[index]; - - return 0; -} - -static int regcache_flat_write(struct regmap *map, unsigned int reg, - unsigned int value) -{ - struct regcache_flat_data *cache =3D map->cache; - unsigned int index =3D regcache_flat_get_index(map, reg); + /* legacy behavior: ignore validity, but warn the user once per reg */ + if (unlikely(!__test_and_set_bit(index, cache->valid))) + dev_warn(map->dev, + "using zero-initialized flat cache, " + "this may cause unexpected behavior"); =20 - cache->data[index] =3D value; + *value =3D cache->data[index]; =20 return 0; } @@ -120,7 +115,7 @@ static int regcache_flat_sparse_read(struct regmap *map, return 0; } =20 -static int regcache_flat_sparse_write(struct regmap *map, unsigned int reg, +static int regcache_flat_write(struct regmap *map, unsigned int reg, unsigned int value) { struct regcache_flat_data *cache =3D map->cache; @@ -159,6 +154,6 @@ struct regcache_ops regcache_flat_sparse_ops =3D { .init =3D regcache_flat_init, .exit =3D regcache_flat_exit, .read =3D regcache_flat_sparse_read, - .write =3D regcache_flat_sparse_write, + .write =3D regcache_flat_write, .drop =3D regcache_flat_drop, }; --=20 2.51.0