From 87edb8940a47a3c775bfd26317174468e3dd9eec Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 24 Jan 2012 13:31:12 +0100 Subject: [PATCH] Replace single-linked with double-linked lists. It results in more compact and more efficient code. * grub-core/kern/list.c (grub_list_push): Moved from here ... * include/grub/list.h (grub_list_push): ... to here. Set prev. (grub_list_remove): Moved from here ... * include/grub/list.h (grub_list_remove): ... here. Use and set prev. (grub_prio_list_insert): Set prev. * include/grub/list.h (grub_list): Add prev. All users updated. --- ChangeLog | 12 ++++++++ grub-core/bus/usb/usb.c | 2 +- grub-core/commands/terminal.c | 11 ++++--- grub-core/disk/ahci.c | 1 + grub-core/gettext/gettext.c | 1 + grub-core/kern/command.c | 3 +- grub-core/kern/emu/hostdisk.c | 1 + grub-core/kern/list.c | 23 ++------------- grub-core/loader/i386/xnu.c | 6 ++-- grub-core/net/net.c | 7 ++--- grub-core/net/tcp.c | 12 ++++---- grub-core/net/udp.c | 4 +-- grub-core/normal/auth.c | 5 ++-- grub-core/term/serial.c | 2 +- grub-core/tests/lib/test.c | 3 +- include/grub/command.h | 1 + include/grub/cryptodisk.h | 4 ++- include/grub/fs.h | 3 +- include/grub/list.h | 54 ++++++++++++++++++++++++----------- include/grub/net.h | 7 +++-- include/grub/partition.h | 4 +-- include/grub/serial.h | 1 + include/grub/term.h | 12 ++++---- include/grub/test.h | 1 + include/grub/usb.h | 1 + include/grub/video.h | 4 +-- util/deviceiter.c | 1 + 27 files changed, 111 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79124720b..6f3b10818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-01-24 Vladimir Serbinenko + + Replace single-linked with double-linked lists. It results in more + compact and more efficient code. + + * grub-core/kern/list.c (grub_list_push): Moved from here ... + * include/grub/list.h (grub_list_push): ... to here. Set prev. + (grub_list_remove): Moved from here ... + * include/grub/list.h (grub_list_remove): ... here. Use and set prev. + (grub_prio_list_insert): Set prev. + * include/grub/list.h (grub_list): Add prev. All users updated. + 2012-01-24 Vladimir Serbinenko Handle newer autotools. Add some missing quotes while on it. diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c index cde57ced8..fb04e6572 100644 --- a/grub-core/bus/usb/usb.c +++ b/grub-core/bus/usb/usb.c @@ -340,7 +340,7 @@ grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc) void grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc) { - grub_list_remove (GRUB_AS_LIST_P (&attach_hooks), GRUB_AS_LIST (desc)); + grub_list_remove (GRUB_AS_LIST (desc)); } diff --git a/grub-core/commands/terminal.c b/grub-core/commands/terminal.c index 0adfd3d2e..7184ca44b 100644 --- a/grub-core/commands/terminal.c +++ b/grub-core/commands/terminal.c @@ -31,6 +31,7 @@ struct grub_term_autoload *grub_term_output_autoload = NULL; struct abstract_terminal { struct abstract_terminal *next; + struct abstract_terminal *prev; const char *name; grub_err_t (*init) (struct abstract_terminal *term); grub_err_t (*fini) (struct abstract_terminal *term); @@ -137,7 +138,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled, if (term->init && term->init (term) != GRUB_ERR_NONE) return grub_errno; - grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term)); } } @@ -156,7 +157,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled, if (!term->next && term == *enabled) return grub_error (GRUB_ERR_BAD_ARGUMENT, "can't remove the last terminal"); - grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); if (term->fini) term->fini (term); grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term)); @@ -174,7 +175,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled, if (term->init && term->init (term) != GRUB_ERR_NONE) return grub_errno; - grub_list_remove (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); grub_list_push (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term)); } } @@ -192,7 +193,7 @@ handle_command (int argc, char **args, struct abstract_terminal **enabled, if (!term->next && term == *enabled) return grub_error (GRUB_ERR_BAD_ARGUMENT, "can't remove the last terminal"); - grub_list_remove (GRUB_AS_LIST_P (enabled), GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); if (term->fini) term->fini (term); grub_list_push (GRUB_AS_LIST_P (disabled), GRUB_AS_LIST (term)); @@ -208,6 +209,7 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, next); + (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, prev); (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, name); (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, init); (void) GRUB_FIELD_MATCH (grub_term_inputs, struct abstract_terminal *, fini); @@ -224,6 +226,7 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, next); + (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, prev); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, name); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, init); (void) GRUB_FIELD_MATCH (grub_term_outputs, struct abstract_terminal *, fini); diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c index 10b7be687..a5a14d414 100644 --- a/grub-core/disk/ahci.c +++ b/grub-core/disk/ahci.c @@ -121,6 +121,7 @@ enum struct grub_ahci_device { struct grub_ahci_device *next; + struct grub_ahci_device **prev; volatile struct grub_ahci_hba *hba; int port; int num; diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 682754421..2ff9d079b 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -46,6 +46,7 @@ static const char *(*grub_gettext_original) (const char *s); struct grub_gettext_msg { struct grub_gettext_msg *next; + struct grub_gettext_msg *prev; const char *name; const char *translated; diff --git a/grub-core/kern/command.c b/grub-core/kern/command.c index 7f353b653..91e469181 100644 --- a/grub-core/kern/command.c +++ b/grub-core/kern/command.c @@ -52,7 +52,6 @@ grub_register_command_prio (const char *name, void grub_unregister_command (grub_command_t cmd) { - grub_prio_list_remove (GRUB_AS_PRIO_LIST_P (&grub_command_list), - GRUB_AS_PRIO_LIST (cmd)); + grub_prio_list_remove (GRUB_AS_PRIO_LIST (cmd)); grub_free (cmd); } diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c index b3d35dd43..81e601f0b 100644 --- a/grub-core/kern/emu/hostdisk.c +++ b/grub-core/kern/emu/hostdisk.c @@ -635,6 +635,7 @@ devmapper_fail: struct linux_partition_cache { struct linux_partition_cache *next; + struct linux_partition_cache **prev; char *dev; unsigned long start; int partno; diff --git a/grub-core/kern/list.c b/grub-core/kern/list.c index 33c334166..f7c4e6bbe 100644 --- a/grub-core/kern/list.c +++ b/grub-core/kern/list.c @@ -21,26 +21,6 @@ #include #include -void -grub_list_push (grub_list_t *head, grub_list_t item) -{ - item->next = *head; - *head = item; -} - -void -grub_list_remove (grub_list_t *head, grub_list_t item) -{ - grub_list_t *p, q; - - for (p = head, q = *p; q; p = &(q->next), q = q->next) - if (q == item) - { - *p = q->next; - break; - } -} - void * grub_named_list_find (grub_named_list_t head, const char *name) { @@ -81,6 +61,9 @@ grub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem) *p = nitem; nitem->next = q; + if (q) + q->prev = &nitem->next; + nitem->prev = p; if (! inactive) nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE; diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index 98b635911..ac562a20d 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -58,6 +58,7 @@ static struct tbl_alias table_aliases[] = struct grub_xnu_devprop_device_descriptor { struct grub_xnu_devprop_device_descriptor *next; + struct grub_xnu_devprop_device_descriptor **prev; struct property_descriptor *properties; struct grub_efi_device_path *path; int pathlen; @@ -212,6 +213,7 @@ guessfsb (void) struct property_descriptor { struct property_descriptor *next; + struct property_descriptor **prev; grub_uint8_t *name; grub_uint16_t *name16; int name16len; @@ -234,7 +236,7 @@ grub_xnu_devprop_remove_property (struct grub_xnu_devprop_device_descriptor *dev grub_free (prop->name16); grub_free (prop->data); - grub_list_remove (GRUB_AS_LIST_P (&dev->properties), GRUB_AS_LIST (prop)); + grub_list_remove (GRUB_AS_LIST (prop)); return GRUB_ERR_NONE; } @@ -245,7 +247,7 @@ grub_xnu_devprop_remove_device (struct grub_xnu_devprop_device_descriptor *dev) void *t; struct property_descriptor *prop; - grub_list_remove (GRUB_AS_LIST_P (&devices), GRUB_AS_LIST (dev)); + grub_list_remove (GRUB_AS_LIST (dev)); for (prop = dev->properties; prop; ) { diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 347a95afd..25d079b94 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -40,6 +40,7 @@ char *grub_net_default_server; struct grub_net_route { struct grub_net_route *next; + struct grub_net_route **prev; grub_net_network_level_netaddress_t target; char *name; struct grub_net_network_level_protocol *prot; @@ -206,8 +207,7 @@ grub_net_card_unregister (struct grub_net_card *card) card->driver->close (card); card->opened = 0; } - grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards), - GRUB_AS_LIST (card)); + grub_list_remove (GRUB_AS_LIST (card)); } static struct grub_net_slaac_mac_list * @@ -366,8 +366,7 @@ grub_net_route_register (struct grub_net_route *route) static inline void grub_net_route_unregister (struct grub_net_route *route) { - grub_list_remove (GRUB_AS_LIST_P (&grub_net_routes), - GRUB_AS_LIST (route)); + grub_list_remove (GRUB_AS_LIST (route)); } #define FOR_NET_ROUTES(var) for (var = grub_net_routes; var; var = var->next) diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c index 1201220b5..65c6869c8 100644 --- a/grub-core/net/tcp.c +++ b/grub-core/net/tcp.c @@ -31,6 +31,7 @@ struct unacked { struct unacked *next; + struct unacked **prev; struct grub_net_buff *nb; grub_uint64_t last_try; int try_count; @@ -49,6 +50,7 @@ enum struct grub_net_tcp_socket { struct grub_net_tcp_socket *next; + struct grub_net_tcp_socket **prev; int established; int i_closed; @@ -80,6 +82,7 @@ struct grub_net_tcp_socket struct grub_net_tcp_listen { struct grub_net_tcp_listen *next; + struct grub_net_tcp_listen **prev; grub_uint16_t port; const struct grub_net_network_level_interface *inf; @@ -149,8 +152,7 @@ grub_net_tcp_listen (grub_uint16_t port, void grub_net_tcp_stop_listen (grub_net_tcp_listen_t listen) { - grub_list_remove (GRUB_AS_LIST_P (&tcp_listens), - GRUB_AS_LIST (listen)); + grub_list_remove (GRUB_AS_LIST (listen)); } static inline void @@ -640,8 +642,7 @@ grub_net_tcp_open (char *server, GRUB_NET_IP_TCP); if (err) { - grub_list_remove (GRUB_AS_LIST_P (&tcp_sockets), - GRUB_AS_LIST (socket)); + grub_list_remove (GRUB_AS_LIST (socket)); grub_free (socket); grub_netbuff_free (nb); return NULL; @@ -654,8 +655,7 @@ grub_net_tcp_open (char *server, } if (!socket->established) { - grub_list_remove (GRUB_AS_LIST_P (&tcp_sockets), - GRUB_AS_LIST (socket)); + grub_list_remove (GRUB_AS_LIST (socket)); if (socket->they_reseted) grub_error (GRUB_ERR_NET_PORT_CLOSED, "port closed"); else diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index 8ca8ebb0a..afe5de0c9 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -25,6 +25,7 @@ struct grub_net_udp_socket { struct grub_net_udp_socket *next; + struct grub_net_udp_socket **prev; enum { GRUB_NET_SOCKET_START, GRUB_NET_SOCKET_ESTABLISHED, @@ -53,8 +54,7 @@ udp_socket_register (grub_net_udp_socket_t sock) void grub_net_udp_close (grub_net_udp_socket_t sock) { - grub_list_remove (GRUB_AS_LIST_P (&udp_sockets), - GRUB_AS_LIST (sock)); + grub_list_remove (GRUB_AS_LIST (sock)); grub_free (sock); } diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c index 8e19568e2..499eb6c9d 100644 --- a/grub-core/normal/auth.c +++ b/grub-core/normal/auth.c @@ -28,6 +28,7 @@ struct grub_auth_user { struct grub_auth_user *next; + struct grub_auth_user **prev; char *name; grub_auth_callback_t callback; void *arg; @@ -73,7 +74,7 @@ grub_auth_unregister_authentication (const char *user) if (!cur->authenticated) { grub_free (cur->name); - grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur)); + grub_list_remove (GRUB_AS_LIST (cur)); grub_free (cur); } else @@ -121,7 +122,7 @@ grub_auth_deauthenticate (const char *user) if (!cur->callback) { grub_free (cur->name); - grub_list_remove (GRUB_AS_LIST_P (&users), GRUB_AS_LIST (cur)); + grub_list_remove (GRUB_AS_LIST (cur)); grub_free (cur); } else diff --git a/grub-core/term/serial.c b/grub-core/term/serial.c index 7b970587f..20ab90d92 100644 --- a/grub-core/term/serial.c +++ b/grub-core/term/serial.c @@ -350,7 +350,7 @@ grub_serial_unregister (struct grub_serial_port *port) if (port->term_out) grub_term_unregister_output (port->term_out); - grub_list_remove (GRUB_AS_LIST_P (&grub_serial_ports), GRUB_AS_LIST (port)); + grub_list_remove (GRUB_AS_LIST (port)); } void diff --git a/grub-core/tests/lib/test.c b/grub-core/tests/lib/test.c index 06d78b7d7..da688efc0 100644 --- a/grub-core/tests/lib/test.c +++ b/grub-core/tests/lib/test.c @@ -24,6 +24,7 @@ struct grub_test_failure { /* The next failure. */ struct grub_test_failure *next; + struct grub_test_failure **prev; /* The test source file name. */ char *file; @@ -124,7 +125,7 @@ grub_test_unregister (const char *name) if (test) { - grub_list_remove (GRUB_AS_LIST_P (&grub_test_list), GRUB_AS_LIST (test)); + grub_list_remove (GRUB_AS_LIST (test)); if (test->name) grub_free (test->name); diff --git a/include/grub/command.h b/include/grub/command.h index 19622752e..57c06da46 100644 --- a/include/grub/command.h +++ b/include/grub/command.h @@ -49,6 +49,7 @@ struct grub_command { /* The next element. */ struct grub_command *next; + struct grub_command **prev; /* The name. */ const char *name; diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index c6d1ce8de..0bb5d444e 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -59,6 +59,7 @@ typedef gcry_err_code_t struct grub_cryptodisk { struct grub_cryptodisk *next; + struct grub_cryptodisk **prev; char *source; grub_disk_addr_t offset; @@ -96,6 +97,7 @@ typedef struct grub_cryptodisk *grub_cryptodisk_t; struct grub_cryptodisk_dev { struct grub_cryptodisk_dev *next; + struct grub_cryptodisk_dev **prev; grub_cryptodisk_t (*scan) (grub_disk_t disk, const char *check_uuid, int boot_only); @@ -116,7 +118,7 @@ grub_cryptodisk_dev_register (grub_cryptodisk_dev_t cr) static inline void grub_cryptodisk_dev_unregister (grub_cryptodisk_dev_t cr) { - grub_list_remove (GRUB_AS_LIST_P (&grub_cryptodisk_list), GRUB_AS_LIST (cr)); + grub_list_remove (GRUB_AS_LIST (cr)); } #define FOR_CRYPTODISK_DEVS(var) FOR_LIST_ELEMENTS((var), (grub_cryptodisk_list)) diff --git a/include/grub/fs.h b/include/grub/fs.h index dd274e151..10374ed90 100644 --- a/include/grub/fs.h +++ b/include/grub/fs.h @@ -46,6 +46,7 @@ struct grub_fs { /* The next filesystem. */ struct grub_fs *next; + struct grub_fs **prev; /* My name. */ const char *name; @@ -111,7 +112,7 @@ grub_fs_register (grub_fs_t fs) static inline void grub_fs_unregister (grub_fs_t fs) { - grub_list_remove (GRUB_AS_LIST_P (&grub_fs_list), GRUB_AS_LIST (fs)); + grub_list_remove (GRUB_AS_LIST (fs)); } #define FOR_FILESYSTEMS(var) FOR_LIST_ELEMENTS((var), (grub_fs_list)) diff --git a/include/grub/list.h b/include/grub/list.h index 3dfb97ac6..6629b2c19 100644 --- a/include/grub/list.h +++ b/include/grub/list.h @@ -27,11 +27,27 @@ struct grub_list { struct grub_list *next; + struct grub_list **prev; }; typedef struct grub_list *grub_list_t; -void EXPORT_FUNC(grub_list_push) (grub_list_t *head, grub_list_t item); -void EXPORT_FUNC(grub_list_remove) (grub_list_t *head, grub_list_t item); +static inline void +grub_list_push (grub_list_t *head, grub_list_t item) +{ + item->prev = head; + if (*head) + (*head)->prev = &item->next; + item->next = *head; + *head = item; +} + +static inline void +grub_list_remove (grub_list_t item) +{ + *item->prev = item->next; + if (item->next) + item->next->prev = item->prev; +} #define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next) @@ -53,16 +69,17 @@ grub_bad_type_cast_real (int line, const char *file) ((char *) &(ptr)->field == (char *) &((type) (ptr))->field) #define GRUB_AS_LIST(ptr) \ - (GRUB_FIELD_MATCH (ptr, grub_list_t, next) ? \ + (GRUB_FIELD_MATCH (ptr, grub_list_t, next) && GRUB_FIELD_MATCH (ptr, grub_list_t, prev) ? \ (grub_list_t) ptr : (grub_list_t) grub_bad_type_cast ()) #define GRUB_AS_LIST_P(pptr) \ - (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) ? \ + (GRUB_FIELD_MATCH (*pptr, grub_list_t, next) && GRUB_FIELD_MATCH (*pptr, grub_list_t, prev) ? \ (grub_list_t *) (void *) pptr : (grub_list_t *) grub_bad_type_cast ()) struct grub_named_list { struct grub_named_list *next; + struct grub_named_list **prev; char *name; }; typedef struct grub_named_list *grub_named_list_t; @@ -71,13 +88,15 @@ void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head, const char *name); #define GRUB_AS_NAMED_LIST(ptr) \ - ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) && \ - GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \ + ((GRUB_FIELD_MATCH (ptr, grub_named_list_t, next) \ + && GRUB_FIELD_MATCH (ptr, grub_named_list_t, prev) \ + && GRUB_FIELD_MATCH (ptr, grub_named_list_t, name))? \ (grub_named_list_t) ptr : (grub_named_list_t) grub_bad_type_cast ()) #define GRUB_AS_NAMED_LIST_P(pptr) \ - ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) && \ - GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \ + ((GRUB_FIELD_MATCH (*pptr, grub_named_list_t, next) \ + && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, prev) \ + && GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \ (grub_named_list_t *) (void *) pptr : (grub_named_list_t *) grub_bad_type_cast ()) #define GRUB_PRIO_LIST_PRIO_MASK 0xff @@ -86,6 +105,7 @@ void * EXPORT_FUNC(grub_named_list_find) (grub_named_list_t head, struct grub_prio_list { struct grub_prio_list *next; + struct grub_prio_list **prev; char *name; int prio; }; @@ -95,24 +115,26 @@ void EXPORT_FUNC(grub_prio_list_insert) (grub_prio_list_t *head, grub_prio_list_t item); static inline void -grub_prio_list_remove (grub_prio_list_t *head, grub_prio_list_t item) +grub_prio_list_remove (grub_prio_list_t item) { if ((item->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (item->next)) item->next->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE; - grub_list_remove (GRUB_AS_LIST_P (head), GRUB_AS_LIST (item)); + grub_list_remove (GRUB_AS_LIST (item)); } #define GRUB_AS_PRIO_LIST(ptr) \ - ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \ - GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \ - GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \ + ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) \ + && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prev) \ + && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) \ + && GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \ (grub_prio_list_t) ptr \ : (grub_prio_list_t) grub_bad_type_cast ()) #define GRUB_AS_PRIO_LIST_P(pptr) \ - ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \ - GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \ - GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio)) ? \ + ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) \ + && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prev) \ + && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) \ + && GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio)) ? \ (grub_prio_list_t *) (void *) pptr \ : (grub_prio_list_t *) grub_bad_type_cast ()) diff --git a/include/grub/net.h b/include/grub/net.h index 3913272eb..d9fd821d9 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -72,6 +72,7 @@ struct grub_net_card; struct grub_net_card_driver { struct grub_net_card_driver *next; + struct grub_net_card_driver **prev; const char *name; grub_err_t (*open) (const struct grub_net_card *dev); void (*close) (const struct grub_net_card *dev); @@ -101,6 +102,7 @@ typedef struct grub_net_packets struct grub_net_slaac_mac_list { struct grub_net_slaac_mac_list *next; + struct grub_net_slaac_mac_list **prev; grub_net_link_level_address_t address; int slaac_counter; char *name; @@ -111,6 +113,7 @@ struct grub_net_link_layer_entry; struct grub_net_card { struct grub_net_card *next; + struct grub_net_card **prev; const char *name; struct grub_net_card_driver *driver; grub_net_link_level_address_t default_address; @@ -220,6 +223,7 @@ typedef struct grub_net_socket *grub_net_socket_t; struct grub_net_app_protocol { struct grub_net_app_protocol *next; + struct grub_net_app_protocol **prev; const char *name; grub_err_t (*dir) (grub_device_t device, const char *path, int (*hook) (const char *filename, @@ -317,8 +321,7 @@ grub_net_app_level_register (grub_net_app_level_t proto) static inline void grub_net_app_level_unregister (grub_net_app_level_t proto) { - grub_list_remove (GRUB_AS_LIST_P (&grub_net_app_level_list), - GRUB_AS_LIST (proto)); + grub_list_remove (GRUB_AS_LIST (proto)); } #define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \ diff --git a/include/grub/partition.h b/include/grub/partition.h index e7e00ef7f..7c1e7f6b3 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -38,6 +38,7 @@ struct grub_partition_map { /* The next partition map type. */ struct grub_partition_map *next; + struct grub_partition_map **prev; /* The name of the partition map type. */ const char *name; @@ -106,8 +107,7 @@ grub_partition_map_register (grub_partition_map_t partmap) static inline void grub_partition_map_unregister (grub_partition_map_t partmap) { - grub_list_remove (GRUB_AS_LIST_P (&grub_partition_map_list), - GRUB_AS_LIST (partmap)); + grub_list_remove (GRUB_AS_LIST (partmap)); } #define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list)) diff --git a/include/grub/serial.h b/include/grub/serial.h index feaa5b1a7..242823fab 100644 --- a/include/grub/serial.h +++ b/include/grub/serial.h @@ -63,6 +63,7 @@ struct grub_serial_config struct grub_serial_port { struct grub_serial_port *next; + struct grub_serial_port **prev; char *name; struct grub_serial_driver *driver; struct grub_serial_config config; diff --git a/include/grub/term.h b/include/grub/term.h index 4c997cdaf..8fdf16234 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -147,6 +147,7 @@ struct grub_term_input { /* The next terminal. */ struct grub_term_input *next; + struct grub_term_input **prev; /* The terminal name. */ const char *name; @@ -171,6 +172,7 @@ struct grub_term_output { /* The next terminal. */ struct grub_term_output *next; + struct grub_term_output **prev; /* The terminal name. */ const char *name; @@ -300,17 +302,15 @@ grub_term_register_output_active (const char *name __attribute__ ((unused)), static inline void grub_term_unregister_input (grub_term_input_t term) { - grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); - grub_list_remove (GRUB_AS_LIST_P (&grub_term_inputs_disabled), - GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); } static inline void grub_term_unregister_output (grub_term_output_t term) { - grub_list_remove (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); - grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), - GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); + grub_list_remove (GRUB_AS_LIST (term)); } #define FOR_ACTIVE_TERM_INPUTS(var) FOR_LIST_ELEMENTS((var), (grub_term_inputs)) diff --git a/include/grub/test.h b/include/grub/test.h index 336d3b672..04a8ca13a 100644 --- a/include/grub/test.h +++ b/include/grub/test.h @@ -29,6 +29,7 @@ struct grub_test { /* The next test. */ struct grub_test *next; + struct grub_test **prev; /* The test name. */ char *name; diff --git a/include/grub/usb.h b/include/grub/usb.h index ee133dbf5..bf6e101c8 100644 --- a/include/grub/usb.h +++ b/include/grub/usb.h @@ -264,6 +264,7 @@ typedef int (*grub_usb_attach_hook_class) (grub_usb_device_t usbdev, struct grub_usb_attach_desc { struct grub_usb_attach_desc *next; + struct grub_usb_attach_desc **prev; int class; grub_usb_attach_hook_class hook; }; diff --git a/include/grub/video.h b/include/grub/video.h index 352544c85..b3709bceb 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -298,6 +298,7 @@ struct grub_video_adapter { /* The next video adapter. */ struct grub_video_adapter *next; + struct grub_video_adapter **prev; /* The video adapter name. */ const char *name; @@ -398,8 +399,7 @@ grub_video_register (grub_video_adapter_t adapter) static inline void grub_video_unregister (grub_video_adapter_t adapter) { - grub_list_remove (GRUB_AS_LIST_P (&grub_video_adapter_list), - GRUB_AS_LIST (adapter)); + grub_list_remove (GRUB_AS_LIST (adapter)); } #define FOR_VIDEO_ADAPTERS(var) FOR_LIST_ELEMENTS((var), (grub_video_adapter_list)) diff --git a/util/deviceiter.c b/util/deviceiter.c index 208dcfdde..87cbc9ebc 100644 --- a/util/deviceiter.c +++ b/util/deviceiter.c @@ -369,6 +369,7 @@ get_xvd_disk_name (char *name, int unit) static struct seen_device { struct seen_device *next; + struct seen_device **prev; const char *name; } *seen;