mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anders Roxell <anders.roxell@linaro.org>
To: shuah@kernel.org
Cc: pintu.ping@gmail.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Anders Roxell <anders.roxell@linaro.org>
Subject: [PATCH] selftests/android/ion: fix heap_type may be uninitialized
Date: Thu,  8 Mar 2018 14:48:45 +0100	[thread overview]
Message-ID: <20180308134845.32409-1-anders.roxell@linaro.org> (raw)

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>
---
 .../testing/selftests/android/ion/ionapp_export.c  | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/android/ion/ionapp_export.c b/tools/testing/selftests/android/ion/ionapp_export.c
index a944e72621a9..b42f803e9d2a 100644
--- a/tools/testing/selftests/android/ion/ionapp_export.c
+++ b/tools/testing/selftests/android/ion/ionapp_export.c
@@ -31,16 +31,24 @@
 
 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]);
 }
 
+void heap_type_error_text(void)
+{
+	printf("heap_type must be specified\n");
+	printf("  need to specify -i <heap_type>\n");
+	printf("  supported heap types 0 or 1\n");
+}
+
 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 +58,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 +77,8 @@ int main(int argc, char *argv[])
 				heap_type = ION_HEAP_TYPE_SYSTEM_CONTIG;
 				break;
 			default:
-				printf("ERROR: heap type not supported\n");
+				heap_type_error_text();
+				print_usage(argc, argv);
 				exit(1);
 			}
 			break;
@@ -82,8 +92,15 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (heap_type < 0) {
+		heap_type_error_text();
+		print_usage(argc, argv);
+		exit(1);
+	}
+
 	if (heap_size <= 0) {
 		printf("heap_size cannot be 0\n");
+		printf("  need to specify -s <heap_size>\n");
 		print_usage(argc, argv);
 		exit(1);
 	}
-- 
2.11.0


             reply	other threads:[~2018-03-08 13:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 13:48 Anders Roxell [this message]
2018-03-16 10:14 ` Pintu Kumar
2018-04-05  7:39 ` [PATCH v2] " Anders Roxell
2018-04-06 17:42   ` Pintu Kumar
2018-04-09  3:36   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180308134845.32409-1-anders.roxell@linaro.org \
    --to=anders.roxell@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pintu.ping@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®