Bug#1030829: mmc-utils: FTBFS on ppc64el with error: ‘cnt’ may be used uninitialized

2023-02-25 Thread Adrian Bunk
Control: severity -1 normal

On Tue, Feb 07, 2023 at 04:38:20PM -0500, Nick Rosbrook wrote:
> Package: mmc-utils
> Severity: serious
> Tags: patch ftbfs
> Justification: fails to build from source (but built successfully in the past)
> User: ubuntu-de...@lists.ubuntu.com
> Usertags: origin-ubuntu lunar ubuntu-patch
> 
> Dear Maintainer,
> 
> In Ubuntu, mcc-utils FTBFS[1] on ppc64el with the following:

Note that this is an Ubuntu-only FTBFS.

For some reason Canonical has chosen to make ppc64el in Ubuntu different 
from all other architectures in Ubuntu and all architectures in Debian
(including ppc64el) by defaulting to build with -O3 instead of -O2.

>  In file included from /usr/include/endian.h:35,
>   from /usr/include/powerpc64le-linux-gnu/sys/types.h:176,
>   from /usr/include/stdlib.h:395,
>   from mmc_cmds.c:21:
>  In function ‘__bswap_32’,
>  inlined from ‘do_rpmb_write_block’ at mmc_cmds.c:2462:27:
>  /usr/include/powerpc64le-linux-gnu/bits/byteswap.h:52:10: error: ‘cnt’ may 
> be used uninitialized [-Werror=maybe-uninitialized]
> 52 |   return __builtin_bswap32 (__bsx);
>|  ^
>...

The fix is not wrong, but I don't think there is an actual bug:
cnt is uninitialized only in the ret != 0 case,
that does already exit(1) two lines earlier.

cu
Adrian



Bug#1030829: mmc-utils: FTBFS on ppc64el with error: ‘cnt’ may be used uninitialized

2023-02-07 Thread Nick Rosbrook
Package: mmc-utils
Severity: serious
Tags: patch ftbfs
Justification: fails to build from source (but built successfully in the past)
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu lunar ubuntu-patch

Dear Maintainer,

In Ubuntu, mcc-utils FTBFS[1] on ppc64el with the following:

 In file included from /usr/include/endian.h:35,
  from /usr/include/powerpc64le-linux-gnu/sys/types.h:176,
  from /usr/include/stdlib.h:395,
  from mmc_cmds.c:21:
 In function ‘__bswap_32’,
 inlined from ‘do_rpmb_write_block’ at mmc_cmds.c:2462:27:
 /usr/include/powerpc64le-linux-gnu/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:2439:22: note: ‘cnt’ was declared here
  2439 | unsigned int cnt;
   |  ^~~
 cc1: all warnings being treated as errors
 make[1]: *** [Makefile:36: mmc_cmds.o] Error 1
 make[1]: Leaving directory '/<>'
 dh_auto_build: error: make -j4 "INSTALL=install --strip-program=true" returned 
exit code 2
 make: *** [debian/rules:8: binary-arch] Error 25
 dpkg-buildpackage: error: debian/rules binary-arch subprocess returned exit 
status 2
 


This was already fixed upstream[2]. We applied the patch in Ubuntu to fix
the build on ppc64el.

Thanks,
Nick

[1] 
https://launchpadlibrarian.net/648312622/buildlog_ubuntu-lunar-ppc64el.mmc-utils_0+git20220624.d7b343fd-1_BUILDING.txt.gz
[2] 
https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/commit/?id=5086e7c0de4d0094f8674368a88d931b27589d53
diff -Nru 
mmc-utils-0+git20220624.d7b343fd/debian/patches/0003-fix-warning-on-uninitialized-cnt.patch
 
mmc-utils-0+git20220624.d7b343fd/debian/patches/0003-fix-warning-on-uninitialized-cnt.patch
--- 
mmc-utils-0+git20220624.d7b343fd/debian/patches/0003-fix-warning-on-uninitialized-cnt.patch
 1969-12-31 19:00:00.0 -0500
+++ 
mmc-utils-0+git20220624.d7b343fd/debian/patches/0003-fix-warning-on-uninitialized-cnt.patch
 2023-02-07 15:14:11.0 -0500
@@ -0,0 +1,54 @@
+Description: mmc-utils: fix warning on uninitialized 'cnt'
+Origin: 
https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/commit/?id=5086e7c0de4d0094f8674368a88d931b27589d53
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/mmc-utils/+bug/2006505
+Last-Update: 2023-02-07
+---
+From 5086e7c0de4d0094f8674368a88d931b27589d53 Mon Sep 17 00:00:00 2001
+From: Giulio Benetti 
+Date: Sun, 18 Sep 2022 18:17:51 +0200
+Subject: mmc-utils: fix warning on uninitialized 'cnt'
+
+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 
+Reviewed-by: Avri Altman 
+Link: 
https://lore.kernel.org/r/20220918161751.1132590-1-giulio.bene...@benettiengineering.com
+Signed-off-by: Ulf Hansson 
+---
+ mmc_cmds.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/mmc_cmds.c b/mmc_cmds.c
+index ef1d8c6..29abd1d 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);
+ 
+-- 
+cgit 
+
diff -Nru mmc-utils-0+git20220624.d7b343fd/debian/patches/series 
mmc-utils-0+git20220624.d7b343fd/debian/patches/series
--- mmc-utils-0+git20220624.d7b343fd/debian/patches/series  2022-08-04 
02:07:11.0 -0400
+++ mmc-utils-0+git20220624.d7b343fd/debian/patches/series  2023-02-07 
15:09:50.0 -0500
@@ -1,2 +1,3 @@
 0001-Fix-typo.patch
 0002-man-mmc.1-Fix-warning-macro-not-defined.patch
+0003-fix-warning-on-uninitialized-cnt.patch