From nobody Sun Dec 14 19:11:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3BA56235C32 for ; Wed, 11 Dec 2024 20:57:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950650; cv=none; b=TzckOKnbHuFT4h9ZEOTp/8Cue7X2c23dn8u7FDRmXaJ9edXNB5hiayLT+DObi77oQMfVj4MfeGce9O1h1HNZQGuiYrtUxL+bDahHYGC8MLAqfKOYBKxYV+pPygOiHmZkyRuDBx3PpW17sK9QkJG+57i8ye+z0fImxAhsNJCuFZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950650; c=relaxed/simple; bh=XvZ70etxbl7a+HEq8W/PmORE99I680EgH7X9zOxKkeU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uvnw9vZnIBN5Zi8jQiUgMmoHt4JFQGMXuxX+5zaIW43/hu93nszoQ3NQ5s2zb2Tit6qkl/K9poyqT0i0sojZd+kEwAg3YaTmlLcT6Iipgdwzpss2j+/jeHF9eyCWkh4WPY1ihOUVMgJmOKNtEIH9Jk5URKPSFCMHJBuXk9xJnPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FhjcpX90; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FhjcpX90" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C643CC4CEDD; Wed, 11 Dec 2024 20:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733950650; bh=XvZ70etxbl7a+HEq8W/PmORE99I680EgH7X9zOxKkeU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FhjcpX904qnBERVAcvLCNepto31hdwld4EYeU1UemcH4x0AkLC9lvG+vQO3caXnc5 e8QlKXo25UKC+eYBrRzv/M5XJ47aws1MUKuu/30z+RTh1n9g19S6C/ZmCSJl/csmAu yKnsVsCOYVpFZItt///kQdR/aNJIeUClZX9WVVsjMvbRn2n44OH2fNZfcCTNnCDMkq gNcZOOLNB5FcPebsjx2tuQqU0AWcn9nQlzxFL+LiItqfDnwR5hxLsaUDQU1rtnrXVe NdzNwgTcGEZn5BqsvTMJKHbWhnRu0+NA7UZEhX/wwh5o60dr/OHf24MsN0AOjt4XCP dq9WQtAydnghg== From: "Rob Herring (Arm)" Date: Wed, 11 Dec 2024 14:57:12 -0600 Subject: [PATCH 1/3] mfd: syscon: Fix race in device_node_get_regmap() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241211-syscon-fixes-v1-1-b5ac8c219e96@kernel.org> References: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> In-Reply-To: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> To: Lee Jones , Arnd Bergmann , Pankaj Dubey , Heiko Stuebner , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi Cc: Peter Griffin , Will McVicker , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15-dev It is possible for multiple, simultaneous callers calling device_node_get_regmap() with the same node to fail to find an entry in the syscon_list. There is a period of time while the first caller is calling of_syscon_register() that subsequent callers also fail to find an entry in the syscon_list and then call of_syscon_register() a second time. Fix this by keeping the lock held until after of_syscon_register() completes and adds the node to syscon_list. Convert the spinlock to a mutex as many of the functions called in of_syscon_register() may sleep. Fixes: bdb0066df96e ("mfd: syscon: Decouple syscon interface from platform = devices") Signed-off-by: Rob Herring (Arm) Reviewed-by: Krzysztof Kozlowski Tested-by: Krzysztof Kozlowski --- drivers/mfd/syscon.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 3e1d699ba934..72f20de9652d 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,7 @@ =20 static struct platform_driver syscon_driver; =20 -static DEFINE_SPINLOCK(syscon_list_slock); +static DEFINE_MUTEX(syscon_list_lock); static LIST_HEAD(syscon_list); =20 struct syscon { @@ -54,6 +55,8 @@ static struct syscon *of_syscon_register(struct device_no= de *np, bool check_res) struct resource res; struct reset_control *reset; =20 + WARN_ON(!mutex_is_locked(&syscon_list_lock)); + struct syscon *syscon __free(kfree) =3D kzalloc(sizeof(*syscon), GFP_KERN= EL); if (!syscon) return ERR_PTR(-ENOMEM); @@ -146,9 +149,7 @@ static struct syscon *of_syscon_register(struct device_= node *np, bool check_res) syscon->regmap =3D regmap; syscon->np =3D np; =20 - spin_lock(&syscon_list_slock); list_add_tail(&syscon->list, &syscon_list); - spin_unlock(&syscon_list_slock); =20 return_ptr(syscon); =20 @@ -169,7 +170,7 @@ static struct regmap *device_node_get_regmap(struct dev= ice_node *np, { struct syscon *entry, *syscon =3D NULL; =20 - spin_lock(&syscon_list_slock); + mutex_lock(&syscon_list_lock); =20 list_for_each_entry(entry, &syscon_list, list) if (entry->np =3D=3D np) { @@ -177,11 +178,11 @@ static struct regmap *device_node_get_regmap(struct d= evice_node *np, break; } =20 - spin_unlock(&syscon_list_slock); - if (!syscon) syscon =3D of_syscon_register(np, check_res); =20 + mutex_unlock(&syscon_list_lock); + if (IS_ERR(syscon)) return ERR_CAST(syscon); =20 @@ -212,7 +213,7 @@ int of_syscon_register_regmap(struct device_node *np, s= truct regmap *regmap) return -ENOMEM; =20 /* check if syscon entry already exists */ - spin_lock(&syscon_list_slock); + mutex_lock(&syscon_list_lock); =20 list_for_each_entry(entry, &syscon_list, list) if (entry->np =3D=3D np) { @@ -225,12 +226,12 @@ int of_syscon_register_regmap(struct device_node *np,= struct regmap *regmap) =20 /* register the regmap in syscon list */ list_add_tail(&syscon->list, &syscon_list); - spin_unlock(&syscon_list_slock); + mutex_unlock(&syscon_list_lock); =20 return 0; =20 err_unlock: - spin_unlock(&syscon_list_slock); + mutex_unlock(&syscon_list_lock); kfree(syscon); return ret; } --=20 2.45.2 From nobody Sun Dec 14 19:11:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3BA9A235C59 for ; Wed, 11 Dec 2024 20:57:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950652; cv=none; b=nCOF8w3Bf1RGGO2ZuE7Ln4uBKavJIAVBtNiyV4H3gjBQyI5msqXMY0oGA3IdXcX8RGON2qqBuNY/qLGrWGPKq4ZVWOUEYxhUTYE6/6Iipqh92svYiDFBOehbmZADz0DdSu9wLC1FmFuTu/h/OQg5/s3y+Le4BHw0eJEVET88HTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950652; c=relaxed/simple; bh=PHYwqGgWB0lSo6OmuMit5TbEY8jguzXS3yzvWMX+Owo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WxUtOxTUWRNklFzvRn58rXeYNKVrAfpge7+wAo05E1iV2Dr5xQR/StpZcdyuz4v2mw+nrYQ75ypVqz9XDJvEaUXhuOb+jsws8884VsTaCSQMwbLEU87s6aOenmNYyNcQEOd3Az7dUN1utINM+pjBehyYLt17rQP8zOTKTWHKIws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=diJ/KSJd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="diJ/KSJd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94BB3C4CED2; Wed, 11 Dec 2024 20:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733950651; bh=PHYwqGgWB0lSo6OmuMit5TbEY8jguzXS3yzvWMX+Owo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=diJ/KSJd+fHcwKKzyci9w6hIBrXUR4Nh2lHGlyrg2KQWcBnF4iNQXryJTwxSsb/X/ HuKC1uDTMgeJ0KrKu1QKACP0BF/dAB4ZxJKwaPOD2gBGnO4idYqWRGbfnBbJ56F9Dj CQ2S4REa8ioDmvAkormSg2r+WfJvzYYtAfXHQh5sHHgxdZiwTlYFBPMsHOJs5n9hYG UxqZ0LYaLyc2iryb0LpOf44LrXdnjTyO+Xa+ChQzttD+WtZS2jy9jlo4CieCwoWw/i kRP4XBogtzH8GmPTsdLbRbDXs2VpJWqUZMRSn0laFgvYwV0DpApIBMJKIsHNOubpcA ch3wccT/zJZsw== From: "Rob Herring (Arm)" Date: Wed, 11 Dec 2024 14:57:13 -0600 Subject: [PATCH 2/3] mfd: syscon: Remove the platform driver support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241211-syscon-fixes-v1-2-b5ac8c219e96@kernel.org> References: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> In-Reply-To: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> To: Lee Jones , Arnd Bergmann , Pankaj Dubey , Heiko Stuebner , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi Cc: Peter Griffin , Will McVicker , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15-dev The platform driver is dead code. It is not used by DT platforms since commit bdb0066df96e ("mfd: syscon: Decouple syscon interface from platform devices") which said: For non-DT based platforms, this patch keeps syscon platform driver structure so that syscon can be probed and such non-DT based drivers can use syscon_regmap_lookup_by_pdev API and access regmap handles. Once all users of "syscon_regmap_lookup_by_pdev" migrated to DT based, we can completely remove platform driver of syscon, and keep only helper functions to get regmap handles. The last user of syscon_regmap_lookup_by_pdevname() was removed in 2018. syscon_regmap_lookup_by_pdevname() was then removed in 2019, but that commit failed to remove the rest of the platform driver. Signed-off-by: Rob Herring (Arm) Tested-by: Krzysztof Kozlowski --- drivers/mfd/syscon.c | 66 --------------------------------= ---- drivers/mfd/vexpress-sysreg.c | 1 - include/linux/platform_data/syscon.h | 9 ----- 3 files changed, 76 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 72f20de9652d..bfb1f69fcff1 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -12,22 +12,15 @@ #include #include #include -#include -#include #include #include #include #include -#include -#include -#include #include #include #include #include =20 -static struct platform_driver syscon_driver; - static DEFINE_MUTEX(syscon_list_lock); static LIST_HEAD(syscon_list); =20 @@ -337,62 +330,3 @@ struct regmap *syscon_regmap_lookup_by_phandle_optiona= l(struct device_node *np, return regmap; } EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle_optional); - -static int syscon_probe(struct platform_device *pdev) -{ - struct device *dev =3D &pdev->dev; - struct syscon_platform_data *pdata =3D dev_get_platdata(dev); - struct syscon *syscon; - struct regmap_config syscon_config =3D syscon_regmap_config; - struct resource *res; - void __iomem *base; - - syscon =3D devm_kzalloc(dev, sizeof(*syscon), GFP_KERNEL); - if (!syscon) - return -ENOMEM; - - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -ENOENT; - - base =3D devm_ioremap(dev, res->start, resource_size(res)); - if (!base) - return -ENOMEM; - - syscon_config.max_register =3D resource_size(res) - 4; - if (!syscon_config.max_register) - syscon_config.max_register_is_0 =3D true; - - if (pdata) - syscon_config.name =3D pdata->label; - syscon->regmap =3D devm_regmap_init_mmio(dev, base, &syscon_config); - if (IS_ERR(syscon->regmap)) { - dev_err(dev, "regmap init failed\n"); - return PTR_ERR(syscon->regmap); - } - - platform_set_drvdata(pdev, syscon); - - dev_dbg(dev, "regmap %pR registered\n", res); - - return 0; -} - -static const struct platform_device_id syscon_ids[] =3D { - { "syscon", }, - { } -}; - -static struct platform_driver syscon_driver =3D { - .driver =3D { - .name =3D "syscon", - }, - .probe =3D syscon_probe, - .id_table =3D syscon_ids, -}; - -static int __init syscon_init(void) -{ - return platform_driver_register(&syscon_driver); -} -postcore_initcall(syscon_init); diff --git a/drivers/mfd/vexpress-sysreg.c b/drivers/mfd/vexpress-sysreg.c index d34d58ce46db..ef03d6cec9ff 100644 --- a/drivers/mfd/vexpress-sysreg.c +++ b/drivers/mfd/vexpress-sysreg.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/include/linux/platform_data/syscon.h b/include/linux/platform_= data/syscon.h deleted file mode 100644 index 2c089dd3e2bd..000000000000 --- a/include/linux/platform_data/syscon.h +++ /dev/null @@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef PLATFORM_DATA_SYSCON_H -#define PLATFORM_DATA_SYSCON_H - -struct syscon_platform_data { - const char *label; -}; - -#endif --=20 2.45.2 From nobody Sun Dec 14 19:11:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C3402236926 for ; Wed, 11 Dec 2024 20:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950653; cv=none; b=UcrPJBcMsm31yGgULnItwEJt5dA7RuPnQ5IyoLnVICBHDIIYsUxXO8IAj+TXQNAvqbHRcDqmKGjvoLr0lfR50/q82VX7DaYwdokSg1lTlOP/uo67nF9TIYXL0SqC319QxS5MJlAFBmz/nwP/XXJl0TLWom0hXQBnpyZoMm8j0XM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733950653; c=relaxed/simple; bh=Y/MDmPX+r3gFiGkupbpCHeLUQbC0UW+h6X8OOkloMKE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZJa/75YLb2HBAxpFUi2zLB5LRC0lG7yNVK78UQ9u1U6oYGCqkZzvzXJ3RkZgm9pXSkN6B/l1WHV0aqVsS4pf8BeD9y016of6f3snKrhiezApZ3vofKvNw4KRQkT8gJ8Rc4O04Q4ObvdZBjpArbp1YvzbehLpsmy2vBvLhBcgQbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LN0YFaNW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LN0YFaNW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76787C4CED2; Wed, 11 Dec 2024 20:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733950653; bh=Y/MDmPX+r3gFiGkupbpCHeLUQbC0UW+h6X8OOkloMKE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LN0YFaNW0XkbhQWrUu4KyYxoUxFeOOL/7gN/959Y/oZ4XosqkwUk6Ful1RaogQoXe d0UADj0jmauunJXNMJtYTA68o52KnvAKrFoADSFc4baqVNTbsf8QO4NAxRyZVT1MBW gcPjNKqg1R8UdZdA6xp84He5i51rheLtXsXe0hDoO04B9JmcTOZEIm6HwFZqV8wV5y NeRys0hIIBzMlo7yDVjGVyTSP2NdJ4xiJWOwgW/ndGBeMUJzFl7L7oGy8tvlHorfK+ mhg1r5u5NYb/QVKhXBxLxRKYlVOLXE8D6Nzz3Ae5U7SOArctOsFvRDY8Qa/h6K87Cy HJ8KM84ngZejg== From: "Rob Herring (Arm)" Date: Wed, 11 Dec 2024 14:57:14 -0600 Subject: [PATCH 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241211-syscon-fixes-v1-3-b5ac8c219e96@kernel.org> References: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> In-Reply-To: <20241211-syscon-fixes-v1-0-b5ac8c219e96@kernel.org> To: Lee Jones , Arnd Bergmann , Pankaj Dubey , Heiko Stuebner , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi Cc: Peter Griffin , Will McVicker , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15-dev of_syscon_register_regmap() was added for nodes which need a custom regmap setup. It's not really correct for those nodes to claim they are compatible with "syscon" as the default handling likely doesn't work in those cases. If device_node_get_regmap() happens to be called first, then of_syscon_register() will be called and an incorrect regmap will be created (barring some other error). That may lead to unknown results in the worst case. In the best case, of_syscon_register_regmap() will fail with -EEXIST. This problem remains unless these cases drop "syscon" (an ABI issue) or we exclude them using their specific compatible. ATM, there is only one user: "google,gs101-pmu" There are also cases of adding "syscon" compatible to existing nodes after the fact in order to register the syscon. That presents a potential DT ABI problem. Instead, if there's a kernel change needing a syscon for a node, then it should be possible to allow the kernel to register a syscon without a DT change. That's only possible by using of_syscon_register_regmap() currently, but in the future we may want to support a match list for cases which don't need a custom regmap. With this change, the lookup functions will succeed for any node registered by of_syscon_register_regmap() regardless of whether the node compatible contains "syscon". Signed-off-by: Rob Herring (Arm) --- drivers/mfd/syscon.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index bfb1f69fcff1..e6df2825c14d 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -171,8 +171,10 @@ static struct regmap *device_node_get_regmap(struct de= vice_node *np, break; } =20 - if (!syscon) + if (!syscon && of_device_is_compatible(np, "syscon")) syscon =3D of_syscon_register(np, check_res); + else + syscon =3D ERR_PTR(-EINVAL); =20 mutex_unlock(&syscon_list_lock); =20 @@ -238,9 +240,6 @@ EXPORT_SYMBOL_GPL(device_node_to_regmap); =20 struct regmap *syscon_node_to_regmap(struct device_node *np) { - if (!of_device_is_compatible(np, "syscon")) - return ERR_PTR(-EINVAL); - return device_node_get_regmap(np, true); } EXPORT_SYMBOL_GPL(syscon_node_to_regmap); --=20 2.45.2