From patchwork Sat Mar 12 20:36:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rutuja shah X-Patchwork-Id: 8572221 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 334D99F758 for ; Sat, 12 Mar 2016 20:37:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 798C420375 for ; Sat, 12 Mar 2016 20:37:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63D542034C for ; Sat, 12 Mar 2016 20:37:06 +0000 (UTC) Received: from localhost ([::1]:33335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeqHZ-0002vV-II for patchwork-qemu-devel@patchwork.kernel.org; Sat, 12 Mar 2016 15:37:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeqHQ-0002v7-NE for qemu-devel@nongnu.org; Sat, 12 Mar 2016 15:36:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aeqHN-0003sN-GO for qemu-devel@nongnu.org; Sat, 12 Mar 2016 15:36:56 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeqHN-0003sJ-9C; Sat, 12 Mar 2016 15:36:53 -0500 Received: by mail-pf0-x244.google.com with SMTP id u190so6471134pfb.2; Sat, 12 Mar 2016 12:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=kzjrXPAlNiCmy3czXo/JlAeW24xvfiBngprkvG0ATug=; b=l+uIMFQCaIpoxUnISyRQookxVdR/j7dehDDrFsd/NovikcJQf0CNdaqO7MFXmp897Y O/7RosCBqNu0CdiSqSQJneXDYoPibkne+ii2DDoC7J5jCcqOVEWue+V8IaCzPC8U87rc VbczEF4d9/BxuHoE8DYL2aKOocTU9kb43t2nlYbHPIA/aTAKUR85Q9/Q7sPd0fNWUKqC KvjUwRkfxE/eVG92y3wubQEstBo6rwDgyP13fAoUTZU3RYTSTEbR4WwG4nwMIBXLE3ra 3M52EwxHaW8ADlqlXYdJs8ZjdXhL99Hk1y2ORY4E59yCk8/Ak5NKlxLIhvnnnc2smV8g tNMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kzjrXPAlNiCmy3czXo/JlAeW24xvfiBngprkvG0ATug=; b=AjontioVb2/ASnPXKdCQDRjH8sKffwlpIvXAtUHUeUagYqn1b+kU3/AMrxnG3IROga wQn7hJxdJ7IcWddeUTP+5j1lI2UW61Xf9kJyAPSjVGEMeUuY9hEgcbKsCQ89Yv8WUQdK nYbcdaxoSxyvaszuro1+UOOOJpnIXZ++moDEAEvkwzo2oAwlM/bqRaFI1KNt2cIFPEmL 1ChOXt782pU+31vy4LrJBtCspx/yXpTTJmXWxcMaNyFvGycbXp+tm0tcKJ8K8Y7/bYo1 RRlhogGiEDINqAnM6UkNs3IH1hEhmLKnVeo/E6KUeSIzDVYRARzgC7WuMTG4DRuNN+ev e9bQ== X-Gm-Message-State: AD7BkJI5RFMsqfeXQo00cQrk8Iro4uT3n5dZ1xVVNvIq5BVJ/Azt64vTXDj+D3cOf2ASBA== X-Received: by 10.98.71.147 with SMTP id p19mr17796552pfi.135.1457815012317; Sat, 12 Mar 2016 12:36:52 -0800 (PST) Received: from localhost.localdomain ([117.223.140.116]) by smtp.gmail.com with ESMTPSA id l81sm21622456pfb.73.2016.03.12.12.36.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 12 Mar 2016 12:36:51 -0800 (PST) From: rutu.shah.26@gmail.com To: qemu-devel@nongnu.org Date: Sun, 13 Mar 2016 02:06:34 +0530 Message-Id: <1457814994-10698-1-git-send-email-rutu.shah.26@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 Cc: Rutuja Shah , mark.cave-ayland@ilande.co.uk, agraf@suse.de, chouteau@adacore.com, blauwirbel@gmail.com, qemu-ppc@nongnu.org, stefanha@redhat.com, scottwood@freescale.com Subject: [Qemu-devel] [PATCH] Added NULL check for qemu_find_file() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rutuja Shah This patch adds NULL check for return value from qemu_find_file(), where it is missing. It avoids unnecessary function calls with NULL parameter which in turn return -1. Especially, incase of load_uimage(), two functions are called which return -1 on passing NULL filename. --- hw/ppc/e500.c | 17 +++++++++++++---- hw/sparc/leon3.c | 6 +++++- 2 files changed, 18 insertions(+), 5 deletions(-) 1.9.1 Signed-off-by: Rutuja Shah Regards Rutuja Shah diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 09154fa..006adf1 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -1016,15 +1016,24 @@ void ppce500_init(MachineState *machine, PPCE500Params *params) } filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL, - 1, PPC_ELF_MACHINE, 0, 0); + if (filename) { + bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL, + 1, PPC_ELF_MACHINE, 0, 0); + } else { + bios_size = -1; + } + if (bios_size < 0) { /* * Hrm. No ELF image? Try a uImage, maybe someone is giving us an * ePAPR compliant kernel */ - kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL, - NULL, NULL); + if (filename) { + kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL, + NULL, NULL); + } else { + kernel_size = -1; + } if (kernel_size < 0) { fprintf(stderr, "qemu: could not load firmware '%s'\n", filename); exit(1); diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c index c579f5b..b4e9334 100644 --- a/hw/sparc/leon3.c +++ b/hw/sparc/leon3.c @@ -168,7 +168,11 @@ static void leon3_generic_hw_init(MachineState *machine) } filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); - bios_size = get_image_size(filename); + if (filename) { + bios_size = get_image_size(filename); + } else { + bios_size = -1; + } if (bios_size > prom_size) { fprintf(stderr, "qemu: could not load prom '%s': file too big\n",