mfd: syscon: Cleanup, fix race condition and remove platform driver
Subsystems (3)
v2 cover mfd: syscon: Cleanup, fix race condition and remove platform driver
Questions from Krzysztof and a syscon related binding review got me looking at the syscon "driver". This series is the result.
This short series drops the stale platform driver part of syscon support, fixes a race condition in device_node_get_regmap() which is used by all the lookup functions, and allows for registering nodes without "syscon" compatibles.
Compile tested only. Testing on Tensor, the one user of of_syscon_register_regmap(), would be helpful.
---
Changes in v2:
- Fix patch 3 logic when a syscon is found in list to not return an
error
- Add tags
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Rob Herring (Arm) (3):
mfd: syscon: Fix race in device_node_get_regmap()
mfd: syscon: Remove the platform driver support
mfd: syscon: Allow syscon nodes without a "syscon" compatible
drivers/mfd/syscon.c | 95 ++++++------------------------------ drivers/mfd/vexpress-sysreg.c | 1 - include/linux/platform_data/syscon.h | 9 ---- 3 files changed, 15 insertions(+), 90 deletions(-)
---
base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
change-id: 20241211-syscon-fixes-9f35ecb9bfbe
Best regards,
Signature · 1 line
Rob Herring (Arm) <[email protected]>
PATCH v2 1/3 mfd: syscon: Fix race in device_node_get_regmap()
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() such as kzalloc() and of_clk_get() may sleep.
--- drivers/mfd/syscon.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/mfd/syscon.c +10 -9
@@ -15,6 +15,7 @@#include <linux/io.h> #include <linux/init.h> #include <linux/list.h> +#include <linux/mutex.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_platform.h>
@@ -27,7 +28,7 @@static struct platform_driver syscon_driver; -static DEFINE_SPINLOCK (syscon_list_slock); +static DEFINE_MUTEX (syscon_list_lock);static LIST_HEAD (syscon_list);struct syscon {
@@ -54,6 +55,8 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)struct resource res;struct reset_control *reset; +WARN_ON (!mutex_is_locked (&syscon_list_lock)); + struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL);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 = regmap; syscon->np = np; -spin_lock (&syscon_list_slock);list_add_tail (&syscon->list, &syscon_list); -spin_unlock (&syscon_list_slock);return_ptr (syscon);
@@ -169,7 +170,7 @@ static struct regmap *device_node_get_regmap(struct device_node *np, {struct syscon *entry, *syscon =NULL ; -spin_lock (&syscon_list_slock); +mutex_lock (&syscon_list_lock);list_for_each_entry (entry, &syscon_list, list)if (entry->np == np) {
@@ -177,11 +178,11 @@ static struct regmap *device_node_get_regmap(struct device_node *np,break ; } -spin_unlock (&syscon_list_slock); -if (!syscon) syscon =of_syscon_register (np, check_res); +mutex_unlock (&syscon_list_lock); +if (IS_ERR (syscon))return ERR_CAST (syscon);
@@ -212,7 +213,7 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)return -ENOMEM ;/* check if syscon entry already exists */ -spin_lock (&syscon_list_slock); +mutex_lock (&syscon_list_lock);list_for_each_entry (entry, &syscon_list, list)if (entry->np == np) {
@@ -225,12 +226,12 @@ int of_syscon_register_regmap(struct device_node *np, struct regmap *regmap)/* register the regmap in syscon list */ list_add_tail (&syscon->list, &syscon_list); -spin_unlock (&syscon_list_slock); +mutex_unlock (&syscon_list_lock);return 0 ; err_unlock: -spin_unlock (&syscon_list_slock); +mutex_unlock (&syscon_list_lock);kfree (syscon);return ret; }
Signature · 1 line
2.45.2
Re: [PATCH v2 1/3] mfd: syscon: Fix race in device_node_get_regmap()
Quoted 12 lines · Rob Herring (Arm)
It is possible for multiple, simultaneous callers calling
device_node_get_regmap()with the same node to fail to find an entry in thesyscon_list. There is a period of time while the first caller is callingof_syscon_register()that subsequent callers also fail to find an entry in thesyscon_listand then callof_syscon_register()a second time.Fix this by keeping the lock held until after
of_syscon_register()completes and adds the node tosyscon_list. Convert the spinlock to a mutex as many of the functions called inof_syscon_register()such askzalloc()andof_clk_get()may sleep.
Quoted 4 lines
Fixes bdb0066df96e ("mfd: syscon: Decouple syscon interface from platform devices")Reviewed-by Krzysztof Kozlowski <[email protected]>Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>
I verified this works on my Pixel 6. Thanks!
Thanks,
Will
RE: [PATCH v2 1/3] mfd: syscon: Fix race in device_node_get_regmap()
In reply to Rob Herring (Arm)Quoted 26 lines
-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Tuesday, December 17, 2024 11:42 PM
To: Lee Jones <[email protected]>; Arnd Bergmann <[email protected]>; Pankaj Dubey <[email protected]>; Heiko Stuebner <[email protected]>; Liviu Dudau <[email protected]>; Sudeep Holla <[email protected]>; Lorenzo Pieralisi <[email protected]>
Cc: Peter Griffin <[email protected]>; Will McVicker <[email protected]>; John Madieu <[email protected]>; Krzysztof Kozlowski <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2 1/3] mfd: syscon: Fix race indevice_node_get_regmap()It is possible for multiple, simultaneous callers calling
device_node_get_regmap()with the same node to fail to find an entry in thesyscon_list. There is a period of time while the first caller is callingof_syscon_register()that subsequent callers also fail to find an entry in thesyscon_listand then callof_syscon_register()a second time.Fix this by keeping the lock held until after
of_syscon_register()completes and adds the node tosyscon_list. Convert the spinlock to a mutex as many of the functions called inof_syscon_register()such askzalloc()andof_clk_get()may sleep.
Quoted 6 lines
Fixes bdb0066df96e ("mfd: syscon: Decouple syscon interface from platformdevices")
Reviewed-by Krzysztof Kozlowski <[email protected]>Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>---
Tested on arm64: Tesla FSD
Thanks.
Pankaj Dubey
RE: [PATCH v2 1/3] mfd: syscon: Fix race in device_node_get_regmap()
In reply to Rob Herring (Arm)Quoted 26 lines
-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Tuesday, December 17, 2024 11:42 PM
To: Lee Jones <[email protected]>; Arnd Bergmann <[email protected]>; Pankaj Dubey <[email protected]>; Heiko Stuebner <[email protected]>; Liviu Dudau <[email protected]>; Sudeep Holla <[email protected]>; Lorenzo Pieralisi <[email protected]>
Cc: Peter Griffin <[email protected]>; Will McVicker <[email protected]>; John Madieu <[email protected]>; Krzysztof Kozlowski <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2 1/3] mfd: syscon: Fix race indevice_node_get_regmap()It is possible for multiple, simultaneous callers calling
device_node_get_regmap()with the same node to fail to find an entry in thesyscon_list. There is a period of time while the first caller is callingof_syscon_register()that subsequent callers also fail to find an entry in thesyscon_listand then callof_syscon_register()a second time.Fix this by keeping the lock held until after
of_syscon_register()completes and adds the node tosyscon_list. Convert the spinlock to a mutex as many of the functions called inof_syscon_register()such askzalloc()andof_clk_get()may sleep.
Quoted 6 lines
Fixes bdb0066df96e ("mfd: syscon: Decouple syscon interface from platformdevices")
Reviewed-by Krzysztof Kozlowski <[email protected]>Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>---
PATCH v2 2/3 mfd: syscon: Remove the platform driver support
In reply to Rob Herring (Arm)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.
--- drivers/mfd/syscon.c | 66 ------------------------------------ drivers/mfd/vexpress-sysreg.c | 1 - include/linux/platform_data/syscon.h | 9 ----- 3 files changed, 76 deletions(-)
drivers/mfd/syscon.c +0 -66
@@ -12,22 +12,15 @@#include <linux/clk.h> #include <linux/err.h> #include <linux/hwspinlock.h> -#include <linux/io.h> -#include <linux/init.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/of_platform.h> -#include <linux/platform_data/syscon.h> -#include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/reset.h> #include <linux/mfd/syscon.h> #include <linux/slab.h> -static struct platform_driver syscon_driver; -static DEFINE_MUTEX (syscon_list_lock);static LIST_HEAD (syscon_list);
@@ -337,62 +330,3 @@ struct regmap *syscon_regmap_lookup_by_phandle_optional(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 = &pdev->dev; -struct syscon_platform_data *pdata =dev_get_platdata (dev); -struct syscon *syscon; -struct regmap_config syscon_config = syscon_regmap_config; -struct resource *res; -void __iomem *base; - - syscon =devm_kzalloc (dev,sizeof (*syscon),GFP_KERNEL ); -if (!syscon) -return -ENOMEM ; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) -return -ENOENT ; - - base =devm_ioremap (dev, res->start,resource_size (res)); -if (!base) -return -ENOMEM ; - - syscon_config.max_register =resource_size (res) -4 ; -if (!syscon_config.max_register) - syscon_config.max_register_is_0 = true; - -if (pdata) - syscon_config.name = pdata->label; - syscon->regmap =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[] = { - {"syscon" , }, - { } -}; - -static struct platform_driver syscon_driver = { - .driver = { - .name ="syscon" , - }, - .probe = syscon_probe, - .id_table = syscon_ids, -}; - -static int __init syscon_init (void ) -{ -return platform_driver_register (&syscon_driver); -} -postcore_initcall (syscon_init);
drivers/mfd/vexpress-sysreg.c +0 -1
@@ -10,7 +10,6 @@#include <linux/mfd/core.h> #include <linux/module.h> #include <linux/of_platform.h> -#include <linux/platform_data/syscon.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/stat.h>
include/linux/platform_data/syscon.h deleted +0 -9
@@ -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
Signature · 1 line
2.45.2
Re: [PATCH v2 2/3] mfd: syscon: Remove the platform driver support
Quoted 11 lines · Rob Herring (Arm)
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_pdevAPI 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.
Quoted 6 lines
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.Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>
I verified this works on my Pixel 6. Thanks!
Thanks,
Will
Re: [PATCH v2 2/3] mfd: syscon: Remove the platform driver support
In reply to Rob Herring (Arm)Quoted 11 lines · Rob Herring (Arm)
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_pdevAPI 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.
Quoted 6 lines
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.Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>
(Mostly for the vexpress-sysreg.c part, but hey, it's all code being removed):
Best regards,
Liviu
Quoted 127 lines
--- drivers/mfd/syscon.c | 66 ------------------------------------ drivers/mfd/vexpress-sysreg.c | 1 - include/linux/platform_data/syscon.h | 9 ----- 3 files changed, 76 deletions(-)drivers/mfd/syscon.c +0
-66@@ -12,22 +12,15 @@#include <linux/clk.h> #include <linux/err.h> #include <linux/hwspinlock.h> -#include <linux/io.h> -#include <linux/init.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/of_platform.h> -#include <linux/platform_data/syscon.h> -#include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/reset.h> #include <linux/mfd/syscon.h> #include <linux/slab.h> -static struct platform_driver syscon_driver; -static DEFINE_MUTEX (syscon_list_lock);static LIST_HEAD (syscon_list);@@ -337,62 +330,3 @@ struct regmap *syscon_regmap_lookup_by_phandle_optional(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 = &pdev->dev; -struct syscon_platform_data *pdata =dev_get_platdata (dev); -struct syscon *syscon; -struct regmap_config syscon_config = syscon_regmap_config; -struct resource *res; -void __iomem *base; - - syscon =devm_kzalloc (dev,sizeof (*syscon),GFP_KERNEL ); -if (!syscon) -return -ENOMEM ; - - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) -return -ENOENT ; - - base =devm_ioremap (dev, res->start,resource_size (res)); -if (!base) -return -ENOMEM ; - - syscon_config.max_register =resource_size (res) -4 ; -if (!syscon_config.max_register) - syscon_config.max_register_is_0 = true; - -if (pdata) - syscon_config.name = pdata->label; - syscon->regmap =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[] = { - {"syscon" , }, - { } -}; - -static struct platform_driver syscon_driver = { - .driver = { - .name ="syscon" , - }, - .probe = syscon_probe, - .id_table = syscon_ids, -}; - -static int __init syscon_init (void ) -{ -return platform_driver_register (&syscon_driver); -} -postcore_initcall (syscon_init);drivers/mfd/vexpress-sysreg.c +0
-1@@ -10,7 +10,6 @@#include <linux/mfd/core.h> #include <linux/module.h> #include <linux/of_platform.h> -#include <linux/platform_data/syscon.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/stat.h> include/linux/platform_data/syscon.h deleted +0
-9@@ -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 Signature · 2 lines
-- 2.45.2
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯RE: [PATCH v2 2/3] mfd: syscon: Remove the platform driver support
In reply to Rob Herring (Arm)Quoted 26 lines
-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Tuesday, December 17, 2024 11:42 PM
To: Lee Jones <[email protected]>; Arnd Bergmann <[email protected]>; Pankaj Dubey <[email protected]>; Heiko Stuebner <[email protected]>; Liviu Dudau <[email protected]>; Sudeep Holla <[email protected]>; Lorenzo Pieralisi <[email protected]>
Cc: Peter Griffin <[email protected]>; Will McVicker <[email protected]>; John Madieu <[email protected]>; Krzysztof Kozlowski <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2 2/3] mfd: syscon: Remove the platform driver supportThe 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_pdevAPI 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.
Quoted 7 lines
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.Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>---
Tested on arm64: Tesla FSD
Thanks,
Pankaj Dubey
Re: [PATCH v2 2/3] mfd: syscon: Remove the platform driver support
In reply to Rob Herring (Arm)Quoted 11 lines · Rob Herring (Arm)
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_pdevAPI 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.
Quoted 7 lines
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.Tested-by Krzysztof Kozlowski <[email protected]>Signed-off-by Rob Herring (Arm) <[email protected]>---
Best regards,
Krzysztof
Re: [PATCH v2 2/3] mfd: syscon: Remove the platform driver support
In reply to Rob Herring (Arm)Quoted 11 lines · Rob Herring (Arm)
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_pdevAPI 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.
Quoted 3 lines
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.
This removed the only driver claiming pmgr nodes on Apple silicon platforms. The nodes use compatible strings of the form
compatible = "apple,t8103-pmgr", "apple,pmgr", "syscon", "simple-mfd";
The description still holds as the removal of the driver did not result in functional changes and went unnoticed. The missing driver became apparent with pmdomain's sync_state() support in 6.17 which prints following messages on a M1 mac mini
| [ 11.789419] apple-pmgr-pwrstate 23b700000.power-management:power-controller@420: sync_state() pending due to 23d280000.power-management | [ 11.792414] apple-pmgr-pwrstate 23b700000.power-management:power-controller@448: sync_state() pending due to 23d280000.power-management
None of the other compatible are claimed by any driver. There is no driver for "apple,t8103-pmgr" or "apple,pmgr" and simple-pm-bus.c binds "simple-mfd" only if it is the first compatible string.
The easiest solution would be to probe via simple-pm-bus.c if the device is compatible with "apple,pmgr". The generic compatible is justified by not having any device specific code. The other option would by to add the growing list of SoC specific "apple,*-pmgr" compatibles to the match table.
The alternative of writing an Apple pmgr driver which does nothing except successfully probing devices does not look appealing.
There is second problem though. The device link between 23b700000.power-management:power-controller@420 and 23d280000.power-management should not exist in the first place. See following excerpt from arch/arm64/boot/dts/apple/{t8103,t8103-pmgr}.dtsi omitting only unrelated child nodes.
/ {
pmgr: power-management@23b700000 {
compatible = "apple,t8103-pmgr", "apple,pmgr", "syscon", "simple-mfd";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x2 0x3b700000 0 0x14000>;
ps_atc0_common: power-controller@420 {
compatible = "apple,t8103-pmgr-pwrstate", "apple,pmgr-pwrstate";
reg = <0x420 4>;
#power-domain-cells = <0>;
#reset-cells = <0>;
label = "atc0_common";
};
};
pmgr_mini: power-management@23d280000 {
compatible = "apple,t8103-pmgr", "apple,pmgr", "syscon", "simple-mfd";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x2 0x3d280000 0 0x4000>;
ps_atc0_usb: power-controller@98 {
compatible = "apple,t8103-pmgr-pwrstate", "apple,pmgr-pwrstate";
reg = <0x98 4>;
#power-domain-cells = <0>;
#reset-cells = <0>;
label = "atc0_usb";
power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_common>;
};
};
}To my understanding the fw_devlinks should only exists between &ps_atc0_common and &ps_atc0_usb. Herve Codina reports and posts a patch for what sounds to be the same issue in [1] for simple-pm-bus. I can't reproduce the report though. As soon as simple-pm-bus successfully probes the pmgr devices the spurious devlinks are gone.
So I think this needs to be fixed in either of/platform.c for all devices handled in of_platform_default_populate() or in driver-core/devlink considering the issue appears without driver for the bus device.
Janne
PATCH v2 3/3 mfd: syscon: Allow syscon nodes without a "syscon" compatible
In reply to Rob Herring (Arm)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".
---
v2:
- Fix logic when a syscon is found in list to not return an error
--- drivers/mfd/syscon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/mfd/syscon.c +6 -6
@@ -171,9 +171,12 @@ static struct regmap *device_node_get_regmap(struct device_node *np,break ; } -if (!syscon) - syscon =of_syscon_register (np, check_res); - +if (!syscon) { +if (of_device_is_compatible (np,"syscon" )) + syscon =of_syscon_register (np, check_res); +else + syscon =ERR_PTR (-EINVAL ); + }mutex_unlock (&syscon_list_lock);if (IS_ERR (syscon))
@@ -238,9 +241,6 @@ EXPORT_SYMBOL_GPL(device_node_to_regmap);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);
Signature · 1 line
2.45.2
Re: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
Quoted 19 lines · Rob Herring (Arm)
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. Ifdevice_node_get_regmap()happens to be called first, thenof_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.
Quoted 5 lines
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) <[email protected]>
I verified this works on my Pixel 6. Thanks!
Thanks,
Will
RE: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
In reply to Rob Herring (Arm)Quoted 34 lines
-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Tuesday, December 17, 2024 11:42 PM
To: Lee Jones <[email protected]>; Arnd Bergmann <[email protected]>; Pankaj Dubey <[email protected]>; Heiko Stuebner <[email protected]>; Liviu Dudau <[email protected]>; Sudeep Holla <[email protected]>; Lorenzo Pieralisi <[email protected]>
Cc: Peter Griffin <[email protected]>; Will McVicker <[email protected]>; John Madieu <[email protected]>; Krzysztof Kozlowski <[email protected]>; linux- [email protected]; [email protected]
Subject: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
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. Ifdevice_node_get_regmap()happens to be called first, thenof_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.
Quoted 6 lines
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) <[email protected]>---
Thanks,
Pankaj Dubey
Re: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
In reply to Rob Herring (Arm)Quoted 11 lines · Rob Herring (Arm)
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. Ifdevice_node_get_regmap()happens to be called first, thenof_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"
Best regards,
Krzysztof
Re: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
In reply to Rob Herring (Arm)Hi Rob,
Quoted 38 lines · Rob Herring (Arm)
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. Ifdevice_node_get_regmap()happens to be called first, thenof_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) <[email protected]>---
v2:
- Fix logic when a syscon is found in list to not return an error--- drivers/mfd/syscon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/mfd/syscon.c +0
-0@@ -171,9 +171,12 @@ static struct regmap *device_node_get_regmap(struct device_node *np,break ; }
drivers/mfd/syscon.c static struct regmap *device_node_get_regmap(struct device_node *np, · line 179
Quoted 10 lines
drivers/mfd/syscon.c +6
-3-if (!syscon) - syscon =of_syscon_register (np, check_res); - +if (!syscon) { +if (of_device_is_compatible (np,"syscon" )) + syscon =of_syscon_register (np, check_res); +else + syscon =ERR_PTR (-EINVAL ); + }
Earlier the above check was only in syscon_node_to_regmap() , but now the users of device_node_to_regmap() also undergoes this check and there are few drivers in tree which uses device_node_to_regmap() without having "syscon" in compatible, likely those drivers need to be fixed, but this patch breaks all those drivers now, atleast the below drivers are affected and all TI platforms fail to boot due to this:
drivers/soc/ti/k3-socinfo.cdrivers/mux/mmio.c ("reg-mux" users)drivers/clk/keystone/syscon-clk.c
All the above drivers fail due to the above check for syscon compatible.
What is the recommended solution to fix this?
Thanks and Regards,
Vaishnav
Quoted 14 lines
drivers/mfd/syscon.c +0
-3mutex_unlock (&syscon_list_lock);if (IS_ERR (syscon))@@ -238,9 +241,6 @@ EXPORT_SYMBOL_GPL(device_node_to_regmap);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);
Re: [PATCH v2 3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
Quoted 60 lines · Vaishnav Achath
Hi Rob,
Quoted 38 lines · Rob Herring (Arm)
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. Ifdevice_node_get_regmap()happens to be called first, thenof_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) <[email protected]>---
v2:
- Fix logic when a syscon is found in list to not return an error--- drivers/mfd/syscon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/mfd/syscon.c +0
-0@@ -171,9 +171,12 @@ static struct regmap *device_node_get_regmap(struct device_node *np,break ; }drivers/mfd/syscon.c static struct regmap *device_node_get_regmap(struct device_node *np, · line 179
Quoted 10 lines
drivers/mfd/syscon.c +6
-3-if (!syscon) - syscon =of_syscon_register (np, check_res); - +if (!syscon) { +if (of_device_is_compatible (np,"syscon" )) + syscon =of_syscon_register (np, check_res); +else + syscon =ERR_PTR (-EINVAL ); + }Earlier the above check was only in
syscon_node_to_regmap(), but now the users ofdevice_node_to_regmap()also undergoes this check and there are few drivers in tree which usesdevice_node_to_regmap()without having "syscon" in compatible, likely those drivers need to be fixed, but this patch breaks all those drivers now, atleast the below drivers are affected and all TI platforms fail to boot due to this:
Quoted 7 lines
drivers/soc/ti/k3-socinfo.cdrivers/mux/mmio.c("reg-mux" users)drivers/clk/keystone/syscon-clk.cAll the above drivers fail due to the above check for syscon compatible.
What is the recommended solution to fix this?
I've sent a fix[1]. That's not to say I don't agree with fixes to drivers removing device_node_to_regmap() calls. If you just need a regmap for within a single driver, then just use regmap APIs directly. What's in syscon.c is for (surprise!) syscon's, and those have the characteristic of being shared.
Rob
Quoted 9 lines · Rob Herring (Arm)
Questions from Krzysztof and a syscon related binding review got me looking at the syscon "driver". This series is the result.
This short series drops the stale platform driver part of syscon support, fixes a race condition in
device_node_get_regmap()which is used by all the lookup functions, and allows for registering nodes without "syscon" compatibles.[...]
Applied, thanks!
[1/3] mfd: syscon: Fix race in device_node_get_regmap()
commit: 805f7aaf7fee14a57b56af01d270edf6c10765e8
[2/3] mfd: syscon: Remove the platform driver support
commit: 26769582bf353ae613f5113a1414ff3a80e08264
[3/3] mfd: syscon: Allow syscon nodes without a "syscon" compatible
commit: ba5095ebbc7a83965ac049a50fa493d7c751f19b--
Lee Jones [李琼斯]