summaryrefslogtreecommitdiff
path: root/drivers/mmc
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2015-06-11 20:53:31 -0400
committerTom Rini <trini@konsulko.com>2015-06-18 16:11:41 -0400
commit180f87fcc58936fb8d9e5a6babce739666c50b13 (patch)
tree90c757fdd1cb7eacb8c9696786f256ae30284960 /drivers/mmc
parent14ec12fa6f3da065842a3428f6cd620f04abcd58 (diff)
downloadu-boot-imx-180f87fcc58936fb8d9e5a6babce739666c50b13.zip
u-boot-imx-180f87fcc58936fb8d9e5a6babce739666c50b13.tar.gz
u-boot-imx-180f87fcc58936fb8d9e5a6babce739666c50b13.tar.bz2
mmc_write.c: Make mmc_berase do 32bit safe 64bit math
We want to see if the requested start or total block count are unaligned. We discard the whole numbers and only care about the remainder. Update the code to use div_u64_rem here and add a comment. Cc: Hans de Goede <hdegoede@redhat.com> Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Cc: Bernhard Nortmann <bernhard.nortmann@web.de> Reported-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com> Tested-by: Bernhard Nortmann <bernhard.nortmann@web.de> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/mmc_write.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index 3db9669..7aea7e9 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -10,6 +10,8 @@
#include <config.h>
#include <common.h>
#include <part.h>
+#include <div64.h>
+#include <linux/math64.h>
#include "mmc_private.h"
static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt)
@@ -66,6 +68,7 @@ err_out:
unsigned long mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)
{
int err = 0;
+ u32 start_rem, blkcnt_rem;
struct mmc *mmc = find_mmc_device(dev_num);
lbaint_t blk = 0, blk_r = 0;
int timeout = 1000;
@@ -73,7 +76,14 @@ unsigned long mmc_berase(int dev_num, lbaint_t start, lbaint_t blkcnt)
if (!mmc)
return -1;
- if ((start % mmc->erase_grp_size) || (blkcnt % mmc->erase_grp_size))
+ /*
+ * We want to see if the requested start or total block count are
+ * unaligned. We discard the whole numbers and only care about the
+ * remainder.
+ */
+ err = div_u64_rem(start, mmc->erase_grp_size, &start_rem);
+ err = div_u64_rem(blkcnt, mmc->erase_grp_size, &blkcnt_rem);
+ if (start_rem || blkcnt_rem)
printf("\n\nCaution! Your devices Erase group is 0x%x\n"
"The erase range would be change to "
"0x" LBAF "~0x" LBAF "\n\n",