Commit 5fe7702eccf1bae5b10f0309cef03e02bfdfa6ef

Authored by Jean-Jacques Hiblot
Committed by Simon Glass
1 parent c98ac3487e

blk: dm: make blk_create_device() take a number of block instead of a size

There is an overflow problem when taking the size instead of the number
of blocks in blk_create_device(). This results in a wrong device size: the
device apparent size is its real size  modulo 4GB.
Using the number of blocks instead of the device size fixes the problem and
is more coherent with the internals of the block layer.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 5 changed files with 13 additions and 13 deletions Side-by-side Diff

drivers/block/blk-uclass.c
... ... @@ -546,7 +546,7 @@
546 546  
547 547 int blk_create_device(struct udevice *parent, const char *drv_name,
548 548 const char *name, int if_type, int devnum, int blksz,
549   - lbaint_t size, struct udevice **devp)
  549 + lbaint_t lba, struct udevice **devp)
550 550 {
551 551 struct blk_desc *desc;
552 552 struct udevice *dev;
... ... @@ -567,7 +567,7 @@
567 567 desc = dev_get_uclass_platdata(dev);
568 568 desc->if_type = if_type;
569 569 desc->blksz = blksz;
570   - desc->lba = size / blksz;
  570 + desc->lba = lba;
571 571 desc->part_type = PART_TYPE_UNKNOWN;
572 572 desc->bdev = dev;
573 573 desc->devnum = devnum;
... ... @@ -578,7 +578,7 @@
578 578  
579 579 int blk_create_devicef(struct udevice *parent, const char *drv_name,
580 580 const char *name, int if_type, int devnum, int blksz,
581   - lbaint_t size, struct udevice **devp)
  581 + lbaint_t lba, struct udevice **devp)
582 582 {
583 583 char dev_name[30], *str;
584 584 int ret;
... ... @@ -589,7 +589,7 @@
589 589 return -ENOMEM;
590 590  
591 591 ret = blk_create_device(parent, drv_name, str, if_type, devnum,
592   - blksz, size, devp);
  592 + blksz, lba, devp);
593 593 if (ret) {
594 594 free(str);
595 595 return ret;
drivers/block/sandbox.c
... ... @@ -129,7 +129,7 @@
129 129 }
130 130 ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str,
131 131 IF_TYPE_HOST, devnum, 512,
132   - os_lseek(fd, 0, OS_SEEK_END), &dev);
  132 + os_lseek(fd, 0, OS_SEEK_END) / 512, &dev);
133 133 if (ret)
134 134 goto err_file;
135 135 ret = device_probe(dev);
... ... @@ -580,7 +580,7 @@
580 580 */
581 581 snprintf(str, sizeof(str), "id%dlun%d", id, lun);
582 582 ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1,
583   - bd.blksz, bd.blksz * bd.lba, &bdev);
  583 + bd.blksz, bd.lba, &bdev);
584 584 if (ret) {
585 585 debug("Can't create device\n");
586 586 return ret;
... ... @@ -315,12 +315,12 @@
315 315 * @devnum: Device number, specific to the interface type, or -1 to
316 316 * allocate the next available number
317 317 * @blksz: Block size of the device in bytes (typically 512)
318   - * @size: Total size of the device in bytes
  318 + * @lba: Total number of blocks of the device
319 319 * @devp: the new device (which has not been probed)
320 320 */
321 321 int blk_create_device(struct udevice *parent, const char *drv_name,
322 322 const char *name, int if_type, int devnum, int blksz,
323   - lbaint_t size, struct udevice **devp);
  323 + lbaint_t lba, struct udevice **devp);
324 324  
325 325 /**
326 326 * blk_create_devicef() - Create a new named block device
327 327  
... ... @@ -332,12 +332,12 @@
332 332 * @devnum: Device number, specific to the interface type, or -1 to
333 333 * allocate the next available number
334 334 * @blksz: Block size of the device in bytes (typically 512)
335   - * @size: Total size of the device in bytes
  335 + * @lba: Total number of blocks of the device
336 336 * @devp: the new device (which has not been probed)
337 337 */
338 338 int blk_create_devicef(struct udevice *parent, const char *drv_name,
339 339 const char *name, int if_type, int devnum, int blksz,
340   - lbaint_t size, struct udevice **devp);
  340 + lbaint_t lba, struct udevice **devp);
341 341  
342 342 /**
343 343 * blk_prepare_device() - Prepare a block device for use
... ... @@ -23,9 +23,9 @@
23 23  
24 24 /* Create two, one the parent of the other */
25 25 ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
26   - IF_TYPE_HOST, 1, 512, 1024, &blk));
  26 + IF_TYPE_HOST, 1, 512, 2, &blk));
27 27 ut_assertok(blk_create_device(blk, "usb_storage_blk", "test",
28   - IF_TYPE_USB, 3, 512, 1024, &usb_blk));
  28 + IF_TYPE_USB, 3, 512, 2, &usb_blk));
29 29  
30 30 /* Check we can find them */
31 31 ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_HOST, 0, &dev));
... ... @@ -101,7 +101,7 @@
101 101 struct udevice *blk, *dev;
102 102  
103 103 ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
104   - IF_TYPE_HOST, 1, 512, 1024, &blk));
  104 + IF_TYPE_HOST, 1, 512, 2, &blk));
105 105 ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev));
106 106 ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev));
107 107 ut_asserteq_ptr(blk, dev);