mmc: cat u8 to u64 to avoid unexpected error
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than 0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>
e.g.
u8 data_8; u64 data_64; data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mmc/mmc.c +4 -4
@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0 - | ext_csd[EXT_CSD_SEC_CNT +1 ] <<8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +1 ]) <<8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;
Signature · 1 line
1.9.1
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Quoted 8 lines · Haibo Chen
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than
0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>e.g.
Quoted 8 lines
u8 data_8; u64 data_64; data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000Signed-off-by Haibo Chen <[email protected]>
Please add a 'Reported-by: Coverity' and you can include the CID if you like.
Quoted 13 lines
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mmc/mmc.c +0
-1@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0
drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 1185
Quoted 10 lines
drivers/mmc/mmc.c +4
-3- | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +1 ]) <<8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;
Can't we just move capacity down to a u8 instead? Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160918/e901dc0d/attachment.sig>
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Quoted 13 lines · Tom Rini
Quoted 11 lines · Haibo Chen
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than
0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>e.g.
u8 data_8; u64 data_64;
Quoted 8 lines
Quoted 5 lines
data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000Signed-off-by Haibo Chen <[email protected]>Please add a 'Reported-by: Coverity' and you can include the CID if you like.
I think cid doesn't need to change type.
Quoted 18 lines
Quoted 18 lines
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mmc/mmc.c +1
-4@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0 - | ext_csd[EXT_CSD_SEC_CNT +1 ] <<8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0
Quoted 8 lines
drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 1185
Quoted 6 lines
drivers/mmc/mmc.c +3
-0+ | ((u64)ext_csd[EXT_CSD_SEC_CNT + 1]) << 8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;Can't we just move capacity down to a u8 instead? Thanks!
Maybe not to move down to a u8..because it's displayed the real capacity for storage.
And i wonder that coverity didn't report about the line 1294?
Best Regards,
Jaehoon Chung
Quoted 8 lines
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Quoted 18 lines · Jaehoon Chung
Quoted 17 lines · Tom Rini
Quoted 15 lines · Haibo Chen
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than
0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>e.g.
u8 data_8; u64 data_64; data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Haibo Chen <[email protected]>Please add a 'Reported-by: Coverity' and you can include the CID if you like.
I think cid doesn't need to change type.
I mean the coverity CID :) In the public coverity project it's 149300
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mmc/mmc.c +1
-4@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0 - | ext_csd[EXT_CSD_SEC_CNT +1 ] <<8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0 Quoted 8 lines
drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 1185
Quoted 6 lines
drivers/mmc/mmc.c +3
-0+ | ((u64)ext_csd[EXT_CSD_SEC_CNT + 1]) << 8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;Can't we just move capacity down to a u8 instead? Thanks!
Quoted 1 line
Maybe not to move down to a u8..because it's displayed the real capacity for storage.
We could update those lines too? It's just that one case right there, yes?
Quoted 1 line
And i wonder that coverity didn't report about the line 1294?
It does, along with 1256.
Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160919/e7f07b1f/attachment.sig>
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Quoted 19 lines · Tom Rini
Quoted 18 lines · Jaehoon Chung
Quoted 17 lines · Tom Rini
Quoted 15 lines · Haibo Chen
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than
0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>e.g.
u8 data_8; u64 data_64; data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Haibo Chen <[email protected]>Please add a 'Reported-by: Coverity' and you can include the CID if you like.
I think cid doesn't need to change type.
I mean the coverity CID :) In the public coverity project it's 149300
Ah! I misunderstood CID as cid register. :)
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 16 lines
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mmc/mmc.c +0
-1@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0 drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 1185
Quoted 10 lines
drivers/mmc/mmc.c +4
-3- | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +1 ]) <<8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;Can't we just move capacity down to a u8 instead? Thanks!
Quoted 4 lines
Quoted 1 line
Maybe not to move down to a u8..because it's displayed the real capacity for storage.
We could update those lines too? It's just that one case right there, yes?
If it's possible to calculate the correct capacity?
Best Regards,
Jaehoon Chung
Quoted 7 lines
Quoted 2 lines
And i wonder that coverity didn't report about the line 1294?
It does, along with 1256.
Thanks!
PATCH 1/1 mmc: cat u8 to u64 to avoid unexpected error
Quoted 60 lines · Jaehoon Chung
Quoted 19 lines · Tom Rini
Quoted 18 lines · Jaehoon Chung
Quoted 17 lines · Tom Rini
Quoted 15 lines · Haibo Chen
Suspicious implicit sign extension exist. ext_csd[] is defined as "u8", capacity is defined as u64, so u8 is promoted to signed int first int the "|" expersion, then the sign extended to u64. if the tmp sign value is largeer than
0x7fffffff, after the sign extension, the upper bits of the result will all be 1. Thanks to coverity <http://www.coverity.com>e.g.
u8 data_8; u64 data_64; data_8 = 0x80; data_64 = data_8 << 24; //0xffffffff80000000 data_64 = ((u64)data_8) << 24; //0x80000000Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Haibo Chen <[email protected]>Please add a 'Reported-by: Coverity' and you can include the CID if you like.
I think cid doesn't need to change type.
I mean the coverity CID :) In the public coverity project it's 149300
Ah! I misunderstood CID as cid register. :)
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 16 lines
--- drivers/mmc/mmc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/mmc/mmc.c +0
-1@@ -1176,10 +1176,10 @@ static int mmc_startup(struct mmc *mmc)* ext_csd's capacity is valid if the value is more * than 2GB */ - capacity = ext_csd[EXT_CSD_SEC_CNT ] <<0 drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 1185
Quoted 10 lines
drivers/mmc/mmc.c +4
-3- | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 - | ext_csd[EXT_CSD_SEC_CNT +2 ] <<16 - | ext_csd[EXT_CSD_SEC_CNT +3 ] <<24 ; + capacity = ((u64 )ext_csd[EXT_CSD_SEC_CNT ]) <<0 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +1 ]) <<8 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +2 ]) <<16 + | ((u64 )ext_csd[EXT_CSD_SEC_CNT +3 ]) <<24 ; capacity *=MMC_MAX_BLOCK_LEN ;if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity;Can't we just move capacity down to a u8 instead? Thanks!
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Maybe not to move down to a u8..because it's displayed the real capacity for storage.
We could update those lines too? It's just that one case right there, yes?
If it's possible to calculate the correct capacity?
... I think? I hadn't had my coffee yet when I did a quick compile test this morning but it looks like all of the uses of capacity would fit into a u8. Someone should check and make a formal patch :)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160919/9bb20c79/attachment.sig>