Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH] mmc-utils: mmc_cmds: fix type-punned warning on &ext_csd[] casting
@ 2024-03-05 10:59 Giulio Benetti
  2024-03-05 14:52 ` Avri Altman
  0 siblings, 1 reply; 7+ messages in thread
From: Giulio Benetti @ 2024-03-05 10:59 UTC (permalink / raw)
  To: linux-mmc; +Cc: Giulio Benetti

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 --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--) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-07 11:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 10:59 [PATCH] mmc-utils: mmc_cmds: fix type-punned warning on &ext_csd[] casting Giulio Benetti
2024-03-05 14:52 ` Avri Altman
2024-03-05 15:01   ` Avri Altman
2024-03-05 18:45     ` [PATCH v2] " Giulio Benetti
2024-03-05 19:48       ` Avri Altman
2024-03-07 11:02       ` Ulf Hansson
2024-03-05 18:46     ` [PATCH] " Giulio Benetti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox