[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 8/n] Remove nested functions from USB iterators
From: |
Colin Watson |
Subject: |
[PATCH 8/n] Remove nested functions from USB iterators |
Date: |
Mon, 21 Jan 2013 12:57:00 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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 2013-01-21 11:10:25 +0000
+++ ChangeLog 2013-01-21 12:56:37 +0000
@@ -1,5 +1,17 @@
2013-01-21 Colin Watson <address@hidden>
+ 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 <address@hidden>
+
* 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'
--- grub-core/bus/usb/ehci.c 2013-01-13 01:10:41 +0000
+++ grub-core/bus/usb/ehci.c 2013-01-21 12:18:35 +0000
@@ -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'
--- grub-core/bus/usb/emu/usb.c 2011-04-11 21:01:51 +0000
+++ grub-core/bus/usb/emu/usb.c 2013-01-21 12:18:35 +0000
@@ -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'
--- grub-core/bus/usb/ohci.c 2013-01-13 01:10:41 +0000
+++ grub-core/bus/usb/ohci.c 2013-01-21 12:18:35 +0000
@@ -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'
--- grub-core/bus/usb/uhci.c 2013-01-13 01:10:41 +0000
+++ grub-core/bus/usb/uhci.c 2013-01-21 12:18:35 +0000
@@ -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'
--- grub-core/bus/usb/usb.c 2012-01-24 12:31:12 +0000
+++ grub-core/bus/usb/usb.c 2013-01-21 12:25:17 +0000
@@ -29,27 +29,28 @@ GRUB_MOD_LICENSE ("GPLv3+");
static grub_usb_controller_dev_t grub_usb_list;
static struct grub_usb_attach_desc *attach_hooks;
-void
-grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
+/* Iterate over all controllers found by the driver. */
+static int
+grub_usb_controller_dev_register_iter (grub_usb_controller_t dev, void *data)
{
- auto int iterate_hook (grub_usb_controller_t dev);
+ grub_usb_controller_dev_t usb = data;
- /* Iterate over all controllers found by the driver. */
- int iterate_hook (grub_usb_controller_t dev)
- {
- dev->dev = usb;
+ dev->dev = usb;
- /* Enable the ports of the USB Root Hub. */
- grub_usb_root_hub (dev);
+ /* Enable the ports of the USB Root Hub. */
+ grub_usb_root_hub (dev);
- return 0;
- }
+ return 0;
+}
+void
+grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
+{
usb->next = grub_usb_list;
grub_usb_list = usb;
if (usb->iterate)
- usb->iterate (iterate_hook);
+ usb->iterate (grub_usb_controller_dev_register_iter, usb);
}
void
@@ -66,27 +67,41 @@ grub_usb_controller_dev_unregister (grub
}
#if 0
-int
-grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev))
+/* Context for grub_usb_controller_iterate. */
+struct grub_usb_controller_iterate_ctx
{
+ grub_usb_controller_iterate_hook_t hook;
+ void *hook_data;
grub_usb_controller_dev_t p;
+};
- auto int iterate_hook (grub_usb_controller_t dev);
+/* Helper for grub_usb_controller_iterate. */
+static int
+grub_usb_controller_iterate_iter (grub_usb_controller_t dev, void *data)
+{
+ struct grub_usb_controller_iterate_ctx *ctx = data;
- int iterate_hook (grub_usb_controller_t dev)
- {
- dev->dev = p;
- if (hook (dev))
- return 1;
- return 0;
- }
+ dev->dev = ctx->p;
+ if (ctx->hook (dev, ctx->hook_data))
+ return 1;
+ return 0;
+}
+
+int
+grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook,
+ void *hook_data)
+{
+ struct grub_usb_controller_iterate_ctx ctx = {
+ .hook = hook,
+ .hook_data = hook_data
+ };
/* Iterate over all controller drivers. */
- for (p = grub_usb_list; p; p = p->next)
+ for (ctx.p = grub_usb_list; ctx.p; ctx.p = ctx.p->next)
{
/* Iterate over the busses of the controllers. XXX: Actually, a
hub driver should do this. */
- if (p->iterate (iterate_hook))
+ if (ctx.p->iterate (grub_usb_controller_iterate_iter, &ctx))
return 1;
}
@@ -295,46 +310,47 @@ void grub_usb_device_attach (grub_usb_de
}
}
-void
-grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
+/* Helper for grub_usb_register_attach_hook_class. */
+static int
+grub_usb_register_attach_hook_class_iter (grub_usb_device_t usbdev, void *data)
{
- auto int usb_iterate (grub_usb_device_t dev);
-
- int usb_iterate (grub_usb_device_t usbdev)
- {
- struct grub_usb_desc_device *descdev = &usbdev->descdev;
- int i;
-
- if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
- || descdev->configcnt == 0)
- return 0;
+ struct grub_usb_attach_desc *desc = data;
+ struct grub_usb_desc_device *descdev = &usbdev->descdev;
+ int i;
- /* XXX: Just check configuration 0 for now. */
- for (i = 0; i < usbdev->config[0].descconf->numif; i++)
- {
- struct grub_usb_desc_if *interf;
+ if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
+ || descdev->configcnt == 0)
+ return 0;
- interf = usbdev->config[0].interf[i].descif;
+ /* XXX: Just check configuration 0 for now. */
+ for (i = 0; i < usbdev->config[0].descconf->numif; i++)
+ {
+ struct grub_usb_desc_if *interf;
- grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d,
protocol=%d\n",
- i, interf->class, interf->subclass, interf->protocol);
+ interf = usbdev->config[0].interf[i].descif;
- if (usbdev->config[0].interf[i].attached)
- continue;
+ grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d,
protocol=%d\n",
+ i, interf->class, interf->subclass, interf->protocol);
- if (interf->class != desc->class)
- continue;
- if (desc->hook (usbdev, 0, i))
- usbdev->config[0].interf[i].attached = 1;
- }
+ if (usbdev->config[0].interf[i].attached)
+ continue;
- return 0;
+ if (interf->class != desc->class)
+ continue;
+ if (desc->hook (usbdev, 0, i))
+ usbdev->config[0].interf[i].attached = 1;
}
+ return 0;
+}
+
+void
+grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
+{
desc->next = attach_hooks;
attach_hooks = desc;
- grub_usb_iterate (usb_iterate);
+ grub_usb_iterate (grub_usb_register_attach_hook_class_iter, desc);
}
void
=== modified file 'grub-core/bus/usb/usbhub.c'
--- grub-core/bus/usb/usbhub.c 2012-02-01 15:13:17 +0000
+++ grub-core/bus/usb/usbhub.c 2013-01-21 12:18:35 +0000
@@ -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'
--- grub-core/commands/usbtest.c 2012-04-07 18:03:38 +0000
+++ grub-core/commands/usbtest.c 2013-01-21 12:18:35 +0000
@@ -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'
--- include/grub/usb.h 2012-02-01 13:30:40 +0000
+++ include/grub/usb.h 2013-01-21 12:18:35 +0000
@@ -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,
--
Colin Watson address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 8/n] Remove nested functions from USB iterators,
Colin Watson <=