nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0137-Remove-nested-functions-from-USB-iterators.patch

f96e0b
From c01c5f4a571b66bd330f4312f643f283bc8161c8 Mon Sep 17 00:00:00 2001
f96e0b
From: Colin Watson <cjwatson@ubuntu.com>
f96e0b
Date: Mon, 21 Jan 2013 21:02:24 +0000
f96e0b
Subject: [PATCH 137/482] Remove nested functions from USB iterators.
f96e0b
f96e0b
* include/grub/usb.h (grub_usb_iterate_hook_t): New type.
f96e0b
(grub_usb_controller_iterate_hook_t): Likewise.
f96e0b
(grub_usb_iterate): Add hook_data argument.
f96e0b
(grub_usb_controller_iterate): Likewise.
f96e0b
(struct grub_usb_controller_dev.iterate): Likewise.
f96e0b
f96e0b
Update all implementations and callers.
f96e0b
---
f96e0b
 ChangeLog                    |  12 +++++
f96e0b
 grub-core/bus/usb/ehci.c     |   4 +-
f96e0b
 grub-core/bus/usb/emu/usb.c  |   4 +-
f96e0b
 grub-core/bus/usb/ohci.c     |   4 +-
f96e0b
 grub-core/bus/usb/uhci.c     |   4 +-
f96e0b
 grub-core/bus/usb/usb.c      | 120 ++++++++++++++++++++++++-------------------
f96e0b
 grub-core/bus/usb/usbhub.c   |   4 +-
f96e0b
 grub-core/commands/usbtest.c |   4 +-
f96e0b
 include/grub/usb.h           |  11 ++--
f96e0b
 9 files changed, 100 insertions(+), 67 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index cf7a777..08c2c9f 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,15 @@
f96e0b
+2013-01-21  Colin Watson  <cjwatson@ubuntu.com>
f96e0b
+
f96e0b
+	Remove nested functions from USB iterators.
f96e0b
+
f96e0b
+	* include/grub/usb.h (grub_usb_iterate_hook_t): New type.
f96e0b
+	(grub_usb_controller_iterate_hook_t): Likewise.
f96e0b
+	(grub_usb_iterate): Add hook_data argument.
f96e0b
+	(grub_usb_controller_iterate): Likewise.
f96e0b
+	(struct grub_usb_controller_dev.iterate): Likewise.
f96e0b
+
f96e0b
+	Update all implementations and callers.
f96e0b
+
f96e0b
 2013-01-21  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/normal/term.c (print_ucs4_terminal): Don't output right
f96e0b
diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c
f96e0b
index b9872b6..9215866 100644
f96e0b
--- a/grub-core/bus/usb/ehci.c
f96e0b
+++ b/grub-core/bus/usb/ehci.c
f96e0b
@@ -870,7 +870,7 @@ fail:
f96e0b
 }
f96e0b
 
f96e0b
 static int
f96e0b
-grub_ehci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
+grub_ehci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
f96e0b
 {
f96e0b
   struct grub_ehci *e;
f96e0b
   struct grub_usb_controller dev;
f96e0b
@@ -878,7 +878,7 @@ grub_ehci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
   for (e = ehci; e; e = e->next)
f96e0b
     {
f96e0b
       dev.data = e;
f96e0b
-      if (hook (&dev))
f96e0b
+      if (hook (&dev, hook_data))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
 
f96e0b
diff --git a/grub-core/bus/usb/emu/usb.c b/grub-core/bus/usb/emu/usb.c
f96e0b
index 38c5f01..3ad2fc3 100644
f96e0b
--- a/grub-core/bus/usb/emu/usb.c
f96e0b
+++ b/grub-core/bus/usb/emu/usb.c
f96e0b
@@ -88,7 +88,7 @@ grub_usb_poll_devices (void)
f96e0b
 
f96e0b
 
f96e0b
 int
f96e0b
-grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
f96e0b
+grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
f96e0b
 {
f96e0b
   int i;
f96e0b
 
f96e0b
@@ -96,7 +96,7 @@ grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
f96e0b
     {
f96e0b
       if (grub_usb_devs[i])
f96e0b
 	{
f96e0b
-	  if (hook (grub_usb_devs[i]))
f96e0b
+	  if (hook (grub_usb_devs[i], hook_data))
f96e0b
 	      return 1;
f96e0b
 	}
f96e0b
     }
f96e0b
diff --git a/grub-core/bus/usb/ohci.c b/grub-core/bus/usb/ohci.c
f96e0b
index b10a9a3..835bb15 100644
f96e0b
--- a/grub-core/bus/usb/ohci.c
f96e0b
+++ b/grub-core/bus/usb/ohci.c
f96e0b
@@ -483,7 +483,7 @@ grub_ohci_inithw (void)
f96e0b
 
f96e0b
 
f96e0b
 static int
f96e0b
-grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
+grub_ohci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
f96e0b
 {
f96e0b
   struct grub_ohci *o;
f96e0b
   struct grub_usb_controller dev;
f96e0b
@@ -491,7 +491,7 @@ grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
   for (o = ohci; o; o = o->next)
f96e0b
     {
f96e0b
       dev.data = o;
f96e0b
-      if (hook (&dev))
f96e0b
+      if (hook (&dev, hook_data))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
 
f96e0b
diff --git a/grub-core/bus/usb/uhci.c b/grub-core/bus/usb/uhci.c
f96e0b
index e405b33..74de392 100644
f96e0b
--- a/grub-core/bus/usb/uhci.c
f96e0b
+++ b/grub-core/bus/usb/uhci.c
f96e0b
@@ -672,7 +672,7 @@ grub_uhci_cancel_transfer (grub_usb_controller_t dev,
f96e0b
 }
f96e0b
 
f96e0b
 static int
f96e0b
-grub_uhci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
+grub_uhci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
f96e0b
 {
f96e0b
   struct grub_uhci *u;
f96e0b
   struct grub_usb_controller dev;
f96e0b
@@ -680,7 +680,7 @@ grub_uhci_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
   for (u = uhci; u; u = u->next)
f96e0b
     {
f96e0b
       dev.data = u;
f96e0b
-      if (hook (&dev))
f96e0b
+      if (hook (&dev, hook_data))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
 
f96e0b
diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c
f96e0b
index fb04e65..6fbf134 100644
f96e0b
--- a/grub-core/bus/usb/usb.c
f96e0b
+++ b/grub-core/bus/usb/usb.c
f96e0b
@@ -29,27 +29,28 @@ GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
 static grub_usb_controller_dev_t grub_usb_list;
f96e0b
 static struct grub_usb_attach_desc *attach_hooks;
f96e0b
 
f96e0b
-void
f96e0b
-grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
f96e0b
+/* Iterate over all controllers found by the driver.  */
f96e0b
+static int
f96e0b
+grub_usb_controller_dev_register_iter (grub_usb_controller_t dev, void *data)
f96e0b
 {
f96e0b
-  auto int iterate_hook (grub_usb_controller_t dev);
f96e0b
+  grub_usb_controller_dev_t usb = data;
f96e0b
 
f96e0b
-  /* Iterate over all controllers found by the driver.  */
f96e0b
-  int iterate_hook (grub_usb_controller_t dev)
f96e0b
-    {
f96e0b
-      dev->dev = usb;
f96e0b
+  dev->dev = usb;
f96e0b
 
f96e0b
-      /* Enable the ports of the USB Root Hub.  */
f96e0b
-      grub_usb_root_hub (dev);
f96e0b
+  /* Enable the ports of the USB Root Hub.  */
f96e0b
+  grub_usb_root_hub (dev);
f96e0b
 
f96e0b
-      return 0;
f96e0b
-    }
f96e0b
+  return 0;
f96e0b
+}
f96e0b
 
f96e0b
+void
f96e0b
+grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
f96e0b
+{
f96e0b
   usb->next = grub_usb_list;
f96e0b
   grub_usb_list = usb;
f96e0b
 
f96e0b
   if (usb->iterate)
f96e0b
-    usb->iterate (iterate_hook);
f96e0b
+    usb->iterate (grub_usb_controller_dev_register_iter, usb);
f96e0b
 }
f96e0b
 
f96e0b
 void
f96e0b
@@ -66,27 +67,41 @@ grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb)
f96e0b
 }
f96e0b
 
f96e0b
 #if 0
f96e0b
-int
f96e0b
-grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev))
f96e0b
+/* Context for grub_usb_controller_iterate.  */
f96e0b
+struct grub_usb_controller_iterate_ctx
f96e0b
 {
f96e0b
+  grub_usb_controller_iterate_hook_t hook;
f96e0b
+  void *hook_data;
f96e0b
   grub_usb_controller_dev_t p;
f96e0b
+};
f96e0b
 
f96e0b
-  auto int iterate_hook (grub_usb_controller_t dev);
f96e0b
+/* Helper for grub_usb_controller_iterate.  */
f96e0b
+static int
f96e0b
+grub_usb_controller_iterate_iter (grub_usb_controller_t dev, void *data)
f96e0b
+{
f96e0b
+  struct grub_usb_controller_iterate_ctx *ctx = data;
f96e0b
 
f96e0b
-  int iterate_hook (grub_usb_controller_t dev)
f96e0b
-    {
f96e0b
-      dev->dev = p;
f96e0b
-      if (hook (dev))
f96e0b
-	return 1;
f96e0b
-      return 0;
f96e0b
-    }
f96e0b
+  dev->dev = ctx->p;
f96e0b
+  if (ctx->hook (dev, ctx->hook_data))
f96e0b
+    return 1;
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+int
f96e0b
+grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
f96e0b
+			     void *hook_data)
f96e0b
+{
f96e0b
+  struct grub_usb_controller_iterate_ctx ctx = {
f96e0b
+    .hook = hook,
f96e0b
+    .hook_data = hook_data
f96e0b
+  };
f96e0b
 
f96e0b
   /* Iterate over all controller drivers.  */
f96e0b
-  for (p = grub_usb_list; p; p = p->next)
f96e0b
+  for (ctx.p = grub_usb_list; ctx.p; ctx.p = ctx.p->next)
f96e0b
     {
f96e0b
       /* Iterate over the busses of the controllers.  XXX: Actually, a
f96e0b
 	 hub driver should do this.  */
f96e0b
-      if (p->iterate (iterate_hook))
f96e0b
+      if (ctx.p->iterate (grub_usb_controller_iterate_iter, &ctx))
f96e0b
 	return 1;
f96e0b
     }
f96e0b
 
f96e0b
@@ -295,46 +310,47 @@ void grub_usb_device_attach (grub_usb_device_t dev)
f96e0b
     }
f96e0b
 }
f96e0b
 
f96e0b
-void
f96e0b
-grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
f96e0b
+/* Helper for grub_usb_register_attach_hook_class.  */
f96e0b
+static int
f96e0b
+grub_usb_register_attach_hook_class_iter (grub_usb_device_t usbdev, void *data)
f96e0b
 {
f96e0b
-  auto int usb_iterate (grub_usb_device_t dev);
f96e0b
-
f96e0b
-  int usb_iterate (grub_usb_device_t usbdev)
f96e0b
-    {
f96e0b
-      struct grub_usb_desc_device *descdev = &usbdev->descdev;
f96e0b
-      int i;
f96e0b
-
f96e0b
-      if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
f96e0b
-	  || descdev->configcnt == 0)
f96e0b
-	return 0;
f96e0b
+  struct grub_usb_attach_desc *desc = data;
f96e0b
+  struct grub_usb_desc_device *descdev = &usbdev->descdev;
f96e0b
+  int i;
f96e0b
 
f96e0b
-      /* XXX: Just check configuration 0 for now.  */
f96e0b
-      for (i = 0; i < usbdev->config[0].descconf->numif; i++)
f96e0b
-	{
f96e0b
-	  struct grub_usb_desc_if *interf;
f96e0b
+  if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
f96e0b
+      || descdev->configcnt == 0)
f96e0b
+    return 0;
f96e0b
 
f96e0b
-	  interf = usbdev->config[0].interf[i].descif;
f96e0b
+  /* XXX: Just check configuration 0 for now.  */
f96e0b
+  for (i = 0; i < usbdev->config[0].descconf->numif; i++)
f96e0b
+    {
f96e0b
+      struct grub_usb_desc_if *interf;
f96e0b
 
f96e0b
-	  grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
f96e0b
-	                i, interf->class, interf->subclass, interf->protocol);
f96e0b
+      interf = usbdev->config[0].interf[i].descif;
f96e0b
 
f96e0b
-	  if (usbdev->config[0].interf[i].attached)
f96e0b
-	    continue;
f96e0b
+      grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
f96e0b
+		    i, interf->class, interf->subclass, interf->protocol);
f96e0b
 
f96e0b
-	  if (interf->class != desc->class)
f96e0b
-	    continue;
f96e0b
-	  if (desc->hook (usbdev, 0, i))
f96e0b
-	    usbdev->config[0].interf[i].attached = 1;
f96e0b
-	}
f96e0b
+      if (usbdev->config[0].interf[i].attached)
f96e0b
+	continue;
f96e0b
 
f96e0b
-      return 0;
f96e0b
+      if (interf->class != desc->class)
f96e0b
+	continue;
f96e0b
+      if (desc->hook (usbdev, 0, i))
f96e0b
+	usbdev->config[0].interf[i].attached = 1;
f96e0b
     }
f96e0b
 
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+void
f96e0b
+grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
f96e0b
+{
f96e0b
   desc->next = attach_hooks;
f96e0b
   attach_hooks = desc;
f96e0b
 
f96e0b
-  grub_usb_iterate (usb_iterate);
f96e0b
+  grub_usb_iterate (grub_usb_register_attach_hook_class_iter, desc);
f96e0b
 }
f96e0b
 
f96e0b
 void
f96e0b
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
f96e0b
index 5fc5eba..3927f51 100644
f96e0b
--- a/grub-core/bus/usb/usbhub.c
f96e0b
+++ b/grub-core/bus/usb/usbhub.c
f96e0b
@@ -556,7 +556,7 @@ grub_usb_poll_devices (void)
f96e0b
 }
f96e0b
 
f96e0b
 int
f96e0b
-grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
f96e0b
+grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
f96e0b
 {
f96e0b
   int i;
f96e0b
 
f96e0b
@@ -564,7 +564,7 @@ grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
f96e0b
     {
f96e0b
       if (grub_usb_devs[i])
f96e0b
 	{
f96e0b
-	  if (hook (grub_usb_devs[i]))
f96e0b
+	  if (hook (grub_usb_devs[i], hook_data))
f96e0b
 	      return 1;
f96e0b
 	}
f96e0b
     }
f96e0b
diff --git a/grub-core/commands/usbtest.c b/grub-core/commands/usbtest.c
f96e0b
index 7247590..af35b8c 100644
f96e0b
--- a/grub-core/commands/usbtest.c
f96e0b
+++ b/grub-core/commands/usbtest.c
f96e0b
@@ -129,7 +129,7 @@ usb_print_str (const char *description, grub_usb_device_t dev, int idx)
f96e0b
 }
f96e0b
 
f96e0b
 static int
f96e0b
-usb_iterate (grub_usb_device_t dev)
f96e0b
+usb_iterate (grub_usb_device_t dev, void *data __attribute__ ((unused)))
f96e0b
 {
f96e0b
   struct grub_usb_desc_device *descdev;
f96e0b
   int i;
f96e0b
@@ -199,7 +199,7 @@ grub_cmd_usbtest (grub_command_t cmd __attribute__ ((unused)),
f96e0b
   grub_usb_poll_devices ();
f96e0b
 
f96e0b
   grub_printf ("USB devices:\n\n");
f96e0b
-  grub_usb_iterate (usb_iterate);
f96e0b
+  grub_usb_iterate (usb_iterate, NULL);
f96e0b
 
f96e0b
   return 0;
f96e0b
 }
f96e0b
diff --git a/include/grub/usb.h b/include/grub/usb.h
f96e0b
index 08d57b2..cefa8b6 100644
f96e0b
--- a/include/grub/usb.h
f96e0b
+++ b/include/grub/usb.h
f96e0b
@@ -50,8 +50,12 @@ typedef enum
f96e0b
     GRUB_USB_SPEED_HIGH
f96e0b
   } grub_usb_speed_t;
f96e0b
 
f96e0b
+typedef int (*grub_usb_iterate_hook_t) (grub_usb_device_t dev, void *data);
f96e0b
+typedef int (*grub_usb_controller_iterate_hook_t) (grub_usb_controller_t dev,
f96e0b
+						   void *data);
f96e0b
+
f96e0b
 /* Call HOOK with each device, until HOOK returns non-zero.  */
f96e0b
-int grub_usb_iterate (int (*hook) (grub_usb_device_t dev));
f96e0b
+int grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data);
f96e0b
 
f96e0b
 grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
f96e0b
 
f96e0b
@@ -72,7 +76,8 @@ void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
f96e0b
 
f96e0b
 void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
f96e0b
 
f96e0b
-int grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev));
f96e0b
+int grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
f96e0b
+				 void *hook_data);
f96e0b
 
f96e0b
 
f96e0b
 grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
f96e0b
@@ -98,7 +103,7 @@ struct grub_usb_controller_dev
f96e0b
   /* The device name.  */
f96e0b
   const char *name;
f96e0b
 
f96e0b
-  int (*iterate) (int (*hook) (grub_usb_controller_t dev));
f96e0b
+  int (*iterate) (grub_usb_controller_iterate_hook_t hook, void *hook_data);
f96e0b
 
f96e0b
   grub_usb_err_t (*setup_transfer) (grub_usb_controller_t dev,
f96e0b
 				    grub_usb_transfer_t transfer);
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b