[02/12] libflash/mbox-flash: Fix unintentional integer overflow (CID 142226)

Message ID 20170803064551.3439-2-cyril.bur@au1.ibm.com
State Accepted
Headers show

Commit Message

Cyril Bur Aug. 3, 2017, 6:45 a.m.
Fixes: CID 142226 (#1 of 1):
overflow_before_widen: Potentially overflowing expression
`1 << mbox_flash->shift` with type int (32 bits, signed) is evaluated using
32-bit arithmetic, and then used in a context that expects an expression
of type uint64_t (64 bits, unsigned).

Fixes: CID 142226
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 libflash/mbox-flash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch

diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c
index 7491d3b1..950e24f0 100644
--- a/libflash/mbox-flash.c
+++ b/libflash/mbox-flash.c
@@ -141,9 +141,9 @@  static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos,
 	return 0;
 }
 
-__unused static uint64_t mbox_flash_mask(struct mbox_flash_data *mbox_flash)
+static uint64_t mbox_flash_mask(struct mbox_flash_data *mbox_flash)
 {
-	return (1 << mbox_flash->shift) - 1;
+	return (1ULL << mbox_flash->shift) - 1;
 }
 
 __unused static uint8_t msg_get_u8(struct bmc_mbox_msg *msg, int i)