All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Paulo Flabiano Smorigo <pfsmorigo@linux.vnet.ibm.com>
Subject: [PATCH] ofdisk: allocate space for vscsi table
Date: Sun,  8 Nov 2015 23:33:09 -0200	[thread overview]
Message-ID: <1447032789-17670-1-git-send-email-pfsmorigo@linux.vnet.ibm.com> (raw)

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



             reply	other threads:[~2015-11-09  7:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  1:33 Paulo Flabiano Smorigo [this message]
2015-11-09 10:46 ` [PATCH] ofdisk: allocate space for vscsi table Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-09 11:59   ` Paulo Flabiano Smorigo
2015-11-09 12:03     ` Vladimir 'phcoder' Serbinenko
2015-11-09 16:33       ` Paulo Flabiano Smorigo
2015-11-09 16:49         ` Vladimir 'phcoder' Serbinenko
2015-11-10 23:31           ` Paulo Flabiano Smorigo

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=1447032789-17670-1-git-send-email-pfsmorigo@linux.vnet.ibm.com \
    --to=pfsmorigo@linux.vnet.ibm.com \
    --cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.