From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] disk: Don't assume blksz > legacy_mbr
Date: Tue, 3 Oct 2017 11:30:07 -0400 [thread overview]
Message-ID: <20171003153015.13458-1-robdclark@gmail.com> (raw)
On some devices, this does not appear to be a valid assumption. So
figure out the number of blocks we actually need to read.
Signed-off-by: Rob Clark <robdclark@gmail.com>
---
Sorry, took a bit longer to get to a point of testing this.. somehow
himport_r() of the default_environment is clobbering my usb keyboard's
usb_device, which I'm still tracking down. Good thing that pointers
overwritten with ascii are fairly obvious.
disk/part_dos.c | 6 ++++--
disk/part_efi.c | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 1a36be0446..a9d23e121c 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -89,9 +89,11 @@ static int test_block_type(unsigned char *buffer)
static int part_test_dos(struct blk_desc *dev_desc)
{
- ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+ /* blksz *should* be a PoT, but to be safe use DIV_ROUND_UP: */
+ lbaint_t blkcnt = DIV_ROUND_UP(sizeof(legacy_mbr), dev_desc->blksz);
+ ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, blkcnt * dev_desc->blksz);
- if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
+ if (blk_dread(dev_desc, 0, blkcnt, (ulong *)mbr) != 1)
return -1;
if (test_block_type((unsigned char *)mbr) != DOS_MBR)
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 208bb14ee8..e00f6c9d24 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -923,7 +923,9 @@ static int is_pmbr_valid(legacy_mbr * mbr)
static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
gpt_header *pgpt_head, gpt_entry **pgpt_pte)
{
- ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+ /* blksz *should* be a PoT, but to be safe use DIV_ROUND_UP: */
+ lbaint_t blkcnt = DIV_ROUND_UP(sizeof(legacy_mbr), dev_desc->blksz);
+ ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, blkcnt * dev_desc->blksz);
if (!dev_desc || !pgpt_head) {
printf("%s: Invalid Argument(s)\n", __func__);
@@ -931,7 +933,7 @@ static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
}
/* Read MBR Header from device */
- if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) {
+ if (blk_dread(dev_desc, 0, blkcnt, (ulong *)mbr) != 1) {
printf("*** ERROR: Can't read MBR header ***\n");
return 0;
}
--
2.13.5
next reply other threads:[~2017-10-03 15:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-03 15:30 Rob Clark [this message]
2017-10-03 16:04 ` [U-Boot] [PATCH] disk: Don't assume blksz > legacy_mbr Fabio Estevam
2017-10-03 16:32 ` Rob Clark
2017-10-04 14:11 ` Rob Clark
2017-10-04 14:27 ` Fabio Estevam
2017-10-04 14:51 ` Rob Clark
2017-10-04 16:08 ` Fabio Estevam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171003153015.13458-1-robdclark@gmail.com \
--to=robdclark@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox