Skip to content

driver core: count references of the platform device's fwnode, not OF node

Bartosz Golaszewski dri-devel driver-core imx intel-xe linux-arm-msm linux-devicetree linux-i2c linux-iommu linux-mips linux-pm linux-sound linux-usb linuxppc-dev lkml mfd netdev platform-driver-x86 stable 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20260520-pdev-fwnode-ref-d867836971eb

Versions newest first

  1. v3 Latest20 patches 10 repliesIn review
  2. v219 patches 10 repliesSuperseded
  3. v123 patches 34 repliesApplied

Changes in v3 from the cover letter

- Use device_set_node() where applicable
- Use __free(device_node) in fsl iommu driver
- Don't use __free() where not really required
- Add a patch updating the kerneldoc for platform_device_alloc()
- Collect more tags
- Link to v2: https://patch.msgid.link/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/20powerpc/powermac: fix OF node refcountarch/powerpc/platforms/powermac/low_i2c.c+1 -10 replies
2/20driver core: platform: provide platform_device_set_of_node()drivers/base/platform.c include/linux/platform_device.h+22 -04 replies
3/20driver core: platform: provide platform_device_set_fwnode()drivers/base/platform.c include/linux/platform_device.h+22 -00 replies
4/20driver core: platform: provide platform_device_set_of_node_from_dev()drivers/base/platform.c include/linux/platform_device.h+18 -00 replies
5/20driver core: update kerneldoc for platform_device_alloc()drivers/base/platform.c+7 -03 replies
6/20of: platform: use platform_device_set_of_node()drivers/of/platform.c+1 -10 replies
7/20powerpc/powermac: use platform_device_set_of_node()arch/powerpc/platforms/powermac/low_i2c.c+1 -10 replies
8/20i2c: pxa-pci: use platform_device_set_of_node()drivers/i2c/busses/i2c-pxa-pci.c+2 -10 replies
9/20iommu/fsl: use platform_device_set_of_node()drivers/iommu/fsl_pamu.c+6 -101 reply
10/20net: bcmgenet: use platform_device_set_of_node()drivers/net/ethernet/broadcom/genet/bcmmii.c+2 -10 replies
11/20pmdomain: imx: use platform_device_set_of_node()drivers/pmdomain/imx/gpc.c+1 -21 reply
12/20mfd: tps6586: use platform_device_set_of_node()drivers/mfd/tps6586x.c+1 -10 replies
13/20slimbus: qcom-ngd-ctrl: use platform_device_set_of_node()drivers/slimbus/qcom-ngd-ctrl.c+1 -10 replies
14/20net: mv643xx: use platform_device_set_of_node()drivers/net/ethernet/marvell/mv643xx_eth.c+1 -10 replies
15/20drm/xe/i2c: use platform_device_set_fwnode()drivers/gpu/drm/xe/xe_i2c.c+1 -10 replies
16/20platform/surface: gpe: use platform_device_set_fwnode()drivers/platform/surface/surface_gpe.c+1 -10 replies
17/20usb: chipidea: use platform_device_set_of_node_from_dev()drivers/usb/chipidea/core.c+1 -10 replies
18/20usb: musb: use platform_device_set_of_node_from_dev()drivers/usb/musb/jz4740.c+1 -10 replies
19/20reset: rzg2l: use platform_device_set_of_node_from_dev()drivers/reset/reset-rzg2l-usbphy-ctrl.c+1 -10 replies
20/20driver core: platform: count references to all kinds of firmware nodesdrivers/base/platform.c+5 -100 replies

Reviews trailers per patch

19 of 20 patches have a Reviewed-by or Acked-by.

PatchAndy ShevchenkoManuel EbnerRob Herring (Arm)Andi ShytiWolfram SangFrank LiLee JonesKonrad DybcioRobin MurphyJakub KicinskiIlpo JärvinenPeter ChenPhilipp ZabelUlf Hansson
1/20R-b
2/20R-b R-b
3/20R-b
4/20R-b
5/20
6/20R-b A-b
7/20R-b
8/20R-b A-b A-b
9/20R-b R-b A-b
10/20R-b
11/20R-b R-b A-b
12/20R-b A-b
13/20R-b A-b
14/20R-b A-b
15/20R-b
16/20R-b A-b
17/20R-b A-b
18/20R-b
19/20R-b A-b
20/20R-b

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

Read the v3 thread

Cover letter [PATCH v3 00/20] driver core: count references of the platform device's fwnode, not OF node

Platform device core provides helper interfaces for dealing with dynamically created platform devices. Most users should use platform_device_register_full() which encapsulates most of the operations but some modules will want to use the split approach of calling platform_device_alloc() + platform_device_add() separately for various reasons.

With many platform devices now using dynamic software nodes as their primary firmware nodes and with the platform device interface being extended to also better cover the use-cases of secondary software nodes, I believe it makes sense to switch to counting the references of all kinds of firmware nodes.

To that end, I identified all users of platform_device_alloc() that also assign dev.of_node or dev.fwnode manually. I noticed five cases where the references are not increased as they should (patches 1-5 fix these users) and provided three new functions in platform_device.h that now become the preferred interfaces for assigning firmware nodes to dynamic platform devices (in line with platform_device_add_data(), platform_device_add_resources(), etc.). The bulk of the patches in this series are small driver conversions to port all users to going through the new functions that now encapsulate the refcount logic. With that done, the final patch seamlessly switches to counting the references of all firmware node types.

This effort is prerequisite of removing platform_device_release_full() and unifying the release path for dynamic platform devices using unmanaged software nodes.

Merging strategy: The entire series should go through the driver core tree, possibly with an immutable branch provided to solve any potential conflicts though these are rather unlikely.

---
Changes in v3:
- Use device_set_node() where applicable
- Use __free(device_node) in fsl iommu driver
- Don't use __free() where not really required
- Add a patch updating the kerneldoc for platform_device_alloc()
- Collect more tags
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Rebased on top of v7.2-rc1, dropped applied patches, collected tags
- Link to v1: https://patch.msgid.link/[email protected]

---
Bartosz Golaszewski (20):
powerpc/powermac: fix OF node refcount
driver core: platform: provide platform_device_set_of_node() driver core: platform: provide platform_device_set_fwnode() driver core: platform: provide platform_device_set_of_node_from_dev() driver core: update kerneldoc for platform_device_alloc()
of: platform: use platform_device_set_of_node() powerpc/powermac: use platform_device_set_of_node()
i2c: pxa-pci: use platform_device_set_of_node()
iommu/fsl: use platform_device_set_of_node()
net: bcmgenet: use platform_device_set_of_node()
pmdomain: imx: use platform_device_set_of_node()
mfd: tps6586: use platform_device_set_of_node()
slimbus: qcom-ngd-ctrl: use platform_device_set_of_node()
net: mv643xx: use platform_device_set_of_node() drm/xe/i2c: use platform_device_set_fwnode() platform/surface: gpe: use platform_device_set_fwnode()
usb: chipidea: use platform_device_set_of_node_from_dev()
usb: musb: use platform_device_set_of_node_from_dev()
reset: rzg2l: use platform_device_set_of_node_from_dev() driver core: platform: count references to all kinds of firmware nodes

 arch/powerpc/platforms/powermac/low_i2c.c    |  2 +-
 drivers/base/platform.c                      | 61 ++++++++++++++++++++++++++--
 drivers/gpu/drm/xe/xe_i2c.c                  |  2 +-
 drivers/i2c/busses/i2c-pxa-pci.c             |  3 +-
 drivers/iommu/fsl_pamu.c                     | 16 +++-----
 drivers/mfd/tps6586x.c                       |  2 +-
 drivers/net/ethernet/broadcom/genet/bcmmii.c |  3 +-
 drivers/net/ethernet/marvell/mv643xx_eth.c   |  2 +-
 drivers/of/platform.c                        |  2 +-
 drivers/platform/surface/surface_gpe.c       |  2 +-
 drivers/pmdomain/imx/gpc.c                   |  3 +-
 drivers/reset/reset-rzg2l-usbphy-ctrl.c      |  2 +-
 drivers/slimbus/qcom-ngd-ctrl.c              |  2 +-
 drivers/usb/chipidea/core.c                  |  2 +-
 drivers/usb/musb/jz4740.c                    |  2 +-
 include/linux/platform_device.h              |  9 ++++
 16 files changed, 88 insertions(+), 27 deletions(-)

---
base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260520-pdev-fwnode-ref-d867836971eb

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>