Re: [PATCH] PCI/IDE: Destroy host bridge IDAs on release

From: Bartosz Golaszewski

Date: Thu Nov 19 2026 - 08:33:36 EST


On Thu, Nov 19, 2026 at 06:54:29AM +0000, Xiaolei Wang wrote:
> pci_ide_init_host_bridge() initializes two IDAs embedded in the host
> bridge and reserves stream ID 255 in ide_stream_ids_ida, which allocates
> an 128-byte IDA chunk. pci_release_host_bridge_dev(), however, only frees
> the resource lists and kfree()s the bridge, leaving both IDAs undestroyed.
> The chunk becomes unreferenced once the bridge is gone.
>
> This is observed at boot with CONFIG_DEBUG_KMEMLEAK:
>
> unreferenced object 0xffff000100d4df00 (size 128):
> comm "kworker/u16:3", pid 52, jiffies 4294892598
> backtrace (crc 6f8346e1):
> kmemleak_alloc+0x34/0x40
> __kmalloc_cache_noprof+0x3c0/0x56c
> ida_alloc_range+0x42c/0x554
> pci_ide_init_host_bridge+0x130/0x170
> pci_alloc_host_bridge+0x16c/0x1e0
> devm_pci_alloc_host_bridge+0x1c/0xb4
>
> The 128 bytes is IDA_CHUNK_SIZE, and the trailing 0x80 in the object hex
> dump is bit 63 of bitmap[3], i.e. the reserved stream ID 255.
>
> The leak only exists in builds with CONFIG_PCI_IDE (selected by
> CONFIG_PCI_TSM), so it is invisible on kernels without TEE-IO support.
> Every host bridge that is freed leaks one chunk: a probe that fails or
> defers, and a driver unbind, all go through the same release callback.
>
> Add pci_ide_destroy_host_bridge() to destroy both IDAs and call it from
> pci_release_host_bridge_dev() just before kfree(), symmetric with
> pci_ide_destroy() which handles struct pci_dev.
>
> Fixes: 079115370d00 ("PCI/IDE: Initialize an ID for all IDE streams")
> Signed-off-by: Xiaolei Wang <wangxiaolei01@xxxxxxxxxxx>
> ---

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>