diff mbox series

[v3] mmc-utils: fix warning on uninitialized 'cnt'

Message ID 20220918161751.1132590-1-giulio.benetti@benettiengineering.com (mailing list archive)
State New, archived
Headers show
Series [v3] mmc-utils: fix warning on uninitialized 'cnt' | expand

Commit Message

Giulio Benetti Sept. 18, 2022, 4:17 p.m. UTC
When building following warning shows up:
```
In function '__bswap_32',
    inlined from 'do_rpmb_write_block' at mmc_cmds.c:2293:27:
/home/autobuild/autobuild/instance-15/output-1/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/bits/byteswap.h:52:10: error: 'cnt' may be used uninitialized [-Werror=maybe-uninitialized]
   52 |   return __builtin_bswap32 (__bsx);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
mmc_cmds.c: In function 'do_rpmb_write_block':
mmc_cmds.c:2270:22: note: 'cnt' was declared here
2270 |         unsigned int cnt;
      |                      ^~~
cc1: all warnings being treated as errors
```
This is due to function rpmb_read_counter() that doesn't set its
argument 'unsigned int *cnt' in all return points. So let's set
*cnt to 0 in the return point that misses to initialize it.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
V1->V2:
* prefix subject with 'mmc-utils:' as pointed by Avri Altman
V2->V3:
* add missing commit as pointed by Avri Altman
* initialize pointer inside rpmb_read_counter() as suggested by Arnd Bergmann
---
 mmc_cmds.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Avri Altman Sept. 19, 2022, 10:13 a.m. UTC | #1
> When building following warning shows up:
> ```
> In function '__bswap_32',
>     inlined from 'do_rpmb_write_block' at mmc_cmds.c:2293:27:
> /home/autobuild/autobuild/instance-15/output-1/host/aarch64-buildroot-
> linux-gnu/sysroot/usr/include/bits/byteswap.h:52:10: error: 'cnt' may be
> used uninitialized [-Werror=maybe-uninitialized]
>    52 |   return __builtin_bswap32 (__bsx);
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~
> mmc_cmds.c: In function 'do_rpmb_write_block':
> mmc_cmds.c:2270:22: note: 'cnt' was declared here
> 2270 |         unsigned int cnt;
>       |                      ^~~
> cc1: all warnings being treated as errors ``` This is due to function
> rpmb_read_counter() that doesn't set its argument 'unsigned int *cnt' in all
> return points. So let's set *cnt to 0 in the return point that misses to initialize
> it.
> 
> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>


> ---
> V1->V2:
> * prefix subject with 'mmc-utils:' as pointed by Avri Altman
> V2->V3:
> * add missing commit as pointed by Avri Altman
> * initialize pointer inside rpmb_read_counter() as suggested by Arnd
> Bergmann
> ---
>  mmc_cmds.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 12b7802..4d203ef 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -2238,8 +2238,10 @@ int rpmb_read_counter(int dev_fd, unsigned int
> *cnt)
>         }
> 
>         /* Check RPMB response */
> -       if (frame_out.result != 0)
> +       if (frame_out.result != 0) {
> +               *cnt = 0;
>                 return be16toh(frame_out.result);
> +       }
> 
>         *cnt = be32toh(frame_out.write_counter);
> 
> --
> 2.34.1
Ulf Hansson Sept. 21, 2022, 12:49 p.m. UTC | #2
On Sun, 18 Sept 2022 at 18:17, Giulio Benetti
<giulio.benetti@benettiengineering.com> wrote:
>
> When building following warning shows up:
> ```
> In function '__bswap_32',
>     inlined from 'do_rpmb_write_block' at mmc_cmds.c:2293:27:
> /home/autobuild/autobuild/instance-15/output-1/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/bits/byteswap.h:52:10: error: 'cnt' may be used uninitialized [-Werror=maybe-uninitialized]
>    52 |   return __builtin_bswap32 (__bsx);
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~
> mmc_cmds.c: In function 'do_rpmb_write_block':
> mmc_cmds.c:2270:22: note: 'cnt' was declared here
> 2270 |         unsigned int cnt;
>       |                      ^~~
> cc1: all warnings being treated as errors
> ```
> This is due to function rpmb_read_counter() that doesn't set its
> argument 'unsigned int *cnt' in all return points. So let's set
> *cnt to 0 in the return point that misses to initialize it.
>
> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>

Applied to git.kernel.org/pub/scm//utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe


> ---
> V1->V2:
> * prefix subject with 'mmc-utils:' as pointed by Avri Altman
> V2->V3:
> * add missing commit as pointed by Avri Altman
> * initialize pointer inside rpmb_read_counter() as suggested by Arnd Bergmann
> ---
>  mmc_cmds.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 12b7802..4d203ef 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -2238,8 +2238,10 @@ int rpmb_read_counter(int dev_fd, unsigned int *cnt)
>         }
>
>         /* Check RPMB response */
> -       if (frame_out.result != 0)
> +       if (frame_out.result != 0) {
> +               *cnt = 0;
>                 return be16toh(frame_out.result);
> +       }
>
>         *cnt = be32toh(frame_out.write_counter);
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/mmc_cmds.c b/mmc_cmds.c
index 12b7802..4d203ef 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2238,8 +2238,10 @@  int rpmb_read_counter(int dev_fd, unsigned int *cnt)
 	}
 
 	/* Check RPMB response */
-	if (frame_out.result != 0)
+	if (frame_out.result != 0) {
+		*cnt = 0;
 		return be16toh(frame_out.result);
+	}
 
 	*cnt = be32toh(frame_out.write_counter);