From nobody Thu Apr 16 02:01:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 B5E1C388E79 for ; Tue, 3 Mar 2026 09:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530107; cv=none; b=lUewfTQlJtgfzHV4q7xcxJpSpJKjVsMMbVG1TjR7T0EaQYoLSvY09gsA+tBgFA3Iz83x8D2oynT7kBfWfsMFnQsvxsqpiPxod/wzZU4EGdzsYfzB6vBlkHqT4gLb6n+dO7lAslgYq/B+rzv7Qjt89fNnIBs0Xb3V/3rKiegQSnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530107; c=relaxed/simple; bh=yE91OKGLs2uTQUKjWEljRwzeF7bgU+XX9O7nDFSUduc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lULtBiPZETBBj67CAJY3ocQcY6EXN6riCbpVlRTLVI83cpJkz+1To9hY0PES8KuZ6HaOClw99xUrLIN4M25Ql2FkfWQAtLQgWd6KhWYzlbasnbmEMACXNfpBxvXRphDn723Kl2vbP7lKjf04+hJG35rzFrt675HAkoU1Q07TBjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AskOa+lW; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AskOa+lW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772530105; x=1804066105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yE91OKGLs2uTQUKjWEljRwzeF7bgU+XX9O7nDFSUduc=; b=AskOa+lWqdRZvMjpud/zyMSvPLdOH0j1LTV+MyxErfmriJX4UGXL1vLU V9zWhTsHr3qWJzDR88u8w1AnmzJF03QSDlJta9KDCRnLeNAhjBdnTG709 W4s3tFLvulA0IJgdXjPa7jgc6C3AoxdnIQFPrucEk5UYtYvH0dYNhnn1h eiLcXo9fuowoVNJplxxLfXYqEueLVcYx4TfnO6yzek+zZ7+wSrWKj42pn LECgkrTcqyDHSXqMkY9lPE6tfLn4lsa0rP9FqqS3rpfUjN1glSRFZgE2m W8Fwgc2l8Gi0tDBCHpC1ha16ikO2BinNv7DV3cQRbiGqUYHqOmpXBPGtV g==; X-CSE-ConnectionGUID: /4xmlThVQDODSX5FdYGRyA== X-CSE-MsgGUID: 7GsUpel8RvOK0AxeNYmXNQ== X-IronPort-AV: E=McAfee;i="6800,10657,11717"; a="99035061" X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="99035061" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2026 01:28:24 -0800 X-CSE-ConnectionGUID: oJi74WpkRAKnoc0lnA206w== X-CSE-MsgGUID: DjHQ2IzsSM+cZVA2C6XXIw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="217927464" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa008.jf.intel.com with ESMTP; 03 Mar 2026 01:28:23 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id 2F83198; Tue, 03 Mar 2026 10:28:21 +0100 (CET) From: Andy Shevchenko To: Mark Brown , Andy Shevchenko , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Subject: [PATCH v5 1/2] regcache: Factor out regcache_hw_exit() helper Date: Tue, 3 Mar 2026 10:26:24 +0100 Message-ID: <20260303092820.2818138-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260303092820.2818138-1-andriy.shevchenko@linux.intel.com> References: <20260303092820.2818138-1-andriy.shevchenko@linux.intel.com> 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" Factor out regcache_hw_exit() helper to make error and exit paths clearer. This helps to avoid missing changes in case the code gets shuffled in the future. Signed-off-by: Andy Shevchenko --- drivers/base/regmap/regcache.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 13c480b6e21d..329cdee1ae1c 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -131,6 +131,13 @@ static int regcache_hw_init(struct regmap *map, int co= unt) return ret; } =20 +static void regcache_hw_exit(struct regmap *map) +{ + kfree(map->reg_defaults); + if (map->cache_free) + kfree(map->reg_defaults_raw); +} + int regcache_init(struct regmap *map, const struct regmap_config *config) { int count =3D 0; @@ -245,9 +252,7 @@ int regcache_init(struct regmap *map, const struct regm= ap_config *config) map->unlock(map->lock_arg); } err_free: - kfree(map->reg_defaults); - if (map->cache_free) - kfree(map->reg_defaults_raw); + regcache_hw_exit(map); =20 return ret; } @@ -259,9 +264,7 @@ void regcache_exit(struct regmap *map) =20 BUG_ON(!map->cache_ops); =20 - kfree(map->reg_defaults); - if (map->cache_free) - kfree(map->reg_defaults_raw); + regcache_hw_exit(map); =20 if (map->cache_ops->exit) { dev_dbg(map->dev, "Destroying %s cache\n", --=20 2.50.1 From nobody Thu Apr 16 02:01:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 D844938C433 for ; Tue, 3 Mar 2026 09:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530110; cv=none; b=QsM20EEW1jiGt796pLwCqoCgS+/HHTFZ3rEOugRzWRy5hEBJbTklrhExk2BhK1lxbRT9Vfn7bUa9sp1NKlQjVZLXh0sWgKQDQFHM8jy5duxQlBgWafON8DAXmIRV8zopWoK73TvIxP+wBdJ10cs3/eIBrKrpn4p0wI5CuXJhArA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772530110; c=relaxed/simple; bh=COVnH2ytVPCM/6gpIZlke7Xd41k7QzVJ48aO0t2mQdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1nRE3cVjkk4SlF9oGUDYvj0FuEzSZmcruCPTfBwrIuyATfprqrxUKYrjl0eImeKsMrYSlH15dJFbftSeocW2tuSA1bFKkXExknaJlUet6/3qgx8OQUX2uDBdKMr10HDamRIK4EO9vmNDg0YIKw1px2HdP1otLh5xVRrFE2vTqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Hj5fOGMl; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hj5fOGMl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772530109; x=1804066109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=COVnH2ytVPCM/6gpIZlke7Xd41k7QzVJ48aO0t2mQdg=; b=Hj5fOGMlsLzGSLsL9GCUbYkTmN396YW8z0v0+n6n9NFwWzLbf047B//o vPRkNb6ozWvEQIQBuy70pweCI+avKwLCkWAbMKdF3firRkrsVGUlFy810 0P87/9P5rnuPm4ejncSzlGWUx+sa0zORvyoXQkW7CVGpI8M+4xmVc+kwX oqNRF63ykH6D6W5wgb78b+g7hO9Yo8bHJiu1oInmo5m+l11UujJYGHFLH aBvWUMwEF60EpJw81B7OlOr87RF/h/P/WwDNZ1K7Lc/hPlvPvzqVWiHfS foqw6/L8pJ04DzWrBMfiXkw1bSTfTiufcO+oToh2Et5Fv3uR1VfG7NnJo A==; X-CSE-ConnectionGUID: 5AfebYh8QaGtGNYLYrLtuQ== X-CSE-MsgGUID: 3wv1diKPRYyARl0FoxfG9A== X-IronPort-AV: E=McAfee;i="6800,10657,11717"; a="76158829" X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="76158829" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2026 01:28:24 -0800 X-CSE-ConnectionGUID: 5fCM5T8ERwS4OK93iqH8UQ== X-CSE-MsgGUID: hBnlXx+QT8GfWR5tvDDjUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,321,1763452800"; d="scan'208";a="222095482" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa003.jf.intel.com with ESMTP; 03 Mar 2026 01:28:23 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id 33C6699; Tue, 03 Mar 2026 10:28:21 +0100 (CET) From: Andy Shevchenko To: Mark Brown , Andy Shevchenko , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Subject: [PATCH v5 2/2] regcache: Move HW readback after cache initialisation Date: Tue, 3 Mar 2026 10:26:25 +0100 Message-ID: <20260303092820.2818138-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260303092820.2818138-1-andriy.shevchenko@linux.intel.com> References: <20260303092820.2818138-1-andriy.shevchenko@linux.intel.com> 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" Make sure that cache is initialised before calling any IO using regmap, this makes sure that we won't access NULL or invalid pointers in the cache which hasn't been initialised. As a side effect it also makes the ordering of cleaning up the resources in regcache_exit() to be the same (and correct) as in the error path of regcache_init(). This is not a problem right now as they do not have dependencies, but it makes code robust against potential changes in the future. Signed-off-by: Andy Shevchenko --- drivers/base/regmap/regcache.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 329cdee1ae1c..5beada4ca64c 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -66,6 +66,14 @@ static int regcache_hw_init(struct regmap *map, int coun= t) unsigned int reg, val; void *tmp_buf; =20 + /* + * When count is zero, it means there is nothing to cache and hence + * nothing to read back from HW to set up defaults, so skip this phase + * without an error code returned. + */ + if (!count) + return 0; + map->num_reg_defaults =3D count; map->reg_defaults =3D kmalloc_objs(struct reg_default, count); if (!map->reg_defaults) @@ -208,14 +216,6 @@ int regcache_init(struct regmap *map, const struct reg= map_config *config) count =3D regcache_count_cacheable_registers(map); if (map->cache_bypass) return 0; - - /* Some devices such as PMICs don't have cache defaults, - * we cope with this by reading back the HW registers and - * crafting the cache defaults by hand. - */ - ret =3D regcache_hw_init(map, count); - if (ret < 0) - return ret; } =20 if (!map->max_register_is_set && map->num_reg_defaults_raw) { @@ -230,9 +230,18 @@ int regcache_init(struct regmap *map, const struct reg= map_config *config) ret =3D map->cache_ops->init(map); map->unlock(map->lock_arg); if (ret) - goto err_free; + return ret; } =20 + /* + * Some devices such as PMICs don't have cache defaults, + * we cope with this by reading back the HW registers and + * crafting the cache defaults by hand. + */ + ret =3D regcache_hw_init(map, count); + if (ret) + goto err_exit; + if (map->cache_ops->populate && (map->num_reg_defaults || map->reg_default_cb)) { dev_dbg(map->dev, "Populating %s cache\n", map->cache_ops->name); @@ -240,10 +249,12 @@ int regcache_init(struct regmap *map, const struct re= gmap_config *config) ret =3D map->cache_ops->populate(map); map->unlock(map->lock_arg); if (ret) - goto err_exit; + goto err_free; } return 0; =20 +err_free: + regcache_hw_exit(map); err_exit: if (map->cache_ops->exit) { dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name); @@ -251,8 +262,6 @@ int regcache_init(struct regmap *map, const struct regm= ap_config *config) ret =3D map->cache_ops->exit(map); map->unlock(map->lock_arg); } -err_free: - regcache_hw_exit(map); =20 return ret; } --=20 2.50.1