Skip to contentSkip to conversation

ieee1275: split up grub_machine_get_bootlocation

PATCH Superseded Eric Snowberg 2 participants 4 messages Mar 7, 2018 – Mar 8, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ieee1275: split up grub_machine_get_bootlocation

Split up some of the functionality in grub_machine_get_bootlocation into grub_ieee1275_get_boot_dev. This will allow for code reuse in a follow on patch.

---
 grub-core/kern/ieee1275/init.c   |   24 ++++--------------------
 grub-core/kern/ieee1275/openfw.c |   27 +++++++++++++++++++++++++++
 include/grub/ieee1275/ieee1275.h |    1 +
 3 files changed, 32 insertions(+), 20 deletions(-)
grub-core/kern/ieee1275/init.c +4 -20
index 1259022..dff2184 100644
@@ -93,29 +93,13 @@ void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path,
 void
 grub_machine_get_bootlocation (char **device, char **path)
 {
-  char *bootpath;
-  grub_ssize_t bootpath_size;
+  char *bootpath = NULL;
   char *filename;
   char *type;
 
-  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
-					 &bootpath_size)
-      || bootpath_size <= 0)
-    {
-      /* Should never happen.  */
-      grub_printf ("/chosen/bootpath property missing!\n");
-      return;
-    }
-
-  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
-  if (! bootpath)
-    {
-      grub_print_error ();
-      return;
-    }
-  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
-                              (grub_size_t) bootpath_size + 1, 0);
-  bootpath[bootpath_size] = '\0';
+  grub_ieee1275_get_boot_dev (&bootpath);
+  if (bootpath == NULL)
+    return;
 
   /* Transform an OF device path to a GRUB path.  */
 
grub-core/kern/ieee1275/openfw.c +27 -0
index ddb7783..81c03cf 100644
@@ -561,3 +561,30 @@ grub_ieee1275_canonicalise_devname (const char *path)
   return NULL;
 }
 
+void
+grub_ieee1275_get_boot_dev (char **boot_dev)
+{
+  char *bootpath;
+  grub_ssize_t bootpath_size;
+
+  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
+					 &bootpath_size)
+      || bootpath_size <= 0)
+    {
+      /* Should never happen.  */
+      grub_printf ("/chosen/bootpath property missing!\n");
+      return;
+    }
+
+  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
+  if (! bootpath)
+    {
+      grub_print_error ();
+      return;
+    }
+  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
+                              (grub_size_t) bootpath_size + 1, 0);
+  bootpath[bootpath_size] = '\0';
+
+  *boot_dev = bootpath;
+}
include/grub/ieee1275/ieee1275.h +1 -0
index d0dc274..7c9bb48 100644
@@ -253,6 +253,7 @@ void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *al
 void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
 						struct grub_ieee1275_devalias *alias);
 
+void EXPORT_FUNC(grub_ieee1275_get_boot_dev) (char **boot_dev);
 #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
 
 #define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \
Signature · 1 line
1.7.1
#1 lore raw
Quoted 3 lines · Eric Snowberg

Split up some of the functionality in grub_machine_get_bootlocation into grub_ieee1275_get_boot_dev. This will allow for code reuse in a follow on patch.

I would like to see follow up patches in such cases like that one.

Quoted 12 lines
---
 grub-core/kern/ieee1275/init.c   |   24 ++++--------------------
 grub-core/kern/ieee1275/openfw.c |   27 +++++++++++++++++++++++++++
 include/grub/ieee1275/ieee1275.h |    1 +
 3 files changed, 32 insertions(+), 20 deletions(-)
grub-core/kern/ieee1275/init.c +0 -0
index 1259022..dff2184 100644

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 96

Quoted 6 lines
grub-core/kern/ieee1275/init.c +1 -2
@@ -93,29 +93,13 @@ void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path,
 void
 grub_machine_get_bootlocation (char **device, char **path)
 {
-  char *bootpath;
-  grub_ssize_t bootpath_size;
+  char *bootpath = NULL;

I do not think that you need initialize this if...

Quoted 13 lines
grub-core/kern/ieee1275/init.c +0 -10
   char *filename;
   char *type;
 
-  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
-					 &bootpath_size)
-      || bootpath_size <= 0)
-    {
-      /* Should never happen.  */
-      grub_printf ("/chosen/bootpath property missing!\n");
-      return;
-    }
-
-  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 101

Quoted 10 lines
grub-core/kern/ieee1275/init.c +2 -8
-  if (! bootpath)
-    {
-      grub_print_error ();
-      return;
-    }
-  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
-                              (grub_size_t) bootpath_size + 1, 0);
-  bootpath[bootpath_size] = '\0';
+  grub_ieee1275_get_boot_dev (&bootpath);
+  if (bootpath == NULL)

if (! bootpath)

Quoted 9 lines
grub-core/kern/ieee1275/init.c +1 -0
+    return;
 
   /* Transform an OF device path to a GRUB path.  */
 
grub-core/kern/ieee1275/openfw.c +0 -0
index ddb7783..81c03cf 100644

grub-core/kern/ieee1275/openfw.c grub_ieee1275_canonicalise_devname (const char *path) · line 565

Quoted 5 lines
grub-core/kern/ieee1275/openfw.c +2 -0
@@ -561,3 +561,30 @@ grub_ieee1275_canonicalise_devname (const char *path)
   return NULL;
 }
 
+void
+grub_ieee1275_get_boot_dev (char **boot_dev)

...you return char * here...

Daniel

#2 lore raw
Quoted 9 lines · Daniel Kiper
Quoted 3 lines · Eric Snowberg

Split up some of the functionality in grub_machine_get_bootlocation into grub_ieee1275_get_boot_dev. This will allow for code reuse in a follow on patch.

I would like to see follow up patches in such cases like that one.

Here is the follow up patch I’m preparing to send that will use it (look at the add_bootpath function):

https://github.com/esnowberg/grub2-sparc/commit/94e4e64c98bce8f43ced440928b3d1e83b36ed11.patch

This patch also uses the other additions I’ve sent recently.

Quoted 8 lines
Quoted 8 lines

---

grub-core/kern/ieee1275/init.c   |   24 ++++--------------------
grub-core/kern/ieee1275/openfw.c |   27 +++++++++++++++++++++++++++
include/grub/ieee1275/ieee1275.h |    1 +
3 files changed, 32 insertions(+), 20 deletions(-)
Quoted 13 lines

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 96

Quoted 11 lines
grub-core/kern/ieee1275/init.c +0 -0
index 1259022..dff2184 100644
@@ -93,29 +93,13 @@ void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path,

void
grub_machine_get_bootlocation (char **device, char **path) {

grub-core/kern/ieee1275/init.c +1 -2
-  char *bootpath;
-  grub_ssize_t bootpath_size;
+  char *bootpath = NULL;

I do not think that you need initialize this if…

I thought the compiler complained about that, but I’ll try to remove it.

Quoted 18 lines
Quoted 18 lines

char *filename;
char *type;

grub-core/kern/ieee1275/init.c +0 -14
-  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
-					 &bootpath_size)
-      || bootpath_size <= 0)
-    {
-      /* Should never happen.  */
-      grub_printf ("/chosen/bootpath property missing!\n");
-      return;
-    }
-
-  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
-  if (! bootpath)
-    {
-      grub_print_error ();
-      return;
Quoted 8 lines

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 101

Quoted 6 lines
grub-core/kern/ieee1275/init.c +2 -4
-    }
-  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
-                              (grub_size_t) bootpath_size + 1, 0);
-  bootpath[bootpath_size] = '\0';
+  grub_ieee1275_get_boot_dev (&bootpath);
+  if (bootpath == NULL)

if (! bootpath)

I’ll make this change.

Quoted 13 lines
Quoted 13 lines
grub-core/kern/ieee1275/init.c +1 -0
+    return;
 
  /* Transform an OF device path to a GRUB path.  */
grub-core/kern/ieee1275/openfw.c +0 -0
index ddb7783..81c03cf 100644
@@ -561,3 +561,30 @@ grub_ieee1275_canonicalise_devname (const char *path)
  return NULL;
 }
 
Quoted 4 lines

grub-core/kern/ieee1275/openfw.c grub_ieee1275_canonicalise_devname (const char *path) · line 565

Quoted 2 lines
grub-core/kern/ieee1275/openfw.c +2 -0
+void
+grub_ieee1275_get_boot_dev (char **boot_dev)

...you return char * here…

The returned value is in the boot_dev. Just to clarify, you want me to change the function prototype to return char * too?

#3 lore raw
Quoted 82 lines · Eric Snowberg
Quoted 9 lines · Daniel Kiper
Quoted 3 lines · Eric Snowberg

Split up some of the functionality in grub_machine_get_bootlocation into grub_ieee1275_get_boot_dev. This will allow for code reuse in a follow on patch.

I would like to see follow up patches in such cases like that one.

Here is the follow up patch I’m preparing to send that will use it (look at the add_bootpath function):

https://github.com/esnowberg/grub2-sparc/commit/94e4e64c98bce8f43ced440928b3d1e83b36ed11.patch

This patch also uses the other additions I’ve sent recently.

Quoted 8 lines
Quoted 8 lines

---

grub-core/kern/ieee1275/init.c   |   24 ++++--------------------
grub-core/kern/ieee1275/openfw.c |   27 +++++++++++++++++++++++++++
include/grub/ieee1275/ieee1275.h |    1 +
3 files changed, 32 insertions(+), 20 deletions(-)
Quoted 13 lines

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 96

Quoted 11 lines
grub-core/kern/ieee1275/init.c +0 -0
index 1259022..dff2184 100644
@@ -93,29 +93,13 @@ void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path,

void
grub_machine_get_bootlocation (char **device, char **path) {

grub-core/kern/ieee1275/init.c +1 -2
-  char *bootpath;
-  grub_ssize_t bootpath_size;
+  char *bootpath = NULL;

I do not think that you need initialize this if…

I thought the compiler complained about that, but I’ll try to remove it.

Quoted 18 lines
Quoted 18 lines

char *filename;
char *type;

grub-core/kern/ieee1275/init.c +0 -14
-  if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
-					 &bootpath_size)
-      || bootpath_size <= 0)
-    {
-      /* Should never happen.  */
-      grub_printf ("/chosen/bootpath property missing!\n");
-      return;
-    }
-
-  bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
-  if (! bootpath)
-    {
-      grub_print_error ();
-      return;
Quoted 8 lines

grub-core/kern/ieee1275/init.c void (*grub_ieee1275_net_config) (const char *dev, char **device, char **path, · line 101

Quoted 6 lines
grub-core/kern/ieee1275/init.c +2 -4
-    }
-  grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
-                              (grub_size_t) bootpath_size + 1, 0);
-  bootpath[bootpath_size] = '\0';
+  grub_ieee1275_get_boot_dev (&bootpath);
+  if (bootpath == NULL)

if (! bootpath)

I’ll make this change.

Quoted 13 lines
Quoted 13 lines
grub-core/kern/ieee1275/init.c +1 -0
+    return;
 
  /* Transform an OF device path to a GRUB path.  */
grub-core/kern/ieee1275/openfw.c +0 -0
index ddb7783..81c03cf 100644
@@ -561,3 +561,30 @@ grub_ieee1275_canonicalise_devname (const char *path)
  return NULL;
 }
 
Quoted 6 lines
Quoted 4 lines

grub-core/kern/ieee1275/openfw.c grub_ieee1275_canonicalise_devname (const char *path) · line 565

Quoted 2 lines
grub-core/kern/ieee1275/openfw.c +2 -0
+void
+grub_ieee1275_get_boot_dev (char **boot_dev)

...you return char * here…

The returned value is in the boot_dev. Just to clarify, you want me to change the function prototype to return char * too?

Sorry, I was not clear enough. I though about:

char *
grub_ieee1275_get_boot_dev (void)
{
...
}

Daniel