U-boot Archive mirror
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math
@ 2015-06-12  0:53 Tom Rini
  2015-06-12  7:32 ` Bernhard Nortmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tom Rini @ 2015-06-12  0:53 UTC (permalink / raw
  To: u-boot

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>
---
 drivers/mmc/mmc_write.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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",
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math
  2015-06-12  0:53 [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math Tom Rini
@ 2015-06-12  7:32 ` Bernhard Nortmann
  2015-06-16  9:53 ` [U-Boot] " Hans de Goede
  2015-06-18 22:46 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Bernhard Nortmann @ 2015-06-12  7:32 UTC (permalink / raw
  To: u-boot

Tom Rini <trini <at> konsulko.com> writes:
> 
> 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.
> 
> ---
>  drivers/mmc/mmc_write.c |   12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
> index 3db9669..7aea7e9 100644

Hi Tom!

I can confirm that this patch solves the CONFIG_SYS_64BIT_LBA compilation
issue with armhf for me (gcc 4.8.3 armv7a-hardfloat-linux-gnueabi, on a
Banana Pi = sun7i/A20).

So I'll add a
Tested-by: Bernhard Nortmann <bernhard.nortmann@web.de>

BTW: There's a small typo you also might want to fix: "The erase range would
be change to " -> "The erase range would be changed to "

Regards, B. Nortmann

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] mmc_write.c: Make mmc_berase do 32bit safe 64bit math
  2015-06-12  0:53 [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math Tom Rini
  2015-06-12  7:32 ` Bernhard Nortmann
@ 2015-06-16  9:53 ` Hans de Goede
  2015-06-18 22:46 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2015-06-16  9:53 UTC (permalink / raw
  To: u-boot

Hi,

On 12-06-15 02:53, Tom Rini wrote:
> 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>

Thanks for this, looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans

> ---
>   drivers/mmc/mmc_write.c |   12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
>
> 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",
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] mmc_write.c: Make mmc_berase do 32bit safe 64bit math
  2015-06-12  0:53 [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math Tom Rini
  2015-06-12  7:32 ` Bernhard Nortmann
  2015-06-16  9:53 ` [U-Boot] " Hans de Goede
@ 2015-06-18 22:46 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2015-06-18 22:46 UTC (permalink / raw
  To: u-boot

On Thu, Jun 11, 2015 at 08:53:31PM -0400, Tom Rini wrote:

> 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>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150618/8803b632/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-18 22:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-12  0:53 [U-Boot] [PATCH] mmc_write.c: Make mmc_berase do 32bit safe 64bit math Tom Rini
2015-06-12  7:32 ` Bernhard Nortmann
2015-06-16  9:53 ` [U-Boot] " Hans de Goede
2015-06-18 22:46 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).