]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
dm: core: Default to using DEVRES outside of xPL
authorTom Rini <trini@konsulko.com>
Sat, 27 Dec 2025 22:37:11 +0000 (16:37 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 9 Jan 2026 15:08:14 +0000 (09:08 -0600)
The devm alloc functions that we have may follow the Linux kernel model
where allocations are (almost always) automatically free()'d. However,
quite often we don't enable, in full U-Boot, the tracking and free()'ing
functionality. This in turn leads to memory leaks because the driver
author expects that since the functions have the same name as in the
Linux Kernel they have the same behavior. In turn we then get
functionally correct commits such as commit 00e1fed93c8c ("firmware:
ti_sci: Fix memory leaks in devm_ti_sci_get_of_resource") that manually
add these calls. Rather than manually tracking allocations and
implementing free()s, rework things so that we follow expectations by
enabling the DEVRES functionality (outside of xPL phases).

This turns DEVRES from a prompted symbol to a symbol that must be
select'd, and we now remove our non-managed alloc/free functions from
outside of xPL builds.

Reviewed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
34 files changed:
arch/arm/mach-stm32mp/Kconfig
drivers/block/Kconfig
drivers/clk/Kconfig
drivers/core/Kconfig
drivers/dma/ti/Kconfig
drivers/firmware/Kconfig
drivers/firmware/arm-ffa/Kconfig
drivers/gpio/Kconfig
drivers/i2c/muxes/Kconfig
drivers/i3c/Kconfig
drivers/mailbox/Kconfig
drivers/mtd/nand/raw/Kconfig
drivers/mtd/nand/spi/Kconfig
drivers/mtd/spi/Kconfig
drivers/mux/Kconfig
drivers/net/Kconfig
drivers/net/phy/Kconfig
drivers/pci/Kconfig
drivers/phy/Kconfig
drivers/pinctrl/Kconfig
drivers/pinctrl/mscc/Kconfig
drivers/pinctrl/mvebu/Kconfig
drivers/pinctrl/renesas/Kconfig
drivers/power/regulator/Kconfig
drivers/reboot-mode/Kconfig
drivers/reset/Kconfig
drivers/smem/Kconfig
drivers/soc/ti/Kconfig
drivers/spi/Kconfig
drivers/usb/cdns3/Kconfig
drivers/usb/dwc3/Kconfig
drivers/usb/host/Kconfig
drivers/video/Kconfig
include/dm/devres.h

index ba4694f296440c7825288ef830f3438c11ae59f6..2716844b25995b5b9a616f9b4ad506930b157eaf 100644 (file)
@@ -170,6 +170,7 @@ config STM32_ECDSA_VERIFY
 
 config STM32MP_TAMP_NVMEM
        bool "STM32 TAMP backup registers via NVMEM API"
+       select DEVRES
        select NVMEM
        default y
        help
index 185da2b5cfc2d0637036ae3a93ab7f3b1a34c937..461b5a9fc838c59b9ec24f0c551b93b582eca8fd 100644 (file)
@@ -265,6 +265,7 @@ config SYS_64BIT_LBA
 
 config RKMTD
        bool "Rockchip rkmtd virtual block device"
+       select DEVRES
        select RANDOM_UUID
        help
          Enable "rkmtd" class and driver to create a virtual block device
index 85cc472b4cb9b2a3148fce02def458e6fa42f22b..ae783254008cdc313c28f2e565d120db8bf4252f 100644 (file)
@@ -3,6 +3,7 @@ menu "Clock"
 config CLK
        bool "Enable clock driver support"
        depends on DM
+       select DEVRES
        help
          This allows drivers to be provided for clock generators, including
          oscillators and PLLs. Devices can use a common clock API to request
index 6b4330fe4ea3e3697cddbbb490a81dcb84c33337..c9253099e6eac22862156929384e4196201a3266 100644 (file)
@@ -197,6 +197,7 @@ config DM_DMA
 config REGMAP
        bool "Support register maps"
        depends on DM
+       select DEVRES
        help
          Hardware peripherals tend to have one or more sets of registers
          which can be accessed to control the hardware. A register map
@@ -271,16 +272,17 @@ config VPL_SYSCON
          assigning a unique number to each.
 
 config DEVRES
-       bool "Managed device resources"
+       bool
        depends on DM
        help
          This option enables the Managed device resources core support.
          Device resources managed by the devres framework are automatically
          released whether initialization fails half-way or the device gets
-         detached.
+         detached. This is most often used via devm_kmalloc and family and
+         is expected to work in a manner analogous to the Linux Kernel.
 
-         If this option is disabled, devres functions fall back to
-         non-managed variants.  For example, devres_alloc() to kzalloc(),
+         This option is disabled in xPL phases and devres functions fall back
+         to non-managed variants. For example, devres_alloc() to kzalloc(),
          devm_kmalloc() to kmalloc(), etc.
 
 config DEBUG_DEVRES
index 87c026e049031aa2575ed36674a87e20be12f864..5cec6ddd3e30ee0e20f3c7b1167e4ce0a433f4eb 100644 (file)
@@ -5,6 +5,7 @@ if ARCH_K3
 config TI_K3_NAVSS_UDMA
         bool "Texas Instruments UDMA"
         depends on ARCH_K3
+        select DEVRES
         select DMA
         select TI_K3_NAVSS_RINGACC
         select TI_K3_NAVSS_PSILCFG
index a094e6c3afef4010cea62f37cc7a16b40a3f5cd0..220de7319506145ed65919ad878565883ca02853 100644 (file)
@@ -16,6 +16,7 @@ config ARM_PSCI_FW
 config TI_SCI_PROTOCOL
        tristate "TI System Control Interface (TISCI) Message Protocol"
        depends on K3_SEC_PROXY
+       select DEVRES
        select FIRMWARE
        select SPL_FIRMWARE if SPL
        help
index d75f8b53fd854854ca4a6a1a59a8f0986a9640f1..3706a8893059668e7023eda1d2a39e393a4276ca 100644 (file)
@@ -6,6 +6,7 @@ config ARM_FFA_TRANSPORT
        select ARM_SMCCC if !SANDBOX
        select ARM_SMCCC_FEATURES if !SANDBOX
        imply CMD_ARMFFA
+       select DEVRES
        select LIB_UUID
        select DEVRES
        help
index 18ca8ad4caca17c1b0a4fa46de8abd9101b4bb72..60c5c54688e64be4704c108f9e1d3103b32c54e5 100644 (file)
@@ -19,6 +19,7 @@ if GPIO
 config DM_GPIO
        bool "Enable Driver Model for GPIO drivers"
        depends on DM
+       select DEVRES
        help
          Enable driver model for GPIO access. The standard GPIO
          interface (gpio_get_value(), etc.) is then implemented by
@@ -151,6 +152,7 @@ config CORTINA_GPIO
 config DWAPB_GPIO
        bool "DWAPB GPIO driver"
        depends on DM && DM_GPIO
+       select DEVRES
        help
          Support for the Designware APB GPIO driver.
 
@@ -253,6 +255,7 @@ config IMX_RGPIO2P
 
 config IPROC_GPIO
        bool "Broadcom iProc GPIO driver(without pinconf)"
+       select DEVRES
        help
          The Broadcom iProc based SoCs- Cygnus, NS2, NS3, NSP and Stingray,
          use the same GPIO Controller IP hence this driver could be used
index 65319bb6fd83af5b153e35eab0453942f2d36558..3b1220b210564e4c7537b89f6703b0fc0db8f999 100644 (file)
@@ -51,6 +51,7 @@ config I2C_MUX_PCA954x
 config I2C_MUX_GPIO
         tristate "GPIO-based I2C multiplexer"
        depends on I2C_MUX && DM_GPIO
+       select DEVRES
        help
          If you say yes to this option, support will be included for
          a GPIO based I2C multiplexer. This driver provides access to
index d877a7443538c556d5f885aa6cc5a58e0f7ef4eb..48341f9b8737bfa2735ab6a26d0d3504bc7d5e55 100644 (file)
@@ -1,6 +1,7 @@
 menuconfig I3C
        tristate "I3C support"
        select I2C
+       select DEVRES
        help
          I3C is a serial protocol standardized by the MIPI alliance.
 
index cfd2a3be3fd08fc2cebc318eacd5ba705cfc0abe..f45e611c9662f7b7ff8288a46b181a7e03a70e83 100644 (file)
@@ -31,6 +31,7 @@ config IMX_MU_MBOX
 config MPFS_MBOX
        bool "Enable MPFS system controller support"
        depends on DM_MAILBOX && ARCH_RV64I
+       select DEVRES
        help
          Enable support for the mailboxes that provide a communication
          channel with the system controller integrated on PolarFire SoC.
index 5e4d1c0a9378bb4207886c8a96a9b22173a75c9b..e0ff28cb21bd8f2d266ec999d7a791f3588112a3 100644 (file)
@@ -51,6 +51,7 @@ config DM_NAND_ATMEL
        bool "Support Atmel NAND controller with DM support"
        depends on ARCH_AT91
        select ATMEL_EBI
+       select DEVRES
        select SYS_NAND_SELF_INIT
        imply SYS_NAND_USE_FLASH_BBT
        help
@@ -74,6 +75,7 @@ config ATMEL_NAND_HWECC
 config ATMEL_NAND_HW_PMECC
        bool "Atmel Programmable Multibit ECC (PMECC)"
        select ATMEL_NAND_HWECC
+       select DEVRES
        help
          The Programmable Multibit ECC (PMECC) controller is a programmable
          binary BCH(Bose, Chaudhuri and Hocquenghem) encoder and decoder.
@@ -118,6 +120,7 @@ config NAND_BRCMNAND
        bool "Support Broadcom NAND controller"
        depends on OF_CONTROL && DM && DM_MTD
        depends on ARCH_BCMBCA || ARCH_BMIPS || TARGET_BCMNS || TARGET_BCMNS3
+       select DEVRES
        select SYS_NAND_SELF_INIT
        help
          Enable the driver for NAND flash on platforms using a Broadcom NAND
@@ -197,6 +200,7 @@ config SPL_NAND_LOAD
 config NAND_CADENCE
        bool "Support Cadence NAND controller as a DT device"
        depends on OF_CONTROL && DM_MTD && ARCH_SOCFPGA
+       select DEVRES
        select SYS_NAND_SELF_INIT
        select SPL_SYS_NAND_SELF_INIT
        select SPL_NAND_BASE
@@ -211,6 +215,7 @@ config NAND_CADENCE
 
 config NAND_DENALI
        bool
+       select DEVRES
        select SYS_NAND_SELF_INIT
        select SYS_NAND_ONFI_DETECTION if TARGET_SOCFPGA_SOC64
        imply CMD_NAND
index 0777dfdf0a7028fd815b57bedc539e153d47caa5..1124dada950644c1d4ee03438f66fb78c59f878a 100644 (file)
@@ -1,6 +1,7 @@
 menuconfig MTD_SPI_NAND
        bool "SPI NAND device Support"
        depends on DM_MTD && DM_SPI
+       select DEVRES
        select MTD_NAND_CORE
        select SPI_MEM
        help
index ca60a425ba3413621a8b84109b6ccc533ea79e60..a13c7fc60e689ce38e34aab0d732960caa06a026 100644 (file)
@@ -3,6 +3,7 @@ menu "SPI Flash Support"
 config DM_SPI_FLASH
        bool "Enable Driver Model for SPI flash"
        depends on DM_SPI
+       select DEVRES
        imply SPI_FLASH
        help
          Enable driver model for SPI flash. This SPI flash interface
index 2b95eb02177c67a01fdf9c07a612b3caacc72882..de74e5d5e4edc6c45e1cbd2e54a5ae1e9f56e7c9 100644 (file)
@@ -3,6 +3,7 @@ menu "Multiplexer drivers"
 config MULTIPLEXER
        bool "Multiplexer Support"
        depends on DM
+       select DEVRES
        help
         The mux framework is a minimalistic subsystem that handles multiplexer
         controllers. It provides the same API as Linux and mux drivers should
index f382a7752d5350d58b54d3775befb27f95528c17..13e631c55dc2663acaa23cb55d25dc3c4783a14b 100644 (file)
@@ -125,6 +125,7 @@ config AIROHA_ETH
        bool "Airoha Ethernet QDMA Driver"
        depends on ARCH_AIROHA
        select PHYLIB
+       select DEVRES
        select DM_RESET
        select MDIO_MT7531
        help
@@ -359,6 +360,7 @@ config ETH_SANDBOX_RAW
 
 config ETH_DESIGNWARE
        bool "Synopsys Designware Ethernet MAC"
+       select DEVRES
        select PHYLIB
        imply ETH_DESIGNWARE_SOCFPGA if ARCH_SOCFPGA
        help
@@ -555,6 +557,7 @@ config MVNETA
 config MVPP2
        bool "Marvell Armada 375/7K/8K network interface support"
        depends on ARMADA_375 || ARMADA_8K
+       select DEVRES
        select PHYLIB
        select MVMDIO
        select DM_MDIO
index d0aab0b8fe879aae5d5397210244b53e6c42ff24..709f1c91eb2dee42e57963f0a3bca6f0eaba4cca 100644 (file)
@@ -182,6 +182,7 @@ config PHY_MARVELL
 
 config PHY_MARVELL_10G
        bool "Marvell Alaska 10Gbit PHYs"
+       select DEVRES
        help
          Support for the Marvell Alaska MV88X3310 and compatible PHYs.
 
@@ -245,6 +246,7 @@ config PHY_NATSEMI
 
 config PHY_NXP_C45_TJA11XX
        tristate "NXP C45 TJA11XX PHYs"
+       select DEVRES
        help
          Enable support for NXP C45 TJA11XX PHYs.
          Currently supports only the TJA1103 PHY.
index ea9868425d044e8a83d640f3d06c0033016a9fd3..8fc57895a7861d279094c1f062657e93bd3dcc52 100644 (file)
@@ -131,6 +131,7 @@ config PCIE_APPLE
        bool "Enable Apple PCIe driver"
        depends on ARCH_APPLE
        imply PCI_INIT_R
+       select DEVRES
        select SYS_PCI_64BIT
        default y
        help
@@ -264,6 +265,7 @@ config PCI_XILINX
 
 config PCIE_LAYERSCAPE
        bool
+       select DEVRES
 
 config PCIE_LAYERSCAPE_RC
        bool "Layerscape PCIe Root Complex mode support"
@@ -361,6 +363,7 @@ config PCI_KEYSTONE
 config PCIE_MEDIATEK
        bool "MediaTek PCIe Gen2 controller"
        depends on ARCH_MEDIATEK
+       select DEVRES
        help
          Say Y here if you want to enable Gen2 PCIe controller,
          which could be found on MT7623 SoC family.
index 420d7c7a44dd4e5b879c63b540e87b907a3f41fe..87729b479bd949dc9425f355f5f105715e9150bd 100644 (file)
@@ -4,6 +4,7 @@ menu "PHY Subsystem"
 config PHY
        bool "PHY Core"
        depends on DM
+       select DEVRES
        help
          PHY support.
 
index 48119694031da1eecbc249623505323aa176ec93..ea90713ec6ca8c26f6be4c1c02d95f4465688432 100644 (file)
@@ -294,6 +294,7 @@ config PINCTRL_SANDBOX
 config PINCTRL_SINGLE
        bool "Single register pin-control and pin-multiplex driver"
        depends on DM
+       select DEVRES
        help
          This enables pinctrl driver for systems using a single register for
          pin configuration and multiplexing. TI's AM335X SoCs are examples of
index aab67fabd2cd67aa63064161ba05e3400c32097f..567c93f404ccba4ccb5a6b78607bb82481986b77 100644 (file)
@@ -2,6 +2,7 @@
 
 config PINCTRL_MSCC
        bool
+       select DEVRES
 
 config PINCTRL_MSCC_OCELOT
        depends on SOC_OCELOT && PINCTRL_FULL && OF_CONTROL
index 7c51d138c8bd8b9621b2ecb737fff3ac30c656b5..10ba440f246e8cae4e5aaf02fcbde925bc6a0715 100644 (file)
@@ -9,6 +9,7 @@ config PINCTRL_ARMADA_38X
 
 config PINCTRL_ARMADA_37XX
        depends on ARMADA_3700 && PINCTRL_FULL
+       select DEVRES
        bool "Armada 37xx pin control driver"
        help
           Support pin multiplexing and pin configuration control on
index ac40b31dbfaa6d033213c44a82f3d8159e77dccb..171da88cfcf46d98b2bb83306b792345a3090eb9 100644 (file)
@@ -166,6 +166,7 @@ config PINCTRL_RZG2L
        depends on PINCTRL
        depends on PINCTRL_GENERIC
        depends on PINCONF
+       select DEVRES
        help
          Support the pinctrl functionality of the pin function controller (PFC)
          on the Renesas RZ/G2L SoC family.
index c6da459a212a0f8f3d4f50fdca1d00d2fc085ed6..bd9ccd26981a7b0c15e3d6b6d95530a8da02a0a6 100644 (file)
@@ -228,6 +228,7 @@ config DM_REGULATOR_GPIO
 config DM_REGULATOR_QCOM_RPMH
        bool "Enable driver model for Qualcomm RPMh regulator"
        depends on DM_REGULATOR && QCOM_RPMH
+       select DEVRES
        ---help---
          Enable support for the Qualcomm RPMh regulator. The driver
          implements get/set api for a limited set of regulators used
index bb5189351881d82df3613583cc6ec5c59a32b78d..72b33d7122351de4edc3593c9b156f6fa0ea7b3a 100644 (file)
@@ -9,6 +9,7 @@ menu "Reboot Mode Support"
 config DM_REBOOT_MODE
        bool "Enable reboot mode using Driver Model"
        depends on DM
+       select DEVRES
        help
                Enable support for reboot mode control. This will allow users to
                adjust the boot process based on reboot mode parameter
index 74c267dfc4e5f42f294806f944031c3992fac2e0..2fd91d6299cccd1f230925f593d04a58f9edb930 100644 (file)
@@ -3,6 +3,7 @@ menu "Reset Controller Support"
 config DM_RESET
        bool "Enable reset controllers using Driver Model"
        depends on DM && OF_CONTROL
+       select DEVRES
        help
          Enable support for the reset controller driver class. Many hardware
          modules are equipped with a reset signal, typically driven by some
index 73d51b3a7a487681c52d11d47b015330cfba815a..e5d7dcc81b17e5de3d9a01bca813ea63949abd78 100644 (file)
@@ -16,6 +16,7 @@ config MSM_SMEM
     bool "Qualcomm Shared Memory Manager (SMEM)"
     depends on DM
     depends on ARCH_SNAPDRAGON || ARCH_IPQ40XX
+    select DEVRES
     help
       Enable support for the Qualcomm Shared Memory Manager.
       The driver provides an interface to items in a heap shared among all
index 0ee21f9904888dc0b98dde4372b86b0e6e8ba1a4..36129cb72f68376b11d3ec4348ceeec8f1396b06 100644 (file)
@@ -8,6 +8,7 @@ if SOC_TI
 config TI_K3_NAVSS_RINGACC
        bool "K3 Ring accelerator Sub System"
        depends on ARCH_K3
+       select DEVRES
        select MISC
        help
          Say y here to support the K3 AM65x Ring accelerator module.
index e31db9d4e31b60dbc176e3f35b0cad56c4b74a9d..50d22bf3fc4c2b7b471e1c983d3770ea0d151824 100644 (file)
@@ -35,6 +35,7 @@ config DM_SPI
 
 config SPI_MEM
        bool "SPI memory extension"
+       select DEVRES
        help
          Enable this option if you want to enable the SPI memory extension.
          This extension is meant to simplify interaction with SPI memories
@@ -343,6 +344,7 @@ config MT7621_SPI
 config MTK_SNOR
        bool "Mediatek SPI-NOR controller driver"
        depends on SPI_MEM
+       select DEVRES
        help
          Enable the Mediatek SPINOR controller driver. This driver has
           better read/write performance with NOR.
index 1d5e4afac6cd0b33337ddf0c660dbd165f94d4a6..7964f3f41d5e5418fb42386a5170cdb5bb820da6 100644 (file)
@@ -1,6 +1,7 @@
 config USB_CDNS3
        tristate "Cadence USB3 Dual-Role Controller"
        depends on USB_XHCI_HCD || USB_GADGET
+       select DEVRES
        help
          Say Y here if your system has a Cadence USB3 dual-role controller.
          It supports: Host-only, and Peripheral-only.
index 744dfa90463c8cd120142ebfd4d2d56fbc4bfb5f..27fcae54b2275f1c87b77381914f15d4b3c78ce3 100644 (file)
@@ -1,6 +1,7 @@
 config USB_DWC3
        bool "DesignWare USB3 DRD Core Support"
        depends on USB_XHCI_HCD || USB_GADGET
+       select DEVRES
        help
          Say Y here if your system has a Dual Role SuperSpeed
          USB controller based on the DesignWare USB3 IP Core.
index 99f381db9f9b2ba5bf0edbdbd8aad5d4d8c68344..54df4264a4413c087413724e46e2edc49fb0314c 100644 (file)
@@ -367,6 +367,7 @@ config USB_OHCI_GENERIC
 config USB_OHCI_DA8XX
        bool "Support for da850 OHCI USB controller"
        depends on ARCH_DAVINCI
+       select DEVRES
        help
          Enable support for the da850 USB controller.
 
index b5777da5218a85252feab78991bc4e4dab64bbad..2c67d089492c1af07c4314d381b659291c00e57c 100644 (file)
@@ -831,6 +831,7 @@ config BACKLIGHT_LM3533
 config BACKLIGHT_LP855x
        bool "Backlight Driver for LP855x"
        depends on BACKLIGHT
+       select DEVRES
        select DM_I2C
        help
          Say Y to enable the backlight driver for National Semiconductor / TI
index 27761deb6d1fbb0f2a37adbc518535877c128e6a..406d18686f4d05fc7ad6c71a340355601ee95c6d 100644 (file)
@@ -207,7 +207,8 @@ void devm_kfree(struct udevice *dev, void *ptr);
 /* Get basic stats on allocations */
 void devres_get_stats(const struct udevice *dev, struct devres_stats *stats);
 
-#else /* ! DEVRES */
+#elif IS_ENABLED(CONFIG_DEVRES) && defined(CONFIG_XPL_BUILD)
+/* Allow these to be dummy functions in xPL builds. */
 
 static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
 {