From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Zvh2i-0003EM-IG for mharc-grub-devel@gnu.org; Mon, 09 Nov 2015 02:39:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvbKl-0002ia-54 for grub-devel@gnu.org; Sun, 08 Nov 2015 20:33:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvbKh-0003wN-Ve for grub-devel@gnu.org; Sun, 08 Nov 2015 20:33:23 -0500 Received: from e24smtp03.br.ibm.com ([32.104.18.24]:59053) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvbKh-0003vr-H0 for grub-devel@gnu.org; Sun, 08 Nov 2015 20:33:19 -0500 Received: from /spool/local by e24smtp03.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 8 Nov 2015 23:33:17 -0200 Received: from d24dlp01.br.ibm.com (9.18.248.204) by e24smtp03.br.ibm.com (10.172.0.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 8 Nov 2015 23:33:15 -0200 X-Helo: d24dlp01.br.ibm.com X-MailFrom: pfsmorigo@linux.vnet.ibm.com X-RcptTo: grub-devel@gnu.org Received: from d24relay02.br.ibm.com (d24relay02.br.ibm.com [9.13.184.26]) by d24dlp01.br.ibm.com (Postfix) with ESMTP id 693CB3520078 for ; Sun, 8 Nov 2015 20:32:03 -0500 (EST) Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.8.31.93]) by d24relay02.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tA91V7fp28442950 for ; Sun, 8 Nov 2015 23:31:07 -0200 Received: from d24av02.br.ibm.com (localhost [127.0.0.1]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tA91XDZD010108 for ; Sun, 8 Nov 2015 23:33:13 -0200 Received: from london.ltc.br.ibm.com ([9.8.9.89]) by d24av02.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tA91XCHC010100; Sun, 8 Nov 2015 23:33:13 -0200 From: Paulo Flabiano Smorigo To: The development of GNU GRUB Subject: [PATCH] ofdisk: allocate space for vscsi table Date: Sun, 8 Nov 2015 23:33:09 -0200 Message-Id: <1447032789-17670-1-git-send-email-pfsmorigo@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15110901-0025-0000-0000-00000534FC6C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.104.18.24 X-Mailman-Approved-At: Mon, 09 Nov 2015 02:39:07 -0500 Cc: Paulo Flabiano Smorigo X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Nov 2015 01:33:24 -0000 The table must be allocated in order to avoid memory leak. Also added some vscsi paths for illustration purpose. --- grub-core/disk/ieee1275/ofdisk.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c index afec9ba..4ea6089 100644 --- a/grub-core/disk/ieee1275/ofdisk.c +++ b/grub-core/disk/ieee1275/ofdisk.c @@ -211,6 +211,11 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) { if (grub_strcmp (alias->type, "vscsi") == 0) { + /* Example of vscsi paths: + * /vdevice/v-scsi@30000002/disk@8100000000000000 + * /vdevice/v-scsi@30000002/disk@8200000000000000 + * /vdevice/v-scsi@30000002/disk@8400000000000000 */ + static grub_ieee1275_ihandle_t ihandle; struct set_color_args { @@ -222,27 +227,41 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) grub_ieee1275_cell_t table; } args; - char *buf, *bufptr; + char *buf, *bufptr, *table; unsigned i; + grub_uint32_t table_size; if (grub_ieee1275_open (alias->path, &ihandle)) return; - + + /* 64 entries should be enough */ + table_size = sizeof (grub_uint64_t) * 64; + table = grub_malloc (table_size); + + if (!table) + return; + INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3); args.method = (grub_ieee1275_cell_t) "vscsi-report-luns"; args.ihandle = ihandle; - args.table = 0; + args.table = (grub_ieee1275_cell_t) table; args.nentries = 0; if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result) { grub_ieee1275_close (ihandle); - return; + grub_free (table); + return; } buf = grub_malloc (grub_strlen (alias->path) + 32); if (!buf) - return; + { + grub_ieee1275_close (ihandle); + grub_free (table); + return; + } + bufptr = grub_stpcpy (buf, alias->path); for (i = 0; i < args.nentries; i++) @@ -257,6 +276,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) } } grub_ieee1275_close (ihandle); + grub_free (table); grub_free (buf); return; } -- 2.1.0