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

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

 



 
> 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.
If any, I would just revert commit a1b594ca735e.

Thanks,
Avri

> 
> Signed-off-by: Giulio Benetti <giulio.benetti@xxxxxxxxxxxxxxxxxxxxxx>
> ---
>  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
> 






[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux