From: Juergen Borleis <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Juergen Borleis <jbe@pengutronix.de>
Subject: [PATCH 1/5] commands: mmc_extcsd: print_field: fix 32 bit overflow
Date: Wed, 9 Sep 2020 13:01:14 +0200 [thread overview]
Message-ID: <20200909110118.19923-1-jbe@pengutronix.de> (raw)
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
commands/mmc_extcsd.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/commands/mmc_extcsd.c b/commands/mmc_extcsd.c
index c9a28fb1fe..40d11df17d 100644
--- a/commands/mmc_extcsd.c
+++ b/commands/mmc_extcsd.c
@@ -11,6 +11,7 @@
#include <mci.h>
#include <getopt.h>
#include <fs.h>
+#include <linux/sizes.h>
#define EXT_CSD_BLOCKSIZE 512
@@ -1142,7 +1143,7 @@ static int print_field(u8 *reg, int index)
return 1;
case EXT_CSD_SEC_COUNT:
- tmp64 = val * 512;
+ tmp64 *= 512;
printf("\tDevice density: %llu B\n", tmp64);
return 1;
@@ -1232,7 +1233,7 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_HC_ERASE_GRP_SIZE:
val = get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- val = val * 524288;
+ val = val * SZ_512K;
if (val)
str = basprintf("Erase-unit size: %u", val);
else
@@ -1342,7 +1343,8 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_ENH_SIZE_MULT:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tEnhanced User Data Area %i Size: %llu B\n",
index - EXT_CSD_ENH_SIZE_MULT, tmp64);
return 1;
@@ -1350,28 +1352,32 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_GP_SIZE_MULT3:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_3 Size: %llu B\n", tmp64);
return 1;
case EXT_CSD_GP_SIZE_MULT2:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_2 Size: %llu B\n", tmp64);
return 1;
case EXT_CSD_GP_SIZE_MULT1:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_1 Size: %llu B\n", tmp64);
return 1;
case EXT_CSD_GP_SIZE_MULT0:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tGeneral_Purpose_Partition_0 Size: %llu B\n", tmp64);
return 1;
@@ -1422,7 +1428,8 @@ static int print_field(u8 *reg, int index)
case EXT_CSD_MAX_ENH_SIZE_MULT:
tmp = get_field_val(EXT_CSD_HC_WP_GRP_SIZE, 0, 0xFF);
tmp = tmp + get_field_val(EXT_CSD_HC_ERASE_GRP_SIZE, 0, 0xFF);
- tmp64 = val * tmp * 524288;
+ tmp64 *= tmp;
+ tmp64 *= SZ_512K;
printf("\tMax Enhanced Area: %llu B\n", tmp64);
return 1;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2020-09-09 11:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 11:01 Juergen Borleis [this message]
2020-09-09 11:01 ` [PATCH 2/5] commands: mmc_extcsd: print_field: fix layout Juergen Borleis
2020-09-09 11:01 ` [PATCH 3/5] mci: mci-core: fix long lasting FIXMEs Juergen Borleis
2020-09-14 14:58 ` Ahmad Fatoum
2020-09-14 18:02 ` Sascha Hauer
2020-09-15 7:45 ` Juergen Borleis
2020-09-15 7:52 ` [PATCH v2] " Juergen Borleis
2020-09-15 12:36 ` Sascha Hauer
2020-09-09 11:01 ` [PATCH 4/5] mci: kconfig: explain what boot partitions are Juergen Borleis
2020-09-09 11:01 ` [PATCH 5/5] mci: mci-core: add GPP support Juergen Borleis
2020-09-14 10:07 ` [PATCH 1/5] commands: mmc_extcsd: print_field: fix 32 bit overflow Sascha Hauer
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=20200909110118.19923-1-jbe@pengutronix.de \
--to=jbe@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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