Skip to content

of: Add and use of_machine_get_match() helper

Geert Uytterhoeven linux-arm-msm linux-devicetree linux-pm linux-renesas-soc lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7of: Add of_machine_get_match() helperdrivers/of/base.c include/linux/of.h+13 -90 replies
2/7of: Convert to of_machine_get_match()drivers/of/base.c+1 -80 replies
3/7cpufreq: airoha: Convert to of_machine_get_match()drivers/cpufreq/airoha-cpufreq.c+1 -60 replies
4/7cpufreq: qcom-nvmem: Convert to of_machine_get_match()drivers/cpufreq/qcom-cpufreq-nvmem.c+2 -140 replies
5/7cpufreq: ti-cpufreq: Convert to of_machine_get_match()drivers/cpufreq/ti-cpufreq.c+1 -110 replies
6/7soc: qcom: pd-mapper: Convert to of_machine_get_match()drivers/soc/qcom/qcom_pd_mapper.c+1 -72 replies
7/7soc: renesas: Convert to of_machine_get_match()drivers/soc/renesas/renesas-soc.c+1 -13 replies

Reviews trailers per patch

1 of 7 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchViresh KumarKonrad DybcioBjorn Andersson
SeriesA-b
1/7
2/7
3/7
4/7
5/7
6/7R-b A-b
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 0/7] of: Add and use of_machine_get_match() helper

Hi all,

Currently, there are two helpers to match the root compatible value against an of_device_id array:
- of_machine_device_match() returns true if a match is found,
- of_machine_get_match_data() returns the match data if a match is found.
However, there is no helper that returns the actual of_device_id structure corresponding to the match, leading to code duplication in various drivers. Worse, with the plan to make of_root private[1], more open-coded users may appear.

Hence this series adds a new helper of_machine_get_match(), which returns the match entry, and converts several drivers to make use of it. Note that the new wrapper comes at no cost (binary size-wise), as the variant returning bool can be a trivial inline wrapper.

One could argue we don't even need the variant that returns bool, as

    "if (of_machine_device_match(...))" and
    "if (of_machine_get_match(...))",
and
    "if (!of_machine_device_match(...))" and
    "if (!of_machine_get_match(...))"

are equivalent.

The return type only matters when assigning to or returning an explicit type, like in drivers/soc/tegra/common.c:

    bool soc_is_tegra(void)
    {
	    return of_machine_device_match(tegra_machine_match);
    }

Only the Renesas driver patch was tested on actual hardware.

Thanks for your comments!

[1] "[PATCH v2 0/9] soc: remove direct accesses to of_root from

     drivers/soc/"
    https://lore.kernel.org/[email protected]/

Geert Uytterhoeven (7):
of: Add of_machine_get_match() helper
of: Convert to of_machine_get_match()
cpufreq: airoha: Convert to of_machine_get_match()
cpufreq: qcom-nvmem: Convert to of_machine_get_match()
cpufreq: ti-cpufreq: Convert to of_machine_get_match()
soc: qcom: pd-mapper: Convert to of_machine_get_match()
soc: renesas: Convert to of_machine_get_match()

 drivers/cpufreq/airoha-cpufreq.c     |  7 +------
 drivers/cpufreq/qcom-cpufreq-nvmem.c | 16 ++--------------
 drivers/cpufreq/ti-cpufreq.c         | 12 +-----------
 drivers/of/base.c                    | 20 ++++++--------------
 drivers/soc/qcom/qcom_pd_mapper.c    |  8 +-------
 drivers/soc/renesas/renesas-soc.c    |  2 +-
 include/linux/of.h                   | 11 ++++++++---
 7 files changed, 20 insertions(+), 56 deletions(-)
Signature · 12 lines
2.43.0

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds