Received: by 10.213.65.68 with SMTP id h4csp289623imn; Fri, 16 Mar 2018 03:15:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELuHTZZhHua0+BJLMi3htiBsbu9AtB+q3x0XSdsyxDoQnHTQSrJEWPwHz39C/gPNJSN5+4Nl X-Received: by 10.98.97.1 with SMTP id v1mr1111332pfb.119.1521195336483; Fri, 16 Mar 2018 03:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521195336; cv=none; d=google.com; s=arc-20160816; b=pQYb0A40C3TaEfc/fXHhQISZ+ppyZbZYTE7SV3IfD32US+RB8U9E+W8OcT9VR9tXke oMUkbzew3YIpdTx8GDzCPSMRyP0pM4jZIPQfF80tl5TM6XIr+tae+PyoIiUD6StQgAdV iFR/h31LLYNxgkHwTXeejUsnsjNQrU8cgi8XgnIjssG7FCqOUassMToT83h0eiCWbIM3 6ZFDmWJl5bUqercKyZVEyforaHOJBtZSiyn34tEGIO8JigmAtPuJQXSxotIDI/eo8Znl c2S78So88RfVu7hRbgoEwZ2mH9adq9XiAqhO0yoDg6dzLXJVafEnnWLlxtAX7fQiGg5+ UwOg== 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=8bzo6SHmHOaE+dako4jlvQy+p2t5nOTn74JZrmm/90s=; b=OCFEEW94DmO721Bgzu+8bub6t3jDzsrnn2Th9FfnWCFWzFf/S6phy8NmLpklX5kpV8 rVmS445kV97ajunpGG7XU2XY4M+cfAfeeLPefKtHG9HrRAidTbLTGRc7p2QpG/+Y1Y7J N9mwfEIP2peDFLTVMBzvqqQth8tp80y76s9VrFATjc1X3nbhns3n0VtqURuHQZcrmamt 58tZI0E/DCbwhOTY8d6nGb+JAuh70zAOJ7gPkNQBf5A2QmHciDlGbmGVnGBD/wzRN+bN B6oaqdUhpkqNBeqZu6Spwzk4y1qMmkIPpDDTdkZrQP6AGk4Tl2F46h67lP7Q/h9Ostca SA1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ungQnyHs; 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 u6-v6si5845653pls.424.2018.03.16.03.15.22; Fri, 16 Mar 2018 03:15:36 -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=ungQnyHs; 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 S1753206AbeCPKOM (ORCPT + 99 others); Fri, 16 Mar 2018 06:14:12 -0400 Received: from mail-vk0-f68.google.com ([209.85.213.68]:33607 "EHLO mail-vk0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbeCPKOG (ORCPT ); Fri, 16 Mar 2018 06:14:06 -0400 Received: by mail-vk0-f68.google.com with SMTP id d140so325538vke.0; Fri, 16 Mar 2018 03:14:04 -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=8bzo6SHmHOaE+dako4jlvQy+p2t5nOTn74JZrmm/90s=; b=ungQnyHsDvzs3Oz2LU6+SCjLc4Lxaoowv9XWLqSKWydj60vq0GTc6QLsumaUegH7nc VyvoNSQWxYRFxDtXBx/jAc4ZHtpqnD6qPzMTht+cZPxXt1RF80Wfxq8o5R2rGceu3gwa UmjAnZtCDEGy1MvKBTP3ZtS/39xIiq5Js3m39C3vb3Zv4aXTRWoSgkRjdJpKm4faJZvj Ic+4T4Kjugrb7YXs1FTqnAuzdkuCCMiC2kQasTcNWQfLoPkDV6LthrEqsEcH/wUXZGMZ QdJWgY9jXCfLGZP4FR0dFAo6ChE4aYPa5TTRmLBhRr4meC8BU0GJf/8DKnI+W1H011UJ vqsg== 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=8bzo6SHmHOaE+dako4jlvQy+p2t5nOTn74JZrmm/90s=; b=ODE5tSeYdV6ZziQMddxJvP6Tm+Kd93r73r64y71v1LnxEoLPN7vIDxx7Dp13HPRYng 6gzyNgl/B3V/r0TPizGNfts91m23uNNO3a+9d+hCuMN4fyXirgAvjW9DvWMnqHFMi/lK YBBcpyDOALCOLUckM7hk2z38phrKPtoHvBsLhiFdUi6BuMXndek+AI57vMUaqDo9oAuW 4JJ0VrgXowwn0KiZcp4v748ISTfdOg8OffnPQn6B21tcpkqtrwajBP7NzSVTDwnYNW29 K0OYkM9Zl60/l6eBalrO+kdivoJ5YJwQ/Ok9+bvydcX+/NlP0mM8XlvllrlIx5poWPDq 6f9Q== X-Gm-Message-State: AElRT7EF2a/kpuUdA9MhiVITMXydUdEN+Pkf74fwrZTZhLQ4nlyZj7gb EBgdL07LPeuJOGAyxUlGGyZAJEdYQY3sg8WSBkM= X-Received: by 10.31.174.1 with SMTP id x1mr685511vke.25.1521195244125; Fri, 16 Mar 2018 03:14:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.196.138 with HTTP; Fri, 16 Mar 2018 03:14:03 -0700 (PDT) In-Reply-To: <20180308134845.32409-1-anders.roxell@linaro.org> References: <20180308134845.32409-1-anders.roxell@linaro.org> From: Pintu Kumar Date: Fri, 16 Mar 2018 15:44:03 +0530 Message-ID: Subject: Re: [PATCH] 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, Mar 8, 2018 at 7:18 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: > OK thanks for your patch. > 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. > OK > Fixes: 47a18c42d992 ("android/ion: userspace test utility for ion buffer = sharing") > Signed-off-by: Anders Roxell > --- > .../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 ] [-i ] [-s ]= \n", > + printf("Usage: %s [-h ] -i -s \n", > argv[0]); > } > > +void heap_type_error_text(void) > +{ > + printf("heap_type must be specified\n"); > + printf(" need to specify -i \n"); > + printf(" supported heap types 0 or 1\n"); > +} > + I think this error function needs to be generic. See explanation below. > 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 =3D 0; > + heap_type =3D -1; > flags =3D 0; > > while ((opt =3D getopt(argc, argv, "hi:s:")) !=3D -1) { > @@ -68,7 +77,8 @@ int main(int argc, char *argv[]) > heap_type =3D 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 <=3D 0) { > printf("heap_size cannot be 0\n"); > + printf(" need to specify -s \n"); > print_usage(argc, argv); > exit(1); > } I think both heap_type and heap_size error message is almost same. How about creating a common error handler for both ? Also it may be possible to merge both the above. Or, another option is to make use of print_usage function itself, instead of one more function. > -- > 2.11.0 >