All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ofdisk: allocate space for vscsi table
@ 2015-11-09  1:33 Paulo Flabiano Smorigo
  2015-11-09 10:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 7+ messages in thread
From: Paulo Flabiano Smorigo @ 2015-11-09  1:33 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Paulo Flabiano Smorigo

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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-10 23:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-09  1:33 [PATCH] ofdisk: allocate space for vscsi table Paulo Flabiano Smorigo
2015-11-09 10:46 ` 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

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.