efi: Set the efi_media device name when binding

Binding a new efi_media device uses a placeholder name which is then
changed after the device is bound. But binding the device immediately
causes a child block device to be bound, which uses this placeholder
name as its base, rather than the eventual name of the efi_media device.

To fix, decide on the name earlier (based on the number of existing
devices), then pass that name to device_bind()

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-20 12:09:00 -06:00
parent 88123cd086
commit dea4ea00a7

View File

@@ -50,7 +50,7 @@ int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
{
struct efi_media_plat *plat;
struct udevice *dev;
char name[18];
char name[18], *str;
int ret;
size_t device_path_len = device_path_length(device_path);
@@ -63,13 +63,20 @@ int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
if (!plat->device_path)
return log_msg_ret("path", -ENOMEM);
memcpy(plat->device_path, device_path, device_path_len);
ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
plat, ofnode_null(), &dev);
if (ret)
return log_msg_ret("bind", ret);
snprintf(name, sizeof(name), "efi_media_%x", dev_seq(dev));
device_set_name(dev, name);
snprintf(name, sizeof(name), "efi_media_%x",
uclass_id_count(UCLASS_EFI_MEDIA));
str = strdup(name);
if (!str)
return -ENOMEM;
ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), str, plat,
ofnode_null(), &dev);
if (ret) {
free(str);
return log_msg_ret("bind", ret);
}
device_set_name_alloced(dev);
*devp = dev;
return 0;