Skip to contentSkip to conversation

Remove nested functions from USB iterators

PATCH New Colin Watson 1 participant 1 message Jan 21, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove nested functions from USB iterators

A nice easy one.

UP: obj/amd64-efi/grub-core/ehci.mod (25272 < 25288) - change: 16
UP: obj/amd64-efi/grub-core/uhci.mod (10088 < 10104) - change: 16
DOWN: obj/amd64-efi/grub-core/usb.mod (15064 > 14992) - change: -72

  UP:   obj/i386-coreboot/grub-core/ehci.mod (15732 < 15736) - change: 4
  UP:   obj/i386-coreboot/grub-core/ohci.mod (10404 < 10408) - change: 4
  UP:   obj/i386-coreboot/grub-core/uhci.mod (6456 < 6460) - change: 4
  DOWN: obj/i386-coreboot/grub-core/usb.mod (9892 > 9840) - change: -52
  UP:   obj/i386-coreboot/grub-core/usbtest.mod (3604 < 3608) - change: 4
  UP:   obj/i386-efi/grub-core/ehci.mod (15844 < 15848) - change: 4
  DOWN: obj/i386-efi/grub-core/usb.mod (10020 > 9952) - change: -68
  UP:   obj/i386-efi/grub-core/usbtest.mod (3648 < 3652) - change: 4
  UP:   obj/i386-ieee1275/grub-core/ehci.mod (15732 < 15736) - change: 4
  UP:   obj/i386-ieee1275/grub-core/ohci.mod (10404 < 10408) - change: 4
  UP:   obj/i386-ieee1275/grub-core/uhci.mod (6456 < 6460) - change: 4
  DOWN: obj/i386-ieee1275/grub-core/usb.mod (9892 > 9840) - change: -52
  UP:   obj/i386-ieee1275/grub-core/usbtest.mod (3604 < 3608) - change: 4
  UP:   obj/i386-pc/grub-core/ehci.mod (15732 < 15736) - change: 4
  UP:   obj/i386-pc/grub-core/ohci.mod (10404 < 10408) - change: 4
  UP:   obj/i386-pc/grub-core/uhci.mod (6456 < 6460) - change: 4

DOWN: obj/i386-pc/grub-core/usb.mod (9892 > 9840) - change: -52
UP: obj/i386-pc/grub-core/usbtest.mod (3604 < 3608) - change: 4

=== modified file 'ChangeLog'

ChangeLog +12 -0
@@ -1,5 +1,17 @@
 2013-01-21  Colin Watson  <[email protected]>
 
+	Remove nested functions from USB iterators.
+
+	* include/grub/usb.h (grub_usb_iterate_hook_t): New type.
+	(grub_usb_controller_iterate_hook_t): Likewise.
+	(grub_usb_iterate): Add hook_data argument.
+	(grub_usb_controller_iterate): Likewise.
+	(struct grub_usb_controller_dev.iterate): Likewise.
+
+	Update all implementations and callers.
+
+2013-01-21  Colin Watson  <[email protected]>
+
 	* grub-core/partmap/msdos.c (embed_signatures): Add the signature of
 	an Acer registration utility with several sightings in the wild.
 	Reported by: Rickard Westman.  Fixes Ubuntu bug #987022.

=== modified file 'grub-core/bus/usb/ehci.c'

bus/usb/ehci.c +2 -2
@@ -870,7 +870,7 @@ fail:
 }
 
 static int
-grub_ehci_iterate (int (*hook) (grub_usb_controller_t dev))
+grub_ehci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
 {
   struct grub_ehci *e;
   struct grub_usb_controller dev;
@@ -878,7 +878,7 @@ grub_ehci_iterate (int (*hook) (grub_usb
   for (e = ehci; e; e = e->next)
     {
       dev.data = e;
-      if (hook (&dev))
+      if (hook (&dev, hook_data))
 	return 1;
     }
 

=== modified file 'grub-core/bus/usb/emu/usb.c'

bus/usb/emu/usb.c +2 -2
@@ -88,7 +88,7 @@ grub_usb_poll_devices (void)
 
 
 int
-grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
+grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
 {
   int i;
 
@@ -96,7 +96,7 @@ grub_usb_iterate (int (*hook) (grub_usb_
     {
       if (grub_usb_devs[i])
 	{
-	  if (hook (grub_usb_devs[i]))
+	  if (hook (grub_usb_devs[i], hook_data))
 	      return 1;
 	}
     }

=== modified file 'grub-core/bus/usb/ohci.c'

bus/usb/ohci.c +2 -2
@@ -483,7 +483,7 @@ grub_ohci_inithw (void)
 
 
 static int
-grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
+grub_ohci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
 {
   struct grub_ohci *o;
   struct grub_usb_controller dev;
@@ -491,7 +491,7 @@ grub_ohci_iterate (int (*hook) (grub_usb
   for (o = ohci; o; o = o->next)
     {
       dev.data = o;
-      if (hook (&dev))
+      if (hook (&dev, hook_data))
 	return 1;
     }
 

=== modified file 'grub-core/bus/usb/uhci.c'

bus/usb/uhci.c +2 -2
@@ -672,7 +672,7 @@ grub_uhci_cancel_transfer (grub_usb_cont
 }
 
 static int
-grub_uhci_iterate (int (*hook) (grub_usb_controller_t dev))
+grub_uhci_iterate (grub_usb_controller_iterate_hook_t hook, void *hook_data)
 {
   struct grub_uhci *u;
   struct grub_usb_controller dev;
@@ -680,7 +680,7 @@ grub_uhci_iterate (int (*hook) (grub_usb
   for (u = uhci; u; u = u->next)
     {
       dev.data = u;
-      if (hook (&dev))
+      if (hook (&dev, hook_data))
 	return 1;
     }
 

=== modified file 'grub-core/bus/usb/usb.c'

bus/usb/usb.c +68 -52

168 lines not on this page · raw message

=== modified file 'grub-core/bus/usb/usbhub.c'

bus/usb/usbhub.c +2 -2
@@ -556,7 +556,7 @@ grub_usb_poll_devices (void)
 }
 
 int
-grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
+grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data)
 {
   int i;
 
@@ -564,7 +564,7 @@ grub_usb_iterate (int (*hook) (grub_usb_
     {
       if (grub_usb_devs[i])
 	{
-	  if (hook (grub_usb_devs[i]))
+	  if (hook (grub_usb_devs[i], hook_data))
 	      return 1;
 	}
     }

=== modified file 'grub-core/commands/usbtest.c'

commands/usbtest.c +2 -2
@@ -129,7 +129,7 @@ usb_print_str (const char *description,
 }
 
 static int
-usb_iterate (grub_usb_device_t dev)
+usb_iterate (grub_usb_device_t dev, void *data __attribute__ ((unused)))
 {
   struct grub_usb_desc_device *descdev;
   int i;
@@ -199,7 +199,7 @@ grub_cmd_usbtest (grub_command_t cmd __a
   grub_usb_poll_devices ();
 
   grub_printf ("USB devices:\n\n");
-  grub_usb_iterate (usb_iterate);
+  grub_usb_iterate (usb_iterate, NULL);
 
   return 0;
 }

=== modified file 'include/grub/usb.h'

grub/usb.h +8 -3
@@ -50,8 +50,12 @@ typedef enum
     GRUB_USB_SPEED_HIGH
   } grub_usb_speed_t;
 
+typedef int (*grub_usb_iterate_hook_t) (grub_usb_device_t dev, void *data);
+typedef int (*grub_usb_controller_iterate_hook_t) (grub_usb_controller_t dev,
+						   void *data);
+
 /* Call HOOK with each device, until HOOK returns non-zero.  */
-int grub_usb_iterate (int (*hook) (grub_usb_device_t dev));
+int grub_usb_iterate (grub_usb_iterate_hook_t hook, void *hook_data);
 
 grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
 
@@ -72,7 +76,8 @@ void grub_usb_controller_dev_register (g
 
 void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
 
-int grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev));
+int grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
+				 void *hook_data);
 
 
 grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
@@ -98,7 +103,7 @@ struct grub_usb_controller_dev
   /* The device name.  */
   const char *name;
 
-  int (*iterate) (int (*hook) (grub_usb_controller_t dev));
+  int (*iterate) (grub_usb_controller_iterate_hook_t hook, void *hook_data);
 
   grub_usb_err_t (*setup_transfer) (grub_usb_controller_t dev,
 				    grub_usb_transfer_t transfer);

Thanks,

Signature · 1 line
Colin Watson                                       [[email protected]]