From d223dcf31ad04e3b363770f2e20a36f1c7716568 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 23 Aug 2023 02:18:17 +0200 Subject: [PATCH] drivers/mtd/nvmxip: Trigger post bind as probe on driver level Perform all the block device creation only once, after the driver itself successfully bound. Do not do this in uclass post bind, as this might be triggered multiple times. For example the ut_dm_host test triggers this and triggers a memory leak that way, since there are now multiple block devices created using the blk_create_devicef() . To retain the old probe-on-boot behavior, set DM_FLAG_PROBE_AFTER_BIND flag in uclass post_bind callback, so the driver model would probe the driver at the right time. Rename the function as well, to match similar functions in other block-related subsystems, like the mmc one. Signed-off-by: Marek Vasut --- drivers/mtd/nvmxip/nvmxip-uclass.c | 18 +++++++----------- drivers/mtd/nvmxip/nvmxip_qspi.c | 1 + include/nvmxip.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nvmxip/nvmxip-uclass.c b/drivers/mtd/nvmxip/nvmxip-uclass.c index 6d8eb177b5..36eb056c21 100644 --- a/drivers/mtd/nvmxip/nvmxip-uclass.c +++ b/drivers/mtd/nvmxip/nvmxip-uclass.c @@ -22,17 +22,7 @@ #define DEFAULT_LBA_SZ BIT(DEFAULT_LBA_SHIFT) -/** - * nvmxip_post_bind() - post binding treatments - * @dev: the NVMXIP device - * - * Create and probe a child block device. - * - * Return: - * - * 0 on success. Otherwise, failure - */ -static int nvmxip_post_bind(struct udevice *udev) +int nvmxip_probe(struct udevice *udev) { int ret; struct udevice *bdev = NULL; @@ -67,6 +57,12 @@ static int nvmxip_post_bind(struct udevice *udev) return 0; } +static int nvmxip_post_bind(struct udevice *udev) +{ + dev_or_flags(udev, DM_FLAG_PROBE_AFTER_BIND); + return 0; +} + UCLASS_DRIVER(nvmxip) = { .name = "nvmxip", .id = UCLASS_NVMXIP, diff --git a/drivers/mtd/nvmxip/nvmxip_qspi.c b/drivers/mtd/nvmxip/nvmxip_qspi.c index 7221fd1cb4..1bf0d311fe 100644 --- a/drivers/mtd/nvmxip/nvmxip_qspi.c +++ b/drivers/mtd/nvmxip/nvmxip_qspi.c @@ -66,5 +66,6 @@ U_BOOT_DRIVER(nvmxip_qspi) = { .id = UCLASS_NVMXIP, .of_match = nvmxip_qspi_ids, .of_to_plat = nvmxip_qspi_of_to_plat, + .probe = nvmxip_probe, .plat_auto = sizeof(struct nvmxip_plat), }; diff --git a/include/nvmxip.h b/include/nvmxip.h index f4ef37725d..726fffeb3e 100644 --- a/include/nvmxip.h +++ b/include/nvmxip.h @@ -29,4 +29,16 @@ struct nvmxip_plat { lbaint_t lba; }; +/** + * nvmxip_bind() - post binding treatments + * @dev: the NVMXIP device + * + * Create and probe a child block device. + * + * Return: + * + * 0 on success. Otherwise, failure + */ +int nvmxip_probe(struct udevice *udev); + #endif /* __DRIVER_NVMXIP_H__ */ -- 2.39.5