diff mbox series

mmc-utils: mmc_cmds: fix type-punned warning on &ext_csd[] casting

Message ID 20240305105949.392092-1-giulio.benetti@benettiengineering.com
State New
Headers show
Series mmc-utils: mmc_cmds: fix type-punned warning on &ext_csd[] casting | expand

Commit Message

Giulio Benetti March 5, 2024, 10:59 a.m. UTC
When building with -Werror=strict-aliasing error is thrown:

mmc_cmds.c: In function 'do_ffu':
mmc_cmds.c:2972:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  sect_done = htole32(*((__u32 *)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0]));
  ^
cc1: all warnings being treated as errors

Let's fix type-punned breaking strict-aliasing by memcpy() the variable.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
 mmc_cmds.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/mmc_cmds.c b/mmc_cmds.c
index ae7b876..dcd60aa 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2968,7 +2968,8 @@  do_retry:
 	}
 
 	/* Test if we need to restart the download */
-	sect_done = htole32(*((__u32 *)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0]));
+	memcpy(&sect_done, &ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0], sizeof(__u32));
+	sect_done = htole32(sect_done);
 	/* By spec, host should re-start download from the first sector if sect_done is 0 */
 	if (sect_done == 0) {
 		if (retry--) {