[PATCH] mci: fix wrong sd/mmc/emmc card size computation for arch where char is signed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



char type can be either signed or unsigned according to C standard.
If your arch has signed char, this kind of computation will end up wrong
because of sign extension:

https://git.pengutronix.de/cgit/barebox/tree/drivers/mci/mci-core.c#n869

mci->capacity = mci->ext_csd[EXT_CSD_SEC_COUNT] << 0 |
		mci->ext_csd[EXT_CSD_SEC_COUNT + 1] << 8 |
		mci->ext_csd[EXT_CSD_SEC_COUNT + 2] << 16 |
		mci->ext_csd[EXT_CSD_SEC_COUNT + 3] << 24;

Turning the ext_csd field into u8 * fixes the issue.
---
 include/mci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/mci.h b/include/mci.h
index 96547fb39..f6d845440 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -456,7 +456,7 @@ struct mci {
 	uint64_t capacity;	/**< Card's data capacity in bytes */
 	int ready_for_use;	/** true if already probed */
 	int dsr_imp;		/**< DSR implementation state from CSD */
-	char *ext_csd;
+	u8 *ext_csd;
 	int probe;
 	struct param_d *param_boot;
 	int bootpart;
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux