Received: by 10.213.65.68 with SMTP id h4csp896786imn; Fri, 6 Apr 2018 10:45:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx48ngu7uc7pISBuCi4+T/Qf1+cn0SbW2UjZU/khG0GYmahiVELQvKgAmgYQnI92A617DBJxb X-Received: by 2002:a17:902:2983:: with SMTP id h3-v6mr28422965plb.346.1523036752903; Fri, 06 Apr 2018 10:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523036752; cv=none; d=google.com; s=arc-20160816; b=zgZuoJ4ZrF60S3/GFs3eAhRGrF2VI6k3Rl5iYhOr5uS523J7H6ORvAKPIEjhGQTo9m KCSHah26IiVx7sq2TRpQoIGPxShIKEeTzWMxyJCtpuFKOWe7kGg3ZTFheRS+n4Hm1Nz/ 7cgx5QalR0gRzyDUPQiDH/bCRgzK+HZdf5EbBc95E9MDHDu2OS/E+WJrT18vbFzIN3Vy nnB96MidpKe1JEUeACzsbcaDQDwTQ1ZhHin0+vu09wjUdREbCh/4c4lmXHf8QPQhxZzZ QUPn7sVbTuQ+WtMJvXhJ0XX404cDBeX53vU7LdVmIwnKp5lg+WWyNsoC7vNffeL8R/VE TyPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=kjuR2yLHoSPDibknt87zrlf2eBxKskQalGJInyHPLKc=; b=AG5s0HbgU3EpOKH2QLTd+1F6ha8GieGikmRKbGGcXDQlNzoNfnnNDEnKH2VZN6i2mU qgtAQ1uHM+40/skIHo1seXcf6oYeoQrWHjScYHqScQnkodNZ+1aML4yWSIH9EykQTntF jgo1kJy1crlMCwA5nO4T3a9+FyKk98SGlAgOsATPlGCnDDJgAaewxHrxEz0Tbu7gcT1E 24/Pohb/PGxAbu8UXaQsBfn+zA+Oyb2u5cluFAH+AUOOZ6OpOR1vk/gpqvjyAQCYG5Tw Pl/ahVn8sYGeZW/2dykP/E+RqY7PT1HHUcm6AAhPZB36aJxy7JrInBikmWuH1csZxYPQ KzEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fEeKo9oQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q64si8262143pfq.385.2018.04.06.10.45.15; Fri, 06 Apr 2018 10:45:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fEeKo9oQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751558AbeDFRmE (ORCPT + 99 others); Fri, 6 Apr 2018 13:42:04 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:43804 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751201AbeDFRmC (ORCPT ); Fri, 6 Apr 2018 13:42:02 -0400 Received: by mail-vk0-f68.google.com with SMTP id v134so1140590vkd.10; Fri, 06 Apr 2018 10:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=kjuR2yLHoSPDibknt87zrlf2eBxKskQalGJInyHPLKc=; b=fEeKo9oQiw/r2Vfazkrr6rJ0O3eJXCAgHHO7DOUWXJLbRaMa7z4C+zQNYGzo6UPFOU sOBcfFZG0sEohsQJBMXTdVh5UsTvHh74r49n7ug1TZJ2v0zOtf7VNhQzw0QzLVBnJSOj xv5AUmYaqXuOLAwu6GDZCZZbw/mF1TdRi+SMBALWr/92bTeghzuMjScDofDOMtypsS0P nvV6c459ICq8rZoI76bcQgsPoX8jvzNUxzXmvd1CbYEiSyuH5JQgh8ISIPeaChBYOQ2W FUcWGQjyzjuIbGd9HEGT5Up6IFJ98l+VcaP/d1MbhRElcg88kUGk8EkmAXv0R+EAj9Y2 Bl3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kjuR2yLHoSPDibknt87zrlf2eBxKskQalGJInyHPLKc=; b=RJ0HNYV/wpIrGXVlfXddaX766MijJ5di3vtuGem27JmcnKNUQmpFZYidYoBxqWqa62 bSaD7RgrBZ0alh8l0E8A2bpdWe1mMphdWjgTRg0202G3qZcK2D/KlFA5hyqSBEqWin1f F2W4GZNXOJ+Aq+l1cJubx3wnYmBnOmUdxgRP0ppK2r3+TAI+97zh8jbLwCutGQcUldeY abuTN9DOvV/Zog4Al8KEXPo+oduOAm7HIGnBhpYu7Sw5HBTMB6QbL0OVos1I1Bh5MTP7 XzUPMv9zZ69l6pvGSnn1kFSJyNfpFIvRkSIE1CUmEM3ywHGLyiQFNChjz/oTIFMWikIv Da+w== X-Gm-Message-State: ALQs6tDfjJpaIfMpjE31bVTa7dlqupxB0jQIoybbcc0pxIBAsoSFOhXP oRquNEtMoilXJJ+2NbtKciCCjwmksK/mo62riE4= X-Received: by 10.31.120.74 with SMTP id t71mr17001428vkc.172.1523036521858; Fri, 06 Apr 2018 10:42:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.222.23 with HTTP; Fri, 6 Apr 2018 10:42:01 -0700 (PDT) In-Reply-To: <20180405073907.30615-1-anders.roxell@linaro.org> References: <20180308134845.32409-1-anders.roxell@linaro.org> <20180405073907.30615-1-anders.roxell@linaro.org> From: Pintu Kumar Date: Fri, 6 Apr 2018 23:12:01 +0530 Message-ID: Subject: Re: [PATCH v2] selftests/android/ion: fix heap_type may be uninitialized To: Anders Roxell Cc: Shuah Khan , linux-kselftest@vger.kernel.org, open list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 5, 2018 at 1:09 PM, Anders Roxell wr= ote: > 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: =E2=80=98heap_type=E2=80=99 may be used un= initialized 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 > --- > 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 ] [-i ] [-s ]= \n", > + printf("Usage: %s [-h ] -i -s \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 =3D 0; > + heap_type =3D -1; > flags =3D 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 =3D getopt(argc, argv, "hi:s:")) !=3D -1) { > @@ -68,7 +72,7 @@ int main(int argc, char *argv[]) > heap_type =3D 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 <=3D 0) { > - printf("heap_size cannot be 0\n"); > + if (heap_size <=3D 0 || heap_type < 0) { > print_usage(argc, argv); > exit(1); > } > -- > 2.11.0 >