Skip to content

Commit

Permalink
blk: Call part_init() in the post_probe() method
Browse files Browse the repository at this point in the history
part_init() is currently called in every DM BLK driver, either
in its bind() or probe() method. However we can use the BLK
uclass driver's post_probe() method to do it automatically.

Update all DM BLK drivers to adopt this change.

Signed-off-by: Bin Meng <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
  • Loading branch information
lbmeng authored and sjg20 committed Nov 14, 2018
1 parent f26ce03 commit d0851c8
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
9 changes: 0 additions & 9 deletions cmd/sata.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ int sata_probe(int devnum)
{
#ifdef CONFIG_AHCI
struct udevice *dev;
struct udevice *blk;
int rc;

rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
Expand All @@ -67,14 +66,6 @@ int sata_probe(int devnum)
return CMD_RET_FAILURE;
}

rc = blk_get_from_parent(dev, &blk);
if (!rc) {
struct blk_desc *desc = dev_get_uclass_platdata(blk);

if (desc->lba > 0 && desc->blksz > 0)
part_init(desc);
}

return 0;
#else
return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
Expand Down
4 changes: 1 addition & 3 deletions common/usb_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ static int usb_stor_probe_device(struct usb_device *udev)
blkdev->lun = lun;

ret = usb_stor_get_info(udev, data, blkdev);
if (ret == 1)
ret = blk_prepare_device(dev);
if (!ret) {
if (ret == 1) {
usb_max_devs++;
debug("%s: Found device %p\n", __func__, udev);
} else {
Expand Down
12 changes: 12 additions & 0 deletions drivers/block/blk-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,20 @@ int blk_unbind_all(int if_type)
return 0;
}

static int blk_post_probe(struct udevice *dev)
{
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
struct blk_desc *desc = dev_get_uclass_platdata(dev);

part_init(desc);
#endif

return 0;
}

UCLASS_DRIVER(blk) = {
.id = UCLASS_BLK,
.name = "blk",
.post_probe = blk_post_probe,
.per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
};
2 changes: 0 additions & 2 deletions drivers/block/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,6 @@ static int ide_blk_probe(struct udevice *udev)
BLK_REV_SIZE);
desc->revision[BLK_REV_SIZE] = '\0';

part_init(desc);

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/block/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int host_dev_bind(int devnum, char *filename)
goto err_file;
}

return blk_prepare_device(dev);
return 0;
err_file:
os_close(fd);
err:
Expand Down
3 changes: 0 additions & 3 deletions drivers/mmc/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc)
bdesc->product[0] = 0;
bdesc->revision[0] = 0;
#endif
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
part_init(bdesc);
#endif

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/nvme/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)
sprintf(desc->vendor, "0x%.4x", pplat->vendor);
memcpy(desc->product, ndev->serial, sizeof(ndev->serial));
memcpy(desc->revision, ndev->firmware_rev, sizeof(ndev->firmware_rev));
part_init(desc);

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/scsi/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ static int do_scsi_scan_one(struct udevice *dev, int id, int lun, bool verbose)
memcpy(&bdesc->vendor, &bd.vendor, sizeof(bd.vendor));
memcpy(&bdesc->product, &bd.product, sizeof(bd.product));
memcpy(&bdesc->revision, &bd.revision, sizeof(bd.revision));
part_init(bdesc);

if (verbose) {
printf(" Device %d: ", 0);
Expand Down
2 changes: 0 additions & 2 deletions lib/efi_driver/efi_block_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)
return ret;
EFI_PRINT("%s: block device '%s' created\n", __func__, bdev->name);

ret = blk_prepare_device(bdev);

/* Create handles for the partions of the block device */
disks = efi_bl_bind_partitions(handle, bdev);
EFI_PRINT("Found %d partitions\n", disks);
Expand Down

0 comments on commit d0851c8

Please sign in to comment.