* [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables
@ 2025-11-06 19:07 Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 01/13] " Krzysztof Kozlowski
` (13 more replies)
0 siblings, 14 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Dependency/merging
==================
All patches depend on the first patch, thus everything could go via
Rob's tree with people's acks.
Description
===========
Several drivers duplicate same code for getting reference to the root
node, matching it against 'struct of_device_id' table and getting out
the match data from the table entry.
There is a of_machine_compatible_match() wrapper but it takes array of
strings, which is not suitable for many drivers since they want the
driver data associated with each compatible.
Add two wrappers, similar to existing of_device_get_match_data():
1. of_machine_device_match() doing only matching against 'struct
of_device_id' and returning bool.
2. of_machine_get_match_data() doing the matching and returning
associated driver data for found compatible.
Best regards,
Krzysztof
---
Krzysztof Kozlowski (13):
of: Add wrappers to match root node with OF device ID tables
cpufreq: dt-platdev: Simplify with of_machine_get_match_data()
cpufreq: mediatek: Simplify with of_machine_get_match_data()
cpufreq: sun50i: Simplify with of_machine_device_match()
cpufreq: ti: Simplify with of_machine_device_match()
cpuidle: big_little: Simplify with of_machine_device_match()
firmware: qcom: scm: Simplify with of_machine_device_match()
irqchip/atmel-aic: Simplify with of_machine_get_match_data()
platform: surface: Simplify with of_machine_get_match_data()
powercap: dtpm: Simplify with of_machine_get_match_data()
soc: qcom: Simplify with of_machine_get_match_data()
soc: qcom: ubwc: Simplify with of_machine_get_match_data()
soc: tegra: Simplify with of_machine_device_match()
drivers/cpufreq/cpufreq-dt-platdev.c | 15 ++-----
drivers/cpufreq/mediatek-cpufreq.c | 12 +-----
drivers/cpufreq/sun50i-cpufreq-nvmem.c | 11 +----
drivers/cpufreq/ti-cpufreq.c | 13 +-----
drivers/cpuidle/cpuidle-big_little.c | 11 +----
drivers/firmware/qcom/qcom_scm.c | 17 +-------
drivers/irqchip/irq-atmel-aic-common.c | 15 ++-----
drivers/of/base.c | 47 ++++++++++++++++++++++
.../platform/surface/surface_aggregator_registry.c | 13 +-----
drivers/powercap/dtpm.c | 16 +-------
drivers/soc/qcom/qcom_pd_mapper.c | 17 +-------
drivers/soc/qcom/ubwc_config.c | 14 ++-----
drivers/soc/tegra/common.c | 12 +-----
include/linux/of.h | 13 ++++++
14 files changed, 82 insertions(+), 144 deletions(-)
---
base-commit: e5efebeef746a24f45b98dbdfcf334285848b32a
change-id: 20251106-b4-of-match-matchine-data-4a64bf046814
Best regards,
--
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH 01/13] of: Add wrappers to match root node with OF device ID tables
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-06 19:53 ` Frank Li
2025-11-06 19:07 ` [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
` (12 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Several drivers duplicate same code for getting reference to the root
node, matching it against 'struct of_device_id' table and getting out
the match data from the table entry.
There is a of_machine_compatible_match() wrapper but it takes array of
strings, which is not suitable for many drivers since they want the
driver data associated with each compatible.
Add two wrappers, similar to existing of_device_get_match_data():
1. of_machine_device_match() doing only matching against 'struct
of_device_id' and returning bool.
2. of_machine_get_match_data() doing the matching and returning
associated driver data for found compatible.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
All further patches depend on this.
---
drivers/of/base.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 13 +++++++++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7043acd971a0..0b65039ece53 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -434,6 +434,53 @@ bool of_machine_compatible_match(const char *const *compats)
}
EXPORT_SYMBOL(of_machine_compatible_match);
+/**
+ * of_machine_device_match - Test root of device tree against a of_device_id array
+ * @matches: NULL terminated array of of_device_id match structures to search in
+ *
+ * Returns true if the root node has any of the given compatible values in its
+ * compatible property.
+ */
+bool of_machine_device_match(const struct of_device_id *matches)
+{
+ struct device_node *root;
+ const struct of_device_id *match = NULL;
+
+ root = of_find_node_by_path("/");
+ if (root) {
+ match = of_match_node(matches, root);
+ of_node_put(root);
+ }
+
+ return match != NULL;
+}
+EXPORT_SYMBOL(of_machine_device_match);
+
+/**
+ * of_machine_get_match_data - Tell if root of device tree has a matching of_match structure
+ * @matches: NULL terminated array of of_device_id match structures to search in
+ *
+ * Returns data associated with matched entry or NULL
+ */
+const void *of_machine_get_match_data(const struct of_device_id *matches)
+{
+ const struct of_device_id *match;
+ struct device_node *root;
+
+ root = of_find_node_by_path("/");
+ if (!root)
+ return NULL;
+
+ match = of_match_node(matches, root);
+ of_node_put(root);
+
+ if (!match)
+ return NULL;
+
+ return match->data;
+}
+EXPORT_SYMBOL(of_machine_get_match_data);
+
static bool __of_device_is_status(const struct device_node *device,
const char * const*strings)
{
diff --git a/include/linux/of.h b/include/linux/of.h
index 121a288ca92d..01bb3affcd49 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -407,6 +407,8 @@ extern int of_alias_get_id(const struct device_node *np, const char *stem);
extern int of_alias_get_highest_id(const char *stem);
bool of_machine_compatible_match(const char *const *compats);
+bool of_machine_device_match(const struct of_device_id *matches);
+const void *of_machine_get_match_data(const struct of_device_id *matches);
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
@@ -855,6 +857,17 @@ static inline bool of_machine_compatible_match(const char *const *compats)
return false;
}
+static inline bool of_machine_device_match(const struct of_device_id *matches)
+{
+ return false;
+}
+
+static inline const void *
+of_machine_get_match_data(const struct of_device_id *matches)
+{
+ return NULL;
+}
+
static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
{
return false;
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 01/13] " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 03/13] cpufreq: mediatek: " Krzysztof Kozlowski
` (11 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with two new helpers: of_machine_get_match_data() and
of_machine_device_match().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/cpufreq/cpufreq-dt-platdev.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c
index dc11b62399ad..a1d11ecd1ac8 100644
--- a/drivers/cpufreq/cpufreq-dt-platdev.c
+++ b/drivers/cpufreq/cpufreq-dt-platdev.c
@@ -219,20 +219,13 @@ static bool __init cpu0_node_has_opp_v2_prop(void)
static int __init cpufreq_dt_platdev_init(void)
{
- struct device_node *np __free(device_node) = of_find_node_by_path("/");
- const struct of_device_id *match;
- const void *data = NULL;
+ const void *data;
- if (!np)
- return -ENODEV;
-
- match = of_match_node(allowlist, np);
- if (match) {
- data = match->data;
+ data = of_machine_get_match_data(allowlist);
+ if (data)
goto create_pdev;
- }
- if (cpu0_node_has_opp_v2_prop() && !of_match_node(blocklist, np))
+ if (cpu0_node_has_opp_v2_prop() && !of_machine_device_match(blocklist))
goto create_pdev;
return -ENODEV;
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 03/13] cpufreq: mediatek: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 01/13] " Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
` (10 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/cpufreq/mediatek-cpufreq.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 5d50a231f944..052ca7cd2f4f 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -764,22 +764,14 @@ MODULE_DEVICE_TABLE(of, mtk_cpufreq_machines);
static int __init mtk_cpufreq_driver_init(void)
{
- struct device_node *np;
- const struct of_device_id *match;
const struct mtk_cpufreq_platform_data *data;
int err;
- np = of_find_node_by_path("/");
- if (!np)
- return -ENODEV;
-
- match = of_match_node(mtk_cpufreq_machines, np);
- of_node_put(np);
- if (!match) {
+ data = of_machine_get_match_data(mtk_cpufreq_machines);
+ if (!data) {
pr_debug("Machine is not compatible with mtk-cpufreq\n");
return -ENODEV;
}
- data = match->data;
err = platform_driver_register(&mtk_cpufreq_platdrv);
if (err)
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (2 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 03/13] cpufreq: mediatek: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-07 13:12 ` Chen-Yu Tsai
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 05/13] cpufreq: ti: " Krzysztof Kozlowski
` (9 subsequent siblings)
13 siblings, 2 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node and matching against it with
new of_machine_device_match() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/cpufreq/sun50i-cpufreq-nvmem.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
index 744312a44279..4fffc8e83692 100644
--- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
+++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
@@ -332,13 +332,6 @@ static const struct of_device_id sun50i_cpufreq_match_list[] = {
};
MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list);
-static const struct of_device_id *sun50i_cpufreq_match_node(void)
-{
- struct device_node *np __free(device_node) = of_find_node_by_path("/");
-
- return of_match_node(sun50i_cpufreq_match_list, np);
-}
-
/*
* Since the driver depends on nvmem drivers, which may return EPROBE_DEFER,
* all the real activity is done in the probe, which may be defered as well.
@@ -346,11 +339,9 @@ static const struct of_device_id *sun50i_cpufreq_match_node(void)
*/
static int __init sun50i_cpufreq_init(void)
{
- const struct of_device_id *match;
int ret;
- match = sun50i_cpufreq_match_node();
- if (!match)
+ if (!of_machine_device_match(sun50i_cpufreq_match_list))
return -ENODEV;
ret = platform_driver_register(&sun50i_cpufreq_driver);
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 05/13] cpufreq: ti: Simplify with of_machine_device_match()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (3 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-08 14:38 ` Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 06/13] cpuidle: big_little: " Krzysztof Kozlowski
` (8 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node and matching against it with
new of_machine_device_match() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/cpufreq/ti-cpufreq.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/drivers/cpufreq/ti-cpufreq.c b/drivers/cpufreq/ti-cpufreq.c
index 6ee76f5fe9c5..b59c46a3cbd6 100644
--- a/drivers/cpufreq/ti-cpufreq.c
+++ b/drivers/cpufreq/ti-cpufreq.c
@@ -470,16 +470,6 @@ static const struct of_device_id ti_cpufreq_of_match[] __maybe_unused = {
{},
};
-static const struct of_device_id *ti_cpufreq_match_node(void)
-{
- struct device_node *np __free(device_node) = of_find_node_by_path("/");
- const struct of_device_id *match;
-
- match = of_match_node(ti_cpufreq_of_match, np);
-
- return match;
-}
-
static int ti_cpufreq_probe(struct platform_device *pdev)
{
u32 version[VERSION_COUNT];
@@ -564,8 +554,7 @@ static int __init ti_cpufreq_init(void)
const struct of_device_id *match;
/* Check to ensure we are on a compatible platform */
- match = ti_cpufreq_match_node();
- if (match)
+ if (of_machine_device_match(ti_cpufreq_of_match))
platform_device_register_data(NULL, "ti-cpufreq", -1, match,
sizeof(*match));
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 06/13] cpuidle: big_little: Simplify with of_machine_device_match()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (4 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 05/13] cpufreq: ti: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 07/13] firmware: qcom: scm: " Krzysztof Kozlowski
` (7 subsequent siblings)
13 siblings, 0 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node and matching against it with
new of_machine_device_match() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/cpuidle/cpuidle-big_little.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-big_little.c b/drivers/cpuidle/cpuidle-big_little.c
index 4abba42fcc31..08f6bf2f6409 100644
--- a/drivers/cpuidle/cpuidle-big_little.c
+++ b/drivers/cpuidle/cpuidle-big_little.c
@@ -166,20 +166,11 @@ static const struct of_device_id compatible_machine_match[] = {
static int __init bl_idle_init(void)
{
int ret;
- struct device_node *root = of_find_node_by_path("/");
- const struct of_device_id *match_id;
-
- if (!root)
- return -ENODEV;
/*
* Initialize the driver just for a compliant set of machines
*/
- match_id = of_match_node(compatible_machine_match, root);
-
- of_node_put(root);
-
- if (!match_id)
+ if (!of_machine_device_match(compatible_machine_match))
return -ENODEV;
if (!mcpm_is_available())
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 07/13] firmware: qcom: scm: Simplify with of_machine_device_match()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (5 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 06/13] cpuidle: big_little: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-07 8:45 ` Konrad Dybcio
2025-11-06 19:07 ` [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
` (6 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node and matching against it with
new of_machine_device_match() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/firmware/qcom/qcom_scm.c | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index e777b7cb9b12..1a6f85e463e0 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -2018,21 +2018,6 @@ static const struct of_device_id qcom_scm_qseecom_allowlist[] __maybe_unused = {
{ }
};
-static bool qcom_scm_qseecom_machine_is_allowed(void)
-{
- struct device_node *np;
- bool match;
-
- np = of_find_node_by_path("/");
- if (!np)
- return false;
-
- match = of_match_node(qcom_scm_qseecom_allowlist, np);
- of_node_put(np);
-
- return match;
-}
-
static void qcom_scm_qseecom_free(void *data)
{
struct platform_device *qseecom_dev = data;
@@ -2064,7 +2049,7 @@ static int qcom_scm_qseecom_init(struct qcom_scm *scm)
dev_info(scm->dev, "qseecom: found qseecom with version 0x%x\n", version);
- if (!qcom_scm_qseecom_machine_is_allowed()) {
+ if (!of_machine_device_match(qcom_scm_qseecom_allowlist)) {
dev_info(scm->dev, "qseecom: untested machine, skipping\n");
return 0;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (6 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 07/13] firmware: qcom: scm: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-10 14:10 ` Nicolas Ferre
2025-11-11 21:14 ` Thomas Gleixner
2025-11-06 19:07 ` [PATCH 09/13] platform: surface: " Krzysztof Kozlowski
` (5 subsequent siblings)
13 siblings, 2 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/irqchip/irq-atmel-aic-common.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/irqchip/irq-atmel-aic-common.c b/drivers/irqchip/irq-atmel-aic-common.c
index 3cad30a40c19..e68853815c7a 100644
--- a/drivers/irqchip/irq-atmel-aic-common.c
+++ b/drivers/irqchip/irq-atmel-aic-common.c
@@ -187,20 +187,11 @@ void __init aic_common_rtt_irq_fixup(void)
static void __init aic_common_irq_fixup(const struct of_device_id *matches)
{
- struct device_node *root = of_find_node_by_path("/");
- const struct of_device_id *match;
+ void (*fixup)(void);
- if (!root)
- return;
-
- match = of_match_node(matches, root);
-
- if (match) {
- void (*fixup)(void) = match->data;
+ fixup = of_machine_get_match_data(matches);
+ if (fixup)
fixup();
- }
-
- of_node_put(root);
}
struct irq_domain *__init aic_common_of_init(struct device_node *node,
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 09/13] platform: surface: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (7 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-10 11:49 ` Ilpo Järvinen
2025-11-06 19:07 ` [PATCH 10/13] powercap: dtpm: " Krzysztof Kozlowski
` (4 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/platform/surface/surface_aggregator_registry.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
index a594d5fcfcfd..78ac3a8fbb73 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -491,24 +491,13 @@ static const struct of_device_id ssam_platform_hub_of_match[] __maybe_unused = {
static int ssam_platform_hub_probe(struct platform_device *pdev)
{
const struct software_node **nodes;
- const struct of_device_id *match;
- struct device_node *fdt_root;
struct ssam_controller *ctrl;
struct fwnode_handle *root;
int status;
nodes = (const struct software_node **)acpi_device_get_match_data(&pdev->dev);
if (!nodes) {
- fdt_root = of_find_node_by_path("/");
- if (!fdt_root)
- return -ENODEV;
-
- match = of_match_node(ssam_platform_hub_of_match, fdt_root);
- of_node_put(fdt_root);
- if (!match)
- return -ENODEV;
-
- nodes = (const struct software_node **)match->data;
+ nodes = (const struct software_node **)of_machine_get_match_data(ssam_platform_hub_of_match);
if (!nodes)
return -ENODEV;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 10/13] powercap: dtpm: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (8 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 09/13] platform: surface: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 11/13] soc: qcom: " Krzysztof Kozlowski
` (3 subsequent siblings)
13 siblings, 0 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/powercap/dtpm.c | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c
index f390665743c4..129d55bc705c 100644
--- a/drivers/powercap/dtpm.c
+++ b/drivers/powercap/dtpm.c
@@ -548,9 +548,7 @@ static int dtpm_for_each_child(const struct dtpm_node *hierarchy,
*/
int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table)
{
- const struct of_device_id *match;
const struct dtpm_node *hierarchy;
- struct device_node *np;
int i, ret;
mutex_lock(&dtpm_lock);
@@ -567,19 +565,7 @@ int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table)
goto out_pct;
}
- ret = -ENODEV;
- np = of_find_node_by_path("/");
- if (!np)
- goto out_err;
-
- match = of_match_node(dtpm_match_table, np);
-
- of_node_put(np);
-
- if (!match)
- goto out_err;
-
- hierarchy = match->data;
+ hierarchy = of_machine_get_match_data(dtpm_match_table);
if (!hierarchy) {
ret = -EFAULT;
goto out_err;
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (9 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 10/13] powercap: dtpm: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-07 3:19 ` Dmitry Baryshkov
2025-11-06 19:07 ` [PATCH 12/13] soc: qcom: ubwc: " Krzysztof Kozlowski
` (2 subsequent siblings)
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
index 1bcbe69688d2..07198d44b559 100644
--- a/drivers/soc/qcom/qcom_pd_mapper.c
+++ b/drivers/soc/qcom/qcom_pd_mapper.c
@@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
static struct qcom_pdm_data *qcom_pdm_start(void)
{
const struct qcom_pdm_domain_data * const *domains;
- const struct of_device_id *match;
struct qcom_pdm_data *data;
- struct device_node *root;
int ret, i;
- root = of_find_node_by_path("/");
- if (!root)
- return ERR_PTR(-ENODEV);
-
- match = of_match_node(qcom_pdm_domains, root);
- of_node_put(root);
- if (!match) {
- pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
- return ERR_PTR(-ENODEV);
- }
-
- domains = match->data;
+ domains = of_machine_get_match_data(qcom_pdm_domains);
if (!domains) {
- pr_debug("PDM: no domains\n");
+ pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
return ERR_PTR(-ENODEV);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 12/13] soc: qcom: ubwc: Simplify with of_machine_get_match_data()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (10 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 11/13] soc: qcom: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-07 3:19 ` Dmitry Baryshkov
2025-11-06 19:07 ` [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-07 9:12 ` [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables AngeloGioacchino Del Regno
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node, matching against it and getting
the match data with new of_machine_get_match_data() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/soc/qcom/ubwc_config.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/soc/qcom/ubwc_config.c b/drivers/soc/qcom/ubwc_config.c
index 1c09796163b0..1c25aaf55e52 100644
--- a/drivers/soc/qcom/ubwc_config.c
+++ b/drivers/soc/qcom/ubwc_config.c
@@ -301,21 +301,15 @@ static const struct of_device_id qcom_ubwc_configs[] __maybe_unused = {
const struct qcom_ubwc_cfg_data *qcom_ubwc_config_get_data(void)
{
- const struct of_device_id *match;
- struct device_node *root;
+ const struct qcom_ubwc_cfg_data *data;
- root = of_find_node_by_path("/");
- if (!root)
- return ERR_PTR(-ENODEV);
-
- match = of_match_node(qcom_ubwc_configs, root);
- of_node_put(root);
- if (!match) {
+ data = of_machine_get_match_data(qcom_ubwc_configs);
+ if (!data) {
pr_err("Couldn't find UBWC config data for this platform!\n");
return ERR_PTR(-EINVAL);
}
- return match->data;
+ return data;
}
EXPORT_SYMBOL_GPL(qcom_ubwc_config_get_data);
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match()
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (11 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 12/13] soc: qcom: ubwc: " Krzysztof Kozlowski
@ 2025-11-06 19:07 ` Krzysztof Kozlowski
2025-11-07 10:41 ` Jon Hunter
2025-11-07 9:12 ` [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables AngeloGioacchino Del Regno
13 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-06 19:07 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
Replace open-coded getting root OF node and matching against it with
new of_machine_device_match() helper.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Depends on the first OF patch.
---
drivers/soc/tegra/common.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/soc/tegra/common.c b/drivers/soc/tegra/common.c
index dff6d5ef4e46..d82b7670abb7 100644
--- a/drivers/soc/tegra/common.c
+++ b/drivers/soc/tegra/common.c
@@ -27,17 +27,7 @@ static const struct of_device_id tegra_machine_match[] = {
bool soc_is_tegra(void)
{
- const struct of_device_id *match;
- struct device_node *root;
-
- root = of_find_node_by_path("/");
- if (!root)
- return false;
-
- match = of_match_node(tegra_machine_match, root);
- of_node_put(root);
-
- return match != NULL;
+ return of_machine_device_match(tegra_machine_match);
}
static int tegra_core_dev_init_opp_state(struct device *dev)
--
2.48.1
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH 01/13] of: Add wrappers to match root node with OF device ID tables
2025-11-06 19:07 ` [PATCH 01/13] " Krzysztof Kozlowski
@ 2025-11-06 19:53 ` Frank Li
2025-11-07 7:00 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Frank Li @ 2025-11-06 19:53 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Thu, Nov 06, 2025 at 08:07:08PM +0100, Krzysztof Kozlowski wrote:
> Several drivers duplicate same code for getting reference to the root
> node, matching it against 'struct of_device_id' table and getting out
> the match data from the table entry.
>
> There is a of_machine_compatible_match() wrapper but it takes array of
> strings, which is not suitable for many drivers since they want the
> driver data associated with each compatible.
>
> Add two wrappers, similar to existing of_device_get_match_data():
> 1. of_machine_device_match() doing only matching against 'struct
> of_device_id' and returning bool.
> 2. of_machine_get_match_data() doing the matching and returning
> associated driver data for found compatible.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> All further patches depend on this.
> ---
...
>
> +/**
> + * of_machine_device_match - Test root of device tree against a of_device_id array
> + * @matches: NULL terminated array of of_device_id match structures to search in
> + *
> + * Returns true if the root node has any of the given compatible values in its
> + * compatible property.
> + */
> +bool of_machine_device_match(const struct of_device_id *matches)
Will it be more useful if pass down path
of_machine_device_match(const char* path, const struct of_device_id *matches)
caller just pass "\", or NULL point as root
> +{
> + struct device_node *root;
> + const struct of_device_id *match = NULL;
> +
> + root = of_find_node_by_path("/");
Use clean up will simplify code
struct device_node *root = __free(device_node) = of_find_node_by_path("/");
Frank
> + if (root) {
> + match = of_match_node(matches, root);
> + of_node_put(root);
> + }
> +
> + return match != NULL;
> +}
> +EXPORT_SYMBOL(of_machine_device_match);
> +
...
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 11/13] soc: qcom: " Krzysztof Kozlowski
@ 2025-11-07 3:19 ` Dmitry Baryshkov
2025-11-07 7:02 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2025-11-07 3:19 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Depends on the first OF patch.
> ---
> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
> 1 file changed, 2 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
> index 1bcbe69688d2..07198d44b559 100644
> --- a/drivers/soc/qcom/qcom_pd_mapper.c
> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
> static struct qcom_pdm_data *qcom_pdm_start(void)
> {
> const struct qcom_pdm_domain_data * const *domains;
> - const struct of_device_id *match;
> struct qcom_pdm_data *data;
> - struct device_node *root;
> int ret, i;
>
> - root = of_find_node_by_path("/");
> - if (!root)
> - return ERR_PTR(-ENODEV);
> -
> - match = of_match_node(qcom_pdm_domains, root);
> - of_node_put(root);
> - if (!match) {
> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
> - return ERR_PTR(-ENODEV);
> - }
> -
> - domains = match->data;
> + domains = of_machine_get_match_data(qcom_pdm_domains);
> if (!domains) {
> - pr_debug("PDM: no domains\n");
> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
> return ERR_PTR(-ENODEV);
> }
Here you are mixing two cases:
- There is not match in the table (in which case the driver should print
a notice)
- There is a match in the table, but the data is NULL (the platform
doesn't have PDM domains). In this case there should be no notice.
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 12/13] soc: qcom: ubwc: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 12/13] soc: qcom: ubwc: " Krzysztof Kozlowski
@ 2025-11-07 3:19 ` Dmitry Baryshkov
0 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2025-11-07 3:19 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Thu, Nov 06, 2025 at 08:07:19PM +0100, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Depends on the first OF patch.
> ---
> drivers/soc/qcom/ubwc_config.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 01/13] of: Add wrappers to match root node with OF device ID tables
2025-11-06 19:53 ` Frank Li
@ 2025-11-07 7:00 ` Krzysztof Kozlowski
2025-11-07 17:11 ` Frank Li
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-07 7:00 UTC (permalink / raw)
To: Frank Li, Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 06/11/2025 20:53, Frank Li wrote:
> On Thu, Nov 06, 2025 at 08:07:08PM +0100, Krzysztof Kozlowski wrote:
>> Several drivers duplicate same code for getting reference to the root
>> node, matching it against 'struct of_device_id' table and getting out
>> the match data from the table entry.
>>
>> There is a of_machine_compatible_match() wrapper but it takes array of
>> strings, which is not suitable for many drivers since they want the
>> driver data associated with each compatible.
>>
>> Add two wrappers, similar to existing of_device_get_match_data():
>> 1. of_machine_device_match() doing only matching against 'struct
>> of_device_id' and returning bool.
>> 2. of_machine_get_match_data() doing the matching and returning
>> associated driver data for found compatible.
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>> ---
>>
>> All further patches depend on this.
>> ---
>
> ...
>>
>> +/**
>> + * of_machine_device_match - Test root of device tree against a of_device_id array
>> + * @matches: NULL terminated array of of_device_id match structures to search in
>> + *
>> + * Returns true if the root node has any of the given compatible values in its
>> + * compatible property.
>> + */
>> +bool of_machine_device_match(const struct of_device_id *matches)
>
> Will it be more useful if pass down path
Path is fixed, there is no point to pass it. If you claim otherwise,
please bring example what benefits would it bring, instead of just
asking nitpicking questions.
>
> of_machine_device_match(const char* path, const struct of_device_id *matches)
>
> caller just pass "\", or NULL point as root
>
>> +{
>> + struct device_node *root;
>> + const struct of_device_id *match = NULL;
>> +
>> + root = of_find_node_by_path("/");
>
> Use clean up will simplify code
>
> struct device_node *root = __free(device_node) = of_find_node_by_path("/");
Not much difference. Look at existing code first. This should not
introduce different style.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-07 3:19 ` Dmitry Baryshkov
@ 2025-11-07 7:02 ` Krzysztof Kozlowski
2025-11-07 7:08 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-07 7:02 UTC (permalink / raw)
To: Dmitry Baryshkov, Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 07/11/2025 04:19, Dmitry Baryshkov wrote:
> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
>> Replace open-coded getting root OF node, matching against it and getting
>> the match data with new of_machine_get_match_data() helper.
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>
>> ---
>>
>> Depends on the first OF patch.
>> ---
>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
>> 1 file changed, 2 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
>> index 1bcbe69688d2..07198d44b559 100644
>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
>> static struct qcom_pdm_data *qcom_pdm_start(void)
>> {
>> const struct qcom_pdm_domain_data * const *domains;
>> - const struct of_device_id *match;
>> struct qcom_pdm_data *data;
>> - struct device_node *root;
>> int ret, i;
>>
>> - root = of_find_node_by_path("/");
>> - if (!root)
>> - return ERR_PTR(-ENODEV);
>> -
>> - match = of_match_node(qcom_pdm_domains, root);
>> - of_node_put(root);
>> - if (!match) {
>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
>> - return ERR_PTR(-ENODEV);
>> - }
>> -
>> - domains = match->data;
>> + domains = of_machine_get_match_data(qcom_pdm_domains);
>> if (!domains) {
>> - pr_debug("PDM: no domains\n");
>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
>> return ERR_PTR(-ENODEV);
>> }
>
> Here you are mixing two cases:
> - There is not match in the table (in which case the driver should print
> a notice)
>
> - There is a match in the table, but the data is NULL (the platform
> doesn't have PDM domains). In this case there should be no notice.
Why? Existing code printed notice in both cases. Why refactoring which
tries to keep code functionally equivalent should change it?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-07 7:02 ` Krzysztof Kozlowski
@ 2025-11-07 7:08 ` Krzysztof Kozlowski
2025-11-07 14:23 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-07 7:08 UTC (permalink / raw)
To: Krzysztof Kozlowski, Dmitry Baryshkov
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 07/11/2025 08:02, Krzysztof Kozlowski wrote:
> On 07/11/2025 04:19, Dmitry Baryshkov wrote:
>> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
>>> Replace open-coded getting root OF node, matching against it and getting
>>> the match data with new of_machine_get_match_data() helper.
>>>
>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>
>>> ---
>>>
>>> Depends on the first OF patch.
>>> ---
>>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
>>> 1 file changed, 2 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
>>> index 1bcbe69688d2..07198d44b559 100644
>>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
>>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
>>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
>>> static struct qcom_pdm_data *qcom_pdm_start(void)
>>> {
>>> const struct qcom_pdm_domain_data * const *domains;
>>> - const struct of_device_id *match;
>>> struct qcom_pdm_data *data;
>>> - struct device_node *root;
>>> int ret, i;
>>>
>>> - root = of_find_node_by_path("/");
>>> - if (!root)
>>> - return ERR_PTR(-ENODEV);
>>> -
>>> - match = of_match_node(qcom_pdm_domains, root);
>>> - of_node_put(root);
>>> - if (!match) {
>>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
>>> - return ERR_PTR(-ENODEV);
>>> - }
>>> -
>>> - domains = match->data;
>>> + domains = of_machine_get_match_data(qcom_pdm_domains);
>>> if (!domains) {
>>> - pr_debug("PDM: no domains\n");
>>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
>>> return ERR_PTR(-ENODEV);
>>> }
>>
>> Here you are mixing two cases:
>> - There is not match in the table (in which case the driver should print
>> a notice)
>>
>> - There is a match in the table, but the data is NULL (the platform
>> doesn't have PDM domains). In this case there should be no notice.
>
>
> Why? Existing code printed notice in both cases. Why refactoring which
> tries to keep code functionally equivalent should change it?
Ah, you mean there was a debug before. Well, then I am a bit confused
because table has entries without data (so expected condition) but old
code returned ERRNO in such case - so unexpected condition.
Wail failing the probe on expected condition?
Unless it is not really expected and notice in second case is valid as well.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 07/13] firmware: qcom: scm: Simplify with of_machine_device_match()
2025-11-06 19:07 ` [PATCH 07/13] firmware: qcom: scm: " Krzysztof Kozlowski
@ 2025-11-07 8:45 ` Konrad Dybcio
0 siblings, 0 replies; 36+ messages in thread
From: Konrad Dybcio @ 2025-11-07 8:45 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra
On 11/6/25 8:07 PM, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node and matching against it with
> new of_machine_device_match() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Konrad
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
` (12 preceding siblings ...)
2025-11-06 19:07 ` [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match() Krzysztof Kozlowski
@ 2025-11-07 9:12 ` AngeloGioacchino Del Regno
13 siblings, 0 replies; 36+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-11-07 9:12 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra
Il 06/11/25 20:07, Krzysztof Kozlowski ha scritto:
> Dependency/merging
> ==================
> All patches depend on the first patch, thus everything could go via
> Rob's tree with people's acks.
>
> Description
> ===========
> Several drivers duplicate same code for getting reference to the root
> node, matching it against 'struct of_device_id' table and getting out
> the match data from the table entry.
>
> There is a of_machine_compatible_match() wrapper but it takes array of
> strings, which is not suitable for many drivers since they want the
> driver data associated with each compatible.
>
> Add two wrappers, similar to existing of_device_get_match_data():
> 1. of_machine_device_match() doing only matching against 'struct
> of_device_id' and returning bool.
> 2. of_machine_get_match_data() doing the matching and returning
> associated driver data for found compatible.
>
> Best regards,
> Krzysztof
>
Makes sense. Whole series is
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cheers!
Angelo
> ---
> Krzysztof Kozlowski (13):
> of: Add wrappers to match root node with OF device ID tables
> cpufreq: dt-platdev: Simplify with of_machine_get_match_data()
> cpufreq: mediatek: Simplify with of_machine_get_match_data()
> cpufreq: sun50i: Simplify with of_machine_device_match()
> cpufreq: ti: Simplify with of_machine_device_match()
> cpuidle: big_little: Simplify with of_machine_device_match()
> firmware: qcom: scm: Simplify with of_machine_device_match()
> irqchip/atmel-aic: Simplify with of_machine_get_match_data()
> platform: surface: Simplify with of_machine_get_match_data()
> powercap: dtpm: Simplify with of_machine_get_match_data()
> soc: qcom: Simplify with of_machine_get_match_data()
> soc: qcom: ubwc: Simplify with of_machine_get_match_data()
> soc: tegra: Simplify with of_machine_device_match()
>
> drivers/cpufreq/cpufreq-dt-platdev.c | 15 ++-----
> drivers/cpufreq/mediatek-cpufreq.c | 12 +-----
> drivers/cpufreq/sun50i-cpufreq-nvmem.c | 11 +----
> drivers/cpufreq/ti-cpufreq.c | 13 +-----
> drivers/cpuidle/cpuidle-big_little.c | 11 +----
> drivers/firmware/qcom/qcom_scm.c | 17 +-------
> drivers/irqchip/irq-atmel-aic-common.c | 15 ++-----
> drivers/of/base.c | 47 ++++++++++++++++++++++
> .../platform/surface/surface_aggregator_registry.c | 13 +-----
> drivers/powercap/dtpm.c | 16 +-------
> drivers/soc/qcom/qcom_pd_mapper.c | 17 +-------
> drivers/soc/qcom/ubwc_config.c | 14 ++-----
> drivers/soc/tegra/common.c | 12 +-----
> include/linux/of.h | 13 ++++++
> 14 files changed, 82 insertions(+), 144 deletions(-)
> ---
> base-commit: e5efebeef746a24f45b98dbdfcf334285848b32a
> change-id: 20251106-b4-of-match-matchine-data-4a64bf046814
>
> Best regards,
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match()
2025-11-06 19:07 ` [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match() Krzysztof Kozlowski
@ 2025-11-07 10:41 ` Jon Hunter
0 siblings, 0 replies; 36+ messages in thread
From: Jon Hunter @ 2025-11-07 10:41 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra
On 06/11/2025 19:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node and matching against it with
> new of_machine_device_match() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Depends on the first OF patch.
> ---
> drivers/soc/tegra/common.c | 12 +-----------
> 1 file changed, 1 insertion(+), 11 deletions(-)
>
> diff --git a/drivers/soc/tegra/common.c b/drivers/soc/tegra/common.c
> index dff6d5ef4e46..d82b7670abb7 100644
> --- a/drivers/soc/tegra/common.c
> +++ b/drivers/soc/tegra/common.c
> @@ -27,17 +27,7 @@ static const struct of_device_id tegra_machine_match[] = {
>
> bool soc_is_tegra(void)
> {
> - const struct of_device_id *match;
> - struct device_node *root;
> -
> - root = of_find_node_by_path("/");
> - if (!root)
> - return false;
> -
> - match = of_match_node(tegra_machine_match, root);
> - of_node_put(root);
> -
> - return match != NULL;
> + return of_machine_device_match(tegra_machine_match);
> }
>
> static int tegra_core_dev_init_opp_state(struct device *dev)
>
Looks good to me ...
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Thanks
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match()
2025-11-06 19:07 ` [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
@ 2025-11-07 13:12 ` Chen-Yu Tsai
2025-11-10 11:07 ` Viresh Kumar
1 sibling, 0 replies; 36+ messages in thread
From: Chen-Yu Tsai @ 2025-11-07 13:12 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Fri, Nov 7, 2025 at 4:08 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> Replace open-coded getting root OF node and matching against it with
> new of_machine_device_match() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Chen-Yu Tsai <wens@kernel.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-07 7:08 ` Krzysztof Kozlowski
@ 2025-11-07 14:23 ` Dmitry Baryshkov
2025-11-07 14:58 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2025-11-07 14:23 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Fri, Nov 07, 2025 at 08:08:28AM +0100, Krzysztof Kozlowski wrote:
> On 07/11/2025 08:02, Krzysztof Kozlowski wrote:
> > On 07/11/2025 04:19, Dmitry Baryshkov wrote:
> >> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
> >>> Replace open-coded getting root OF node, matching against it and getting
> >>> the match data with new of_machine_get_match_data() helper.
> >>>
> >>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >>>
> >>> ---
> >>>
> >>> Depends on the first OF patch.
> >>> ---
> >>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
> >>> 1 file changed, 2 insertions(+), 15 deletions(-)
> >>>
> >>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
> >>> index 1bcbe69688d2..07198d44b559 100644
> >>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
> >>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
> >>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
> >>> static struct qcom_pdm_data *qcom_pdm_start(void)
> >>> {
> >>> const struct qcom_pdm_domain_data * const *domains;
> >>> - const struct of_device_id *match;
> >>> struct qcom_pdm_data *data;
> >>> - struct device_node *root;
> >>> int ret, i;
> >>>
> >>> - root = of_find_node_by_path("/");
> >>> - if (!root)
> >>> - return ERR_PTR(-ENODEV);
> >>> -
> >>> - match = of_match_node(qcom_pdm_domains, root);
> >>> - of_node_put(root);
> >>> - if (!match) {
> >>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
> >>> - return ERR_PTR(-ENODEV);
> >>> - }
> >>> -
> >>> - domains = match->data;
> >>> + domains = of_machine_get_match_data(qcom_pdm_domains);
> >>> if (!domains) {
> >>> - pr_debug("PDM: no domains\n");
> >>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
> >>> return ERR_PTR(-ENODEV);
> >>> }
> >>
> >> Here you are mixing two cases:
> >> - There is not match in the table (in which case the driver should print
> >> a notice)
> >>
> >> - There is a match in the table, but the data is NULL (the platform
> >> doesn't have PDM domains). In this case there should be no notice.
> >
> >
> > Why? Existing code printed notice in both cases. Why refactoring which
> > tries to keep code functionally equivalent should change it?
>
> Ah, you mean there was a debug before. Well, then I am a bit confused
> because table has entries without data (so expected condition) but old
> code returned ERRNO in such case - so unexpected condition.
>
> Wail failing the probe on expected condition?
>
> Unless it is not really expected and notice in second case is valid as well.
If we know that there are no domains on the platform, then the notice
definitely doesn't apply. Failing the probe is a separate topic. The
rest of the code expects that _qcom_pdm_data is not NULL.
>
>
> Best regards,
> Krzysztof
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-07 14:23 ` Dmitry Baryshkov
@ 2025-11-07 14:58 ` Krzysztof Kozlowski
2025-11-08 16:31 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-07 14:58 UTC (permalink / raw)
To: Dmitry Baryshkov, Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 07/11/2025 15:23, Dmitry Baryshkov wrote:
> On Fri, Nov 07, 2025 at 08:08:28AM +0100, Krzysztof Kozlowski wrote:
>> On 07/11/2025 08:02, Krzysztof Kozlowski wrote:
>>> On 07/11/2025 04:19, Dmitry Baryshkov wrote:
>>>> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
>>>>> Replace open-coded getting root OF node, matching against it and getting
>>>>> the match data with new of_machine_get_match_data() helper.
>>>>>
>>>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>>>
>>>>> ---
>>>>>
>>>>> Depends on the first OF patch.
>>>>> ---
>>>>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
>>>>> 1 file changed, 2 insertions(+), 15 deletions(-)
>>>>>
>>>>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
>>>>> index 1bcbe69688d2..07198d44b559 100644
>>>>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
>>>>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
>>>>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
>>>>> static struct qcom_pdm_data *qcom_pdm_start(void)
>>>>> {
>>>>> const struct qcom_pdm_domain_data * const *domains;
>>>>> - const struct of_device_id *match;
>>>>> struct qcom_pdm_data *data;
>>>>> - struct device_node *root;
>>>>> int ret, i;
>>>>>
>>>>> - root = of_find_node_by_path("/");
>>>>> - if (!root)
>>>>> - return ERR_PTR(-ENODEV);
>>>>> -
>>>>> - match = of_match_node(qcom_pdm_domains, root);
>>>>> - of_node_put(root);
>>>>> - if (!match) {
>>>>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
>>>>> - return ERR_PTR(-ENODEV);
>>>>> - }
>>>>> -
>>>>> - domains = match->data;
>>>>> + domains = of_machine_get_match_data(qcom_pdm_domains);
>>>>> if (!domains) {
>>>>> - pr_debug("PDM: no domains\n");
>>>>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
>>>>> return ERR_PTR(-ENODEV);
>>>>> }
>>>>
>>>> Here you are mixing two cases:
>>>> - There is not match in the table (in which case the driver should print
>>>> a notice)
>>>>
>>>> - There is a match in the table, but the data is NULL (the platform
>>>> doesn't have PDM domains). In this case there should be no notice.
>>>
>>>
>>> Why? Existing code printed notice in both cases. Why refactoring which
>>> tries to keep code functionally equivalent should change it?
>>
>> Ah, you mean there was a debug before. Well, then I am a bit confused
>> because table has entries without data (so expected condition) but old
>> code returned ERRNO in such case - so unexpected condition.
>>
>> Wail failing the probe on expected condition?
>>
>> Unless it is not really expected and notice in second case is valid as well.
>
> If we know that there are no domains on the platform, then the notice
> definitely doesn't apply. Failing the probe is a separate topic. The
> rest of the code expects that _qcom_pdm_data is not NULL.
I hoped that separate topic would be the reason, after commit msg
adjustments, to keep this change, but if you insist that this must stay
debug, then this patch should be just dropped because it is impossible
to achieve with current helpers.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 01/13] of: Add wrappers to match root node with OF device ID tables
2025-11-07 7:00 ` Krzysztof Kozlowski
@ 2025-11-07 17:11 ` Frank Li
0 siblings, 0 replies; 36+ messages in thread
From: Frank Li @ 2025-11-07 17:11 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Fri, Nov 07, 2025 at 08:00:53AM +0100, Krzysztof Kozlowski wrote:
> On 06/11/2025 20:53, Frank Li wrote:
> > On Thu, Nov 06, 2025 at 08:07:08PM +0100, Krzysztof Kozlowski wrote:
> >> Several drivers duplicate same code for getting reference to the root
> >> node, matching it against 'struct of_device_id' table and getting out
> >> the match data from the table entry.
> >>
> >> There is a of_machine_compatible_match() wrapper but it takes array of
> >> strings, which is not suitable for many drivers since they want the
> >> driver data associated with each compatible.
> >>
> >> Add two wrappers, similar to existing of_device_get_match_data():
> >> 1. of_machine_device_match() doing only matching against 'struct
> >> of_device_id' and returning bool.
> >> 2. of_machine_get_match_data() doing the matching and returning
> >> associated driver data for found compatible.
> >>
> >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >>
> >> ---
> >>
> >> All further patches depend on this.
> >> ---
> >
> > ...
> >>
> >> +/**
> >> + * of_machine_device_match - Test root of device tree against a of_device_id array
> >> + * @matches: NULL terminated array of of_device_id match structures to search in
> >> + *
> >> + * Returns true if the root node has any of the given compatible values in its
> >> + * compatible property.
> >> + */
> >> +bool of_machine_device_match(const struct of_device_id *matches)
> >
> > Will it be more useful if pass down path
>
> Path is fixed, there is no point to pass it. If you claim otherwise,
> please bring example what benefits would it bring, instead of just
> asking nitpicking questions.
You design new APIs, which should be used more widely. Now there are not
such user case yet, but just avoid need rename again when new case add if
just little bits improve here. Of course, the policy is that add it when
needs. But keep some extentable also negotiable.
>
> >
> > of_machine_device_match(const char* path, const struct of_device_id *matches)
> >
> > caller just pass "\", or NULL point as root
> >
> >> +{
> >> + struct device_node *root;
> >> + const struct of_device_id *match = NULL;
> >> +
> >> + root = of_find_node_by_path("/");
> >
> > Use clean up will simplify code
> >
> > struct device_node *root = __free(device_node) = of_find_node_by_path("/");
> Not much difference. Look at existing code first. This should not
> introduce different style.
__free() already used at base.c. It is not necessary to align with what
will cleanup's code. I know it is little improvement, but code will be more
clean and simple.
Frank
>
> Best regards,
> Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 05/13] cpufreq: ti: Simplify with of_machine_device_match()
2025-11-06 19:07 ` [PATCH 05/13] cpufreq: ti: " Krzysztof Kozlowski
@ 2025-11-08 14:38 ` Krzysztof Kozlowski
0 siblings, 0 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-08 14:38 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra
On 06/11/2025 20:07, Krzysztof Kozlowski wrote:
> static int ti_cpufreq_probe(struct platform_device *pdev)
> {
> u32 version[VERSION_COUNT];
> @@ -564,8 +554,7 @@ static int __init ti_cpufreq_init(void)
> const struct of_device_id *match;
>
> /* Check to ensure we are on a compatible platform */
> - match = ti_cpufreq_match_node();
> - if (match)
> + if (of_machine_device_match(ti_cpufreq_of_match))
> platform_device_register_data(NULL, "ti-cpufreq", -1, match,
> sizeof(*match));
This is obviously wrong patch... weird my W=1 builds did not flag it.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-07 14:58 ` Krzysztof Kozlowski
@ 2025-11-08 16:31 ` Dmitry Baryshkov
2025-11-09 19:06 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2025-11-08 16:31 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On Fri, Nov 07, 2025 at 03:58:26PM +0100, Krzysztof Kozlowski wrote:
> On 07/11/2025 15:23, Dmitry Baryshkov wrote:
> > On Fri, Nov 07, 2025 at 08:08:28AM +0100, Krzysztof Kozlowski wrote:
> >> On 07/11/2025 08:02, Krzysztof Kozlowski wrote:
> >>> On 07/11/2025 04:19, Dmitry Baryshkov wrote:
> >>>> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
> >>>>> Replace open-coded getting root OF node, matching against it and getting
> >>>>> the match data with new of_machine_get_match_data() helper.
> >>>>>
> >>>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >>>>>
> >>>>> ---
> >>>>>
> >>>>> Depends on the first OF patch.
> >>>>> ---
> >>>>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
> >>>>> 1 file changed, 2 insertions(+), 15 deletions(-)
> >>>>>
> >>>>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
> >>>>> index 1bcbe69688d2..07198d44b559 100644
> >>>>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
> >>>>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
> >>>>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
> >>>>> static struct qcom_pdm_data *qcom_pdm_start(void)
> >>>>> {
> >>>>> const struct qcom_pdm_domain_data * const *domains;
> >>>>> - const struct of_device_id *match;
> >>>>> struct qcom_pdm_data *data;
> >>>>> - struct device_node *root;
> >>>>> int ret, i;
> >>>>>
> >>>>> - root = of_find_node_by_path("/");
> >>>>> - if (!root)
> >>>>> - return ERR_PTR(-ENODEV);
> >>>>> -
> >>>>> - match = of_match_node(qcom_pdm_domains, root);
> >>>>> - of_node_put(root);
> >>>>> - if (!match) {
> >>>>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
> >>>>> - return ERR_PTR(-ENODEV);
> >>>>> - }
> >>>>> -
> >>>>> - domains = match->data;
> >>>>> + domains = of_machine_get_match_data(qcom_pdm_domains);
> >>>>> if (!domains) {
> >>>>> - pr_debug("PDM: no domains\n");
> >>>>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
> >>>>> return ERR_PTR(-ENODEV);
> >>>>> }
> >>>>
> >>>> Here you are mixing two cases:
> >>>> - There is not match in the table (in which case the driver should print
> >>>> a notice)
> >>>>
> >>>> - There is a match in the table, but the data is NULL (the platform
> >>>> doesn't have PDM domains). In this case there should be no notice.
> >>>
> >>>
> >>> Why? Existing code printed notice in both cases. Why refactoring which
> >>> tries to keep code functionally equivalent should change it?
> >>
> >> Ah, you mean there was a debug before. Well, then I am a bit confused
> >> because table has entries without data (so expected condition) but old
> >> code returned ERRNO in such case - so unexpected condition.
> >>
> >> Wail failing the probe on expected condition?
> >>
> >> Unless it is not really expected and notice in second case is valid as well.
> >
> > If we know that there are no domains on the platform, then the notice
> > definitely doesn't apply. Failing the probe is a separate topic. The
> > rest of the code expects that _qcom_pdm_data is not NULL.
>
> I hoped that separate topic would be the reason, after commit msg
> adjustments, to keep this change, but if you insist that this must stay
> debug, then this patch should be just dropped because it is impossible
> to achieve with current helpers.
Having the same pr_notice would be misleading: we point users to running
userspace daemon, while we _know_ that the daemon is useless because
there are no PDs. One of the ways to solve it would be to add extra
wrapping, so that the data in the match table is never NULL.
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 11/13] soc: qcom: Simplify with of_machine_get_match_data()
2025-11-08 16:31 ` Dmitry Baryshkov
@ 2025-11-09 19:06 ` Krzysztof Kozlowski
0 siblings, 0 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-09 19:06 UTC (permalink / raw)
To: Dmitry Baryshkov, Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 08/11/2025 17:31, Dmitry Baryshkov wrote:
> On Fri, Nov 07, 2025 at 03:58:26PM +0100, Krzysztof Kozlowski wrote:
>> On 07/11/2025 15:23, Dmitry Baryshkov wrote:
>>> On Fri, Nov 07, 2025 at 08:08:28AM +0100, Krzysztof Kozlowski wrote:
>>>> On 07/11/2025 08:02, Krzysztof Kozlowski wrote:
>>>>> On 07/11/2025 04:19, Dmitry Baryshkov wrote:
>>>>>> On Thu, Nov 06, 2025 at 08:07:18PM +0100, Krzysztof Kozlowski wrote:
>>>>>>> Replace open-coded getting root OF node, matching against it and getting
>>>>>>> the match data with new of_machine_get_match_data() helper.
>>>>>>>
>>>>>>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>>>>>>>
>>>>>>> ---
>>>>>>>
>>>>>>> Depends on the first OF patch.
>>>>>>> ---
>>>>>>> drivers/soc/qcom/qcom_pd_mapper.c | 17 ++---------------
>>>>>>> 1 file changed, 2 insertions(+), 15 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/soc/qcom/qcom_pd_mapper.c b/drivers/soc/qcom/qcom_pd_mapper.c
>>>>>>> index 1bcbe69688d2..07198d44b559 100644
>>>>>>> --- a/drivers/soc/qcom/qcom_pd_mapper.c
>>>>>>> +++ b/drivers/soc/qcom/qcom_pd_mapper.c
>>>>>>> @@ -613,25 +613,12 @@ static void qcom_pdm_stop(struct qcom_pdm_data *data)
>>>>>>> static struct qcom_pdm_data *qcom_pdm_start(void)
>>>>>>> {
>>>>>>> const struct qcom_pdm_domain_data * const *domains;
>>>>>>> - const struct of_device_id *match;
>>>>>>> struct qcom_pdm_data *data;
>>>>>>> - struct device_node *root;
>>>>>>> int ret, i;
>>>>>>>
>>>>>>> - root = of_find_node_by_path("/");
>>>>>>> - if (!root)
>>>>>>> - return ERR_PTR(-ENODEV);
>>>>>>> -
>>>>>>> - match = of_match_node(qcom_pdm_domains, root);
>>>>>>> - of_node_put(root);
>>>>>>> - if (!match) {
>>>>>>> - pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
>>>>>>> - return ERR_PTR(-ENODEV);
>>>>>>> - }
>>>>>>> -
>>>>>>> - domains = match->data;
>>>>>>> + domains = of_machine_get_match_data(qcom_pdm_domains);
>>>>>>> if (!domains) {
>>>>>>> - pr_debug("PDM: no domains\n");
>>>>>>> + pr_notice("PDM: no support for the platform or no domains, userspace daemon might be required.\n");
>>>>>>> return ERR_PTR(-ENODEV);
>>>>>>> }
>>>>>>
>>>>>> Here you are mixing two cases:
>>>>>> - There is not match in the table (in which case the driver should print
>>>>>> a notice)
>>>>>>
>>>>>> - There is a match in the table, but the data is NULL (the platform
>>>>>> doesn't have PDM domains). In this case there should be no notice.
>>>>>
>>>>>
>>>>> Why? Existing code printed notice in both cases. Why refactoring which
>>>>> tries to keep code functionally equivalent should change it?
>>>>
>>>> Ah, you mean there was a debug before. Well, then I am a bit confused
>>>> because table has entries without data (so expected condition) but old
>>>> code returned ERRNO in such case - so unexpected condition.
>>>>
>>>> Wail failing the probe on expected condition?
>>>>
>>>> Unless it is not really expected and notice in second case is valid as well.
>>>
>>> If we know that there are no domains on the platform, then the notice
>>> definitely doesn't apply. Failing the probe is a separate topic. The
>>> rest of the code expects that _qcom_pdm_data is not NULL.
>>
>> I hoped that separate topic would be the reason, after commit msg
>> adjustments, to keep this change, but if you insist that this must stay
>> debug, then this patch should be just dropped because it is impossible
>> to achieve with current helpers.
>
> Having the same pr_notice would be misleading: we point users to running
> userspace daemon, while we _know_ that the daemon is useless because
> there are no PDs. One of the ways to solve it would be to add extra
> wrapping, so that the data in the match table is never NULL.
The message does not matter. It still returns ENODEV which is failing
the probe. This leaves error messages in the dmesg already, if pdm is
ever probed for these devices, so my change of debug->notice here
really, really does not matter. Failing of probe is always a failure of
system, so it is not an expected behavior.
Anyway, I will just drop this change as I said.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
@ 2025-11-10 11:07 ` Viresh Kumar
0 siblings, 0 replies; 36+ messages in thread
From: Viresh Kumar @ 2025-11-10 11:07 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 06-11-25, 20:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with two new helpers: of_machine_get_match_data() and
> of_machine_device_match().
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 03/13] cpufreq: mediatek: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 03/13] cpufreq: mediatek: " Krzysztof Kozlowski
@ 2025-11-10 11:07 ` Viresh Kumar
0 siblings, 0 replies; 36+ messages in thread
From: Viresh Kumar @ 2025-11-10 11:07 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 06-11-25, 20:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match()
2025-11-06 19:07 ` [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-07 13:12 ` Chen-Yu Tsai
@ 2025-11-10 11:07 ` Viresh Kumar
1 sibling, 0 replies; 36+ messages in thread
From: Viresh Kumar @ 2025-11-10 11:07 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner, Nicolas Ferre,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter, devicetree, linux-kernel, linux-pm,
linux-arm-kernel, linux-mediatek, linux-sunxi, linux-arm-msm,
platform-driver-x86, linux-tegra
On 06-11-25, 20:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node and matching against it with
> new of_machine_device_match() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 09/13] platform: surface: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 09/13] platform: surface: " Krzysztof Kozlowski
@ 2025-11-10 11:49 ` Ilpo Järvinen
0 siblings, 0 replies; 36+ messages in thread
From: Ilpo Järvinen @ 2025-11-10 11:49 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Rob Herring, Saravana Kannan, Rafael J. Wysocki, Viresh Kumar,
Matthias Brugger, AngeloGioacchino Del Regno, Yangtao Li,
Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi,
Daniel Lezcano, Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Maximilian Luz,
Hans de Goede, Daniel Lezcano, Thierry Reding, Jonathan Hunter,
devicetree, LKML, linux-pm, linux-arm-kernel, linux-mediatek,
linux-sunxi, linux-arm-msm, platform-driver-x86, linux-tegra
[-- Attachment #1: Type: text/plain, Size: 1866 bytes --]
On Thu, 6 Nov 2025, Krzysztof Kozlowski wrote:
Please change the prefixes to:
platform/surface: aggregator_registry: ...
Once that is changed,
Acked-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>
> ---
>
> Depends on the first OF patch.
> ---
> drivers/platform/surface/surface_aggregator_registry.c | 13 +------------
> 1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
> index a594d5fcfcfd..78ac3a8fbb73 100644
> --- a/drivers/platform/surface/surface_aggregator_registry.c
> +++ b/drivers/platform/surface/surface_aggregator_registry.c
> @@ -491,24 +491,13 @@ static const struct of_device_id ssam_platform_hub_of_match[] __maybe_unused = {
> static int ssam_platform_hub_probe(struct platform_device *pdev)
> {
> const struct software_node **nodes;
> - const struct of_device_id *match;
> - struct device_node *fdt_root;
> struct ssam_controller *ctrl;
> struct fwnode_handle *root;
> int status;
>
> nodes = (const struct software_node **)acpi_device_get_match_data(&pdev->dev);
> if (!nodes) {
> - fdt_root = of_find_node_by_path("/");
> - if (!fdt_root)
> - return -ENODEV;
> -
> - match = of_match_node(ssam_platform_hub_of_match, fdt_root);
> - of_node_put(fdt_root);
> - if (!match)
> - return -ENODEV;
> -
> - nodes = (const struct software_node **)match->data;
> + nodes = (const struct software_node **)of_machine_get_match_data(ssam_platform_hub_of_match);
> if (!nodes)
> return -ENODEV;
> }
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
@ 2025-11-10 14:10 ` Nicolas Ferre
2025-11-11 21:14 ` Thomas Gleixner
1 sibling, 0 replies; 36+ messages in thread
From: Nicolas Ferre @ 2025-11-10 14:10 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Thomas Gleixner,
Alexandre Belloni, Claudiu Beznea, Maximilian Luz, Hans de Goede,
Ilpo Järvinen, Daniel Lezcano, Thierry Reding,
Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra
On 06/11/2025 at 20:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Thanks Krzysztof, best regards,
Nicolas
> ---
>
> Depends on the first OF patch.
> ---
> drivers/irqchip/irq-atmel-aic-common.c | 15 +++------------
> 1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/irqchip/irq-atmel-aic-common.c b/drivers/irqchip/irq-atmel-aic-common.c
> index 3cad30a40c19..e68853815c7a 100644
> --- a/drivers/irqchip/irq-atmel-aic-common.c
> +++ b/drivers/irqchip/irq-atmel-aic-common.c
> @@ -187,20 +187,11 @@ void __init aic_common_rtt_irq_fixup(void)
>
> static void __init aic_common_irq_fixup(const struct of_device_id *matches)
> {
> - struct device_node *root = of_find_node_by_path("/");
> - const struct of_device_id *match;
> + void (*fixup)(void);
>
> - if (!root)
> - return;
> -
> - match = of_match_node(matches, root);
> -
> - if (match) {
> - void (*fixup)(void) = match->data;
> + fixup = of_machine_get_match_data(matches);
> + if (fixup)
> fixup();
> - }
> -
> - of_node_put(root);
> }
>
> struct irq_domain *__init aic_common_of_init(struct device_node *node,
>
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data()
2025-11-06 19:07 ` [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
2025-11-10 14:10 ` Nicolas Ferre
@ 2025-11-11 21:14 ` Thomas Gleixner
1 sibling, 0 replies; 36+ messages in thread
From: Thomas Gleixner @ 2025-11-11 21:14 UTC (permalink / raw)
To: Krzysztof Kozlowski, Rob Herring, Saravana Kannan,
Rafael J. Wysocki, Viresh Kumar, Matthias Brugger,
AngeloGioacchino Del Regno, Yangtao Li, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, Lorenzo Pieralisi, Daniel Lezcano,
Bjorn Andersson, Konrad Dybcio, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Maximilian Luz, Hans de Goede, Ilpo Järvinen,
Daniel Lezcano, Thierry Reding, Jonathan Hunter
Cc: devicetree, linux-kernel, linux-pm, linux-arm-kernel,
linux-mediatek, linux-sunxi, linux-arm-msm, platform-driver-x86,
linux-tegra, Krzysztof Kozlowski
On Thu, Nov 06 2025 at 20:07, Krzysztof Kozlowski wrote:
> Replace open-coded getting root OF node, matching against it and getting
> the match data with new of_machine_get_match_data() helper.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2025-11-11 21:14 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 19:07 [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 01/13] " Krzysztof Kozlowski
2025-11-06 19:53 ` Frank Li
2025-11-07 7:00 ` Krzysztof Kozlowski
2025-11-07 17:11 ` Frank Li
2025-11-06 19:07 ` [PATCH 02/13] cpufreq: dt-platdev: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 03/13] cpufreq: mediatek: " Krzysztof Kozlowski
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 04/13] cpufreq: sun50i: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-07 13:12 ` Chen-Yu Tsai
2025-11-10 11:07 ` Viresh Kumar
2025-11-06 19:07 ` [PATCH 05/13] cpufreq: ti: " Krzysztof Kozlowski
2025-11-08 14:38 ` Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 06/13] cpuidle: big_little: " Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 07/13] firmware: qcom: scm: " Krzysztof Kozlowski
2025-11-07 8:45 ` Konrad Dybcio
2025-11-06 19:07 ` [PATCH 08/13] irqchip/atmel-aic: Simplify with of_machine_get_match_data() Krzysztof Kozlowski
2025-11-10 14:10 ` Nicolas Ferre
2025-11-11 21:14 ` Thomas Gleixner
2025-11-06 19:07 ` [PATCH 09/13] platform: surface: " Krzysztof Kozlowski
2025-11-10 11:49 ` Ilpo Järvinen
2025-11-06 19:07 ` [PATCH 10/13] powercap: dtpm: " Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 11/13] soc: qcom: " Krzysztof Kozlowski
2025-11-07 3:19 ` Dmitry Baryshkov
2025-11-07 7:02 ` Krzysztof Kozlowski
2025-11-07 7:08 ` Krzysztof Kozlowski
2025-11-07 14:23 ` Dmitry Baryshkov
2025-11-07 14:58 ` Krzysztof Kozlowski
2025-11-08 16:31 ` Dmitry Baryshkov
2025-11-09 19:06 ` Krzysztof Kozlowski
2025-11-06 19:07 ` [PATCH 12/13] soc: qcom: ubwc: " Krzysztof Kozlowski
2025-11-07 3:19 ` Dmitry Baryshkov
2025-11-06 19:07 ` [PATCH 13/13] soc: tegra: Simplify with of_machine_device_match() Krzysztof Kozlowski
2025-11-07 10:41 ` Jon Hunter
2025-11-07 9:12 ` [PATCH 00/13] of: Add wrappers to match root node with OF device ID tables AngeloGioacchino Del Regno
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).