diff mbox series

[v2] selftests/android/ion: fix heap_type may be uninitialized

Message ID 20180405073907.30615-1-anders.roxell@linaro.org
State New
Headers show
Series [v2] selftests/android/ion: fix heap_type may be uninitialized | expand

Commit Message

Anders Roxell April 5, 2018, 7:39 a.m. UTC
gcc warns that 'heap_type' is not initialized if we don't come through
any of the two 'case' statesments before:

ionapp_export.c:91:2: warning: ‘heap_type’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
  printf("heap_type: %ld, heap_size: %ld\n", heap_type, heap_size);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In the current code, we initialize the heap_type to -1 before the 'case'
statements. We also change the print_usage function to state that
heap_type and heap_size isn't optional, they are mandatory.

Fixes: 47a18c42d992 ("android/ion: userspace test utility for ion buffer sharing")
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

---
 tools/testing/selftests/android/ion/ionapp_export.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

-- 
2.11.0

Comments

Pintu Agarwal April 6, 2018, 5:42 p.m. UTC | #1
On Thu, Apr 5, 2018 at 1:09 PM, Anders Roxell <anders.roxell@linaro.org> wrote:
> gcc warns that 'heap_type' is not initialized if we don't come through

> any of the two 'case' statesments before:

>

> ionapp_export.c:91:2: warning: ‘heap_type’ may be used uninitialized in

> this function [-Wmaybe-uninitialized]

>   printf("heap_type: %ld, heap_size: %ld\n", heap_type, heap_size);

>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>

> In the current code, we initialize the heap_type to -1 before the 'case'

> statements. We also change the print_usage function to state that

> heap_type and heap_size isn't optional, they are mandatory.

>

> Fixes: 47a18c42d992 ("android/ion: userspace test utility for ion buffer sharing")

> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

> ---

>  tools/testing/selftests/android/ion/ionapp_export.c | 13 ++++++++-----

>  1 file changed, 8 insertions(+), 5 deletions(-)

>

> diff --git a/tools/testing/selftests/android/ion/ionapp_export.c b/tools/testing/selftests/android/ion/ionapp_export.c

> index a944e72621a9..67a0263a7f28 100644

> --- a/tools/testing/selftests/android/ion/ionapp_export.c

> +++ b/tools/testing/selftests/android/ion/ionapp_export.c

> @@ -31,8 +31,10 @@

>

>  void print_usage(int argc, char *argv[])

>  {

> -       printf("Usage: %s [-h <help>] [-i <heap id>] [-s <size in bytes>]\n",

> +       printf("Usage: %s [-h <help>] -i <heap id> -s <size in bytes>\n",

>                 argv[0]);

> +       printf("    Supported heap id's 0 or 1\n");

> +       printf("    Heap size > 0\n");

>  }

>

>  int main(int argc, char *argv[])

> @@ -40,7 +42,8 @@ int main(int argc, char *argv[])

>         int opt, ret, status, heapid;

>         int sockfd, client_fd, shared_fd;

>         unsigned char *map_buf;

> -       unsigned long map_len, heap_type, heap_size, flags;

> +       unsigned long map_len, heap_size, flags;

> +       long heap_type;

>         struct ion_buffer_info info;

>         struct socket_info skinfo;

>

> @@ -50,6 +53,7 @@ int main(int argc, char *argv[])

>         }

>

>         heap_size = 0;

> +       heap_type = -1;

>         flags = 0;

>


To make it simple, I would suggest, let the default heap_type be 0.
Actually that was my original intention but I would have missed it
during submission.
In that case nothing below is required to change.

>         while ((opt = getopt(argc, argv, "hi:s:")) != -1) {

> @@ -68,7 +72,7 @@ int main(int argc, char *argv[])

>                                 heap_type = ION_HEAP_TYPE_SYSTEM_CONTIG;

>                                 break;

>                         default:

> -                               printf("ERROR: heap type not supported\n");

> +                               print_usage(argc, argv);

>                                 exit(1);

>                         }

>                         break;

> @@ -82,8 +86,7 @@ int main(int argc, char *argv[])

>                 }

>         }

>

> -       if (heap_size <= 0) {

> -               printf("heap_size cannot be 0\n");

> +       if (heap_size <= 0 || heap_type < 0) {

>                 print_usage(argc, argv);

>                 exit(1);

>         }

> --

> 2.11.0

>
Sasha Levin April 9, 2018, 3:36 a.m. UTC | #2
Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag,
fixing commit: 47a18c42d992 android/ion: userspace test utility for ion buffer sharing.

The bot has also determined it's probably a bug fixing patch. (score: 30.2608)

The bot has tested the following trees: v4.16, v4.15.15.

v4.16: Build OK!
v4.15.15: Build OK!

--
Thanks,
Sasha
diff mbox series

Patch

diff --git a/tools/testing/selftests/android/ion/ionapp_export.c b/tools/testing/selftests/android/ion/ionapp_export.c
index a944e72621a9..67a0263a7f28 100644
--- a/tools/testing/selftests/android/ion/ionapp_export.c
+++ b/tools/testing/selftests/android/ion/ionapp_export.c
@@ -31,8 +31,10 @@ 
 
 void print_usage(int argc, char *argv[])
 {
-	printf("Usage: %s [-h <help>] [-i <heap id>] [-s <size in bytes>]\n",
+	printf("Usage: %s [-h <help>] -i <heap id> -s <size in bytes>\n",
 		argv[0]);
+	printf("    Supported heap id's 0 or 1\n");
+	printf("    Heap size > 0\n");
 }
 
 int main(int argc, char *argv[])
@@ -40,7 +42,8 @@  int main(int argc, char *argv[])
 	int opt, ret, status, heapid;
 	int sockfd, client_fd, shared_fd;
 	unsigned char *map_buf;
-	unsigned long map_len, heap_type, heap_size, flags;
+	unsigned long map_len, heap_size, flags;
+	long heap_type;
 	struct ion_buffer_info info;
 	struct socket_info skinfo;
 
@@ -50,6 +53,7 @@  int main(int argc, char *argv[])
 	}
 
 	heap_size = 0;
+	heap_type = -1;
 	flags = 0;
 
 	while ((opt = getopt(argc, argv, "hi:s:")) != -1) {
@@ -68,7 +72,7 @@  int main(int argc, char *argv[])
 				heap_type = ION_HEAP_TYPE_SYSTEM_CONTIG;
 				break;
 			default:
-				printf("ERROR: heap type not supported\n");
+				print_usage(argc, argv);
 				exit(1);
 			}
 			break;
@@ -82,8 +86,7 @@  int main(int argc, char *argv[])
 		}
 	}
 
-	if (heap_size <= 0) {
-		printf("heap_size cannot be 0\n");
+	if (heap_size <= 0 || heap_type < 0) {
 		print_usage(argc, argv);
 		exit(1);
 	}