From patchwork Fri Jun 9 14:45:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 774017 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wklTr1pSXz9s8N for ; Sat, 10 Jun 2017 00:46:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="TnH81fLb"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id DEB3AC21FC7; Fri, 9 Jun 2017 14:46:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 32F3EC21E7F; Fri, 9 Jun 2017 14:46:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 36127C21E7F; Fri, 9 Jun 2017 14:45:58 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id 7760EC21E0B for ; Fri, 9 Jun 2017 14:45:57 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v59EjPYH014176; Fri, 9 Jun 2017 09:45:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1497019525; bh=oW6ZlrN6eOKrH5ug55HTmW4ZsfYonMi1g6x7PXgyDfs=; h=From:To:Subject:Date; b=TnH81fLbRPgSg18RlHKjjZxHHNPY3BN+0lQzAAwAWaTHHM7SzOk9khkk+ZNhYWg12 R7c70u0j51ehzM4bStWRiKHHnu8V/Q4SAcaWB+phg6YGuyIRSTjbwqix3tkdINS5kk L6g2cYJzY0CSPgWZx0mTqCaTkVCjCM4Ovtrzm+LU= Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v59EjKL0031051; Fri, 9 Jun 2017 09:45:20 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Fri, 9 Jun 2017 09:45:19 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v59EjIWd030646; Fri, 9 Jun 2017 09:45:19 -0500 From: Jean-Jacques Hiblot To: , , Date: Fri, 9 Jun 2017 16:45:18 +0200 Message-ID: <1497019518-16064-1-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Subject: [U-Boot] [PATCH] blk: dm: make blk_create_device() take a number of block instead of a size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Reviewed-by: Simon Glass --- common/scsi.c | 2 +- drivers/block/blk-uclass.c | 8 ++++---- drivers/block/sandbox.c | 2 +- include/blk.h | 8 ++++---- test/dm/blk.c | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/scsi.c b/common/scsi.c index c456f5a..da15c05 100644 --- a/common/scsi.c +++ b/common/scsi.c @@ -572,7 +572,7 @@ static int do_scsi_scan_one(struct udevice *dev, int id, int lun, int mode) */ snprintf(str, sizeof(str), "id%dlun%d", id, lun); ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1, - bd.blksz, bd.blksz * bd.lba, &bdev); + bd.blksz, bd.lba, &bdev); if (ret) { debug("Can't create device\n"); return ret; diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 6145675..c4ae2f4 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -513,7 +513,7 @@ static int blk_claim_devnum(enum if_type if_type, int devnum) int blk_create_device(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, - lbaint_t size, struct udevice **devp) + lbaint_t lba, struct udevice **devp) { struct blk_desc *desc; struct udevice *dev; @@ -534,7 +534,7 @@ int blk_create_device(struct udevice *parent, const char *drv_name, desc = dev_get_uclass_platdata(dev); desc->if_type = if_type; desc->blksz = blksz; - desc->lba = size / blksz; + desc->lba = lba; desc->part_type = PART_TYPE_UNKNOWN; desc->bdev = dev; desc->devnum = devnum; @@ -545,7 +545,7 @@ int blk_create_device(struct udevice *parent, const char *drv_name, int blk_create_devicef(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, - lbaint_t size, struct udevice **devp) + lbaint_t lba, struct udevice **devp) { char dev_name[30], *str; int ret; @@ -556,7 +556,7 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name, return -ENOMEM; ret = blk_create_device(parent, drv_name, str, if_type, devnum, - blksz, size, devp); + blksz, lba, devp); if (ret) { free(str); return ret; diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c index 34d1c63..98df6b3 100644 --- a/drivers/block/sandbox.c +++ b/drivers/block/sandbox.c @@ -129,7 +129,7 @@ int host_dev_bind(int devnum, char *filename) } ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str, IF_TYPE_HOST, devnum, 512, - os_lseek(fd, 0, OS_SEEK_END), &dev); + os_lseek(fd, 0, OS_SEEK_END) / 512, &dev); if (ret) goto err_file; ret = device_probe(dev); diff --git a/include/blk.h b/include/blk.h index a128ee4..984491c 100644 --- a/include/blk.h +++ b/include/blk.h @@ -310,12 +310,12 @@ int blk_next_device(struct udevice **devp); * @devnum: Device number, specific to the interface type, or -1 to * allocate the next available number * @blksz: Block size of the device in bytes (typically 512) - * @size: Total size of the device in bytes + * @lba: Total number of blocks of the device * @devp: the new device (which has not been probed) */ int blk_create_device(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, - lbaint_t size, struct udevice **devp); + lbaint_t lba, struct udevice **devp); /** * blk_create_devicef() - Create a new named block device @@ -327,12 +327,12 @@ int blk_create_device(struct udevice *parent, const char *drv_name, * @devnum: Device number, specific to the interface type, or -1 to * allocate the next available number * @blksz: Block size of the device in bytes (typically 512) - * @size: Total size of the device in bytes + * @lba: Total number of blocks of the device * @devp: the new device (which has not been probed) */ int blk_create_devicef(struct udevice *parent, const char *drv_name, const char *name, int if_type, int devnum, int blksz, - lbaint_t size, struct udevice **devp); + lbaint_t lba, struct udevice **devp); /** * blk_prepare_device() - Prepare a block device for use diff --git a/test/dm/blk.c b/test/dm/blk.c index 5c5eb82..28790e9 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -23,9 +23,9 @@ static int dm_test_blk_base(struct unit_test_state *uts) /* Create two, one the parent of the other */ ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test", - IF_TYPE_HOST, 1, 512, 1024, &blk)); + IF_TYPE_HOST, 1, 512, 2, &blk)); ut_assertok(blk_create_device(blk, "usb_storage_blk", "test", - IF_TYPE_USB, 3, 512, 1024, &usb_blk)); + IF_TYPE_USB, 3, 512, 2, &usb_blk)); /* Check we can find them */ ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_HOST, 0, &dev)); @@ -101,7 +101,7 @@ static int dm_test_blk_find(struct unit_test_state *uts) struct udevice *blk, *dev; ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test", - IF_TYPE_HOST, 1, 512, 1024, &blk)); + IF_TYPE_HOST, 1, 512, 2, &blk)); ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev)); ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev)); ut_asserteq_ptr(blk, dev);