From e17568ad0642490143d0c6b154c874b9b9e285bf Mon Sep 17 00:00:00 2001 From: Geert Stappers Date: Fri, 30 Jun 2023 10:59:59 +0100 Subject: [build] Inhibit linker warnings about an implied executable stack Signed-off-by: Geert Stappers Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/x86/interface/pcbios/e820mangler.S | 1 + src/arch/x86/interface/pxe/pxe_entry.S | 1 + src/arch/x86/interface/syslinux/com32_wrapper.S | 1 + 3 files changed, 3 insertions(+) (limited to 'src/arch/x86/interface') diff --git a/src/arch/x86/interface/pcbios/e820mangler.S b/src/arch/x86/interface/pcbios/e820mangler.S index 296a6488b..46e1cab4d 100644 --- a/src/arch/x86/interface/pcbios/e820mangler.S +++ b/src/arch/x86/interface/pcbios/e820mangler.S @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/interface/pxe/pxe_entry.S b/src/arch/x86/interface/pxe/pxe_entry.S index 3a5a100e3..354dd1b35 100644 --- a/src/arch/x86/interface/pxe/pxe_entry.S +++ b/src/arch/x86/interface/pxe/pxe_entry.S @@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .arch i386 /**************************************************************************** diff --git a/src/arch/x86/interface/syslinux/com32_wrapper.S b/src/arch/x86/interface/syslinux/com32_wrapper.S index d59a3392c..501919565 100644 --- a/src/arch/x86/interface/syslinux/com32_wrapper.S +++ b/src/arch/x86/interface/syslinux/com32_wrapper.S @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER ) #include "librm.h" + .section ".note.GNU-stack", "", @progbits .text .code32 -- cgit v1.2.3-55-g7522 From 3ef4f7e2ef4a22ea1e2eccc72957d7bf3fe2f945 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 4 Jul 2023 14:31:07 +0100 Subject: [console] Avoid overlap between special keys and Unicode characters The special key range (from KEY_MIN upwards) currently overlaps with the valid range for Unicode characters, and therefore prohibits the use of Unicode key values outside the ASCII range. Create space for Unicode key values by moving the special keys to the range immediately above the maximum valid Unicode character. This allows the existing encoding of special keys as an efficiently packed representation of the equivalent ANSI escape sequence to be maintained almost as-is. Signed-off-by: Michael Brown --- src/arch/x86/interface/pcbios/bios_console.c | 59 +++++++++++++++++----------- src/drivers/usb/usbkbd.c | 4 +- src/include/ipxe/keys.h | 45 ++++++++++++++++++--- 3 files changed, 77 insertions(+), 31 deletions(-) (limited to 'src/arch/x86/interface') diff --git a/src/arch/x86/interface/pcbios/bios_console.c b/src/arch/x86/interface/pcbios/bios_console.c index 0220c8564..7263eb712 100644 --- a/src/arch/x86/interface/pcbios/bios_console.c +++ b/src/arch/x86/interface/pcbios/bios_console.c @@ -290,29 +290,38 @@ static const char *bios_ansi_input = ""; struct bios_key { /** Scancode */ uint8_t scancode; - /** Key code */ - uint16_t key; + /** Relative key value */ + uint16_t rkey; } __attribute__ (( packed )); +/** + * Define a BIOS key mapping + * + * @v scancode Scancode + * @v key iPXE key code + * @v bioskey BIOS key mapping + */ +#define BIOS_KEY( scancode, key ) { scancode, KEY_REL ( key ) } + /** Mapping from BIOS scan codes to iPXE key codes */ static const struct bios_key bios_keys[] = { - { 0x53, KEY_DC }, - { 0x48, KEY_UP }, - { 0x50, KEY_DOWN }, - { 0x4b, KEY_LEFT }, - { 0x4d, KEY_RIGHT }, - { 0x47, KEY_HOME }, - { 0x4f, KEY_END }, - { 0x49, KEY_PPAGE }, - { 0x51, KEY_NPAGE }, - { 0x3f, KEY_F5 }, - { 0x40, KEY_F6 }, - { 0x41, KEY_F7 }, - { 0x42, KEY_F8 }, - { 0x43, KEY_F9 }, - { 0x44, KEY_F10 }, - { 0x85, KEY_F11 }, - { 0x86, KEY_F12 }, + BIOS_KEY ( 0x53, KEY_DC ), + BIOS_KEY ( 0x48, KEY_UP ), + BIOS_KEY ( 0x50, KEY_DOWN ), + BIOS_KEY ( 0x4b, KEY_LEFT ), + BIOS_KEY ( 0x4d, KEY_RIGHT ), + BIOS_KEY ( 0x47, KEY_HOME ), + BIOS_KEY ( 0x4f, KEY_END ), + BIOS_KEY ( 0x49, KEY_PPAGE ), + BIOS_KEY ( 0x51, KEY_NPAGE ), + BIOS_KEY ( 0x3f, KEY_F5 ), + BIOS_KEY ( 0x40, KEY_F6 ), + BIOS_KEY ( 0x41, KEY_F7 ), + BIOS_KEY ( 0x42, KEY_F8 ), + BIOS_KEY ( 0x43, KEY_F9 ), + BIOS_KEY ( 0x44, KEY_F10 ), + BIOS_KEY ( 0x85, KEY_F11 ), + BIOS_KEY ( 0x86, KEY_F12 ), }; /** @@ -323,7 +332,7 @@ static const struct bios_key bios_keys[] = { */ static const char * bios_ansi_seq ( unsigned int scancode ) { static char buf[ 5 /* "[" + two digits + terminator + NUL */ ]; - unsigned int key; + unsigned int rkey; unsigned int terminator; unsigned int n; unsigned int i; @@ -338,9 +347,9 @@ static const char * bios_ansi_seq ( unsigned int scancode ) { continue; /* Construct escape sequence */ - key = bios_keys[i].key; - n = KEY_ANSI_N ( key ); - terminator = KEY_ANSI_TERMINATOR ( key ); + rkey = bios_keys[i].rkey; + n = KEY_ANSI_N ( rkey ); + terminator = KEY_ANSI_TERMINATOR ( rkey ); *(tmp++) = '['; if ( n ) tmp += sprintf ( tmp, "%d", n ); @@ -479,6 +488,7 @@ struct console_driver bios_console __console_driver = { static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) { unsigned int discard_a; unsigned int scancode; + unsigned int rkey; unsigned int i; uint16_t keypress; int key; @@ -521,9 +531,10 @@ static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) { /* Handle special keys */ if ( key >= KEY_MIN ) { + rkey = KEY_REL ( key ); for ( i = 0 ; i < ( sizeof ( bios_keys ) / sizeof ( bios_keys[0] ) ) ; i++ ) { - if ( bios_keys[i].key == key ) { + if ( bios_keys[i].rkey == rkey ) { scancode = bios_keys[i].scancode; keypress = ( scancode << 8 ); break; diff --git a/src/drivers/usb/usbkbd.c b/src/drivers/usb/usbkbd.c index b284e584f..cf881ad1a 100644 --- a/src/drivers/usb/usbkbd.c +++ b/src/drivers/usb/usbkbd.c @@ -95,7 +95,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, } } else if ( keycode <= USBKBD_KEY_UP ) { /* Special keys */ - static const uint16_t special[] = { + static const unsigned int special[] = { 0, 0, 0, 0, 0, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, 0, 0, 0, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, @@ -110,7 +110,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, if ( leds & USBKBD_LED_NUM_LOCK ) { key = "1234567890." [ keycode - USBKBD_KEY_PAD_1 ]; } else { - static const uint16_t keypad[] = { + static const unsigned int keypad[] = { KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, 0, KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PPAGE, KEY_IC, KEY_DC diff --git a/src/include/ipxe/keys.h b/src/include/ipxe/keys.h index d15267a1f..23356913d 100644 --- a/src/include/ipxe/keys.h +++ b/src/include/ipxe/keys.h @@ -49,19 +49,54 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ESC 0x1b /* - * Special keys outside the normal ASCII range - * + * Special keys outside the normal Unicode range * * The names are chosen to match those used by curses. The values are * chosen to facilitate easy conversion from a received ANSI escape * sequence to a KEY_XXX constant. */ -#define KEY_ANSI( n, terminator ) ( 0x100 * ( (n) + 1 ) + (terminator) ) -#define KEY_ANSI_N( key ) ( ( (key) / 0x100 ) - 1 ) +/** + * Minimum value for special keypresses + * + * This value is chosen to lie above the maximum Unicode code point + * value 0x10ffff. + */ +#define KEY_MIN 0x110000 + +/** + * Construct relative key value for special key + * + * @v key Key value + * @ret rkey Relative key value + */ +#define KEY_REL( key ) ( (key) - KEY_MIN ) + +/** + * Construct ANSI escape sequence key value + * + * @v n ANSI escape sequence numeric portion, or 0 for none + * @v terminator ANSI escape sequence terminating character + * @ret key Key value + */ +#define KEY_ANSI( n, terminator ) ( KEY_MIN + ( (n) << 8 ) + (terminator) ) + +/** + * Extract ANSI escape sequence numeric portion + * + * @v key Key value (or relative key value) + * @ret n ANSI escape sequence numeric portion, or 0 for none + */ +#define KEY_ANSI_N( key ) ( ( (key) >> 8 ) & 0xff ) + +/** + * Extract ANSI escape sequence terminating character + * + * @v key Key value (or relative key value) + * @ret terminator ANSI escape sequence terminating character + */ #define KEY_ANSI_TERMINATOR( key ) ( (key) & 0xff ) -#define KEY_MIN 0x101 #define KEY_UP KEY_ANSI ( 0, 'A' ) /**< Up arrow */ #define KEY_DOWN KEY_ANSI ( 0, 'B' ) /**< Down arrow */ #define KEY_RIGHT KEY_ANSI ( 0, 'C' ) /**< Right arrow */ -- cgit v1.2.3-55-g7522 From ae4e85bde97c9b216736a5087039f3309a628d24 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 13 Sep 2023 16:29:59 +0100 Subject: [netdevice] Allocate private data for each network upper-layer driver Allow network upper-layer drivers (such as LLDP, which attaches to each network device in order to provide a corresponding LLDP settings block) to specify a size for private data, which will be allocated as part of the network device structure (as with the existing private data allocated for the underlying device driver). This will allow network upper-layer drivers to be simplified by omitting memory allocation and freeing code. If the upper-layer driver requires a reference counter (e.g. for interface initialisation), then it may use the network device's existing reference counter, since this is now the reference counter for the containing block of memory. Signed-off-by: Michael Brown --- src/arch/x86/interface/pxe/pxe_call.c | 3 +- src/arch/x86/interface/vmware/guestinfo.c | 8 +++- src/core/cachedhcp.c | 3 +- src/drivers/net/netfront.c | 4 +- src/include/ipxe/netdevice.h | 13 ++++-- src/interface/efi/efi_snp.c | 9 ++-- src/net/fcoe.c | 9 ++-- src/net/infiniband/xsigo.c | 4 +- src/net/ipv6.c | 4 +- src/net/lldp.c | 3 +- src/net/neighbour.c | 3 +- src/net/netdevice.c | 72 +++++++++++++++++++++++++------ src/net/vlan.c | 9 ++-- 13 files changed, 110 insertions(+), 34 deletions(-) (limited to 'src/arch/x86/interface') diff --git a/src/arch/x86/interface/pxe/pxe_call.c b/src/arch/x86/interface/pxe/pxe_call.c index 671182991..0e8d5c5a8 100644 --- a/src/arch/x86/interface/pxe/pxe_call.c +++ b/src/arch/x86/interface/pxe/pxe_call.c @@ -375,9 +375,10 @@ int pxe_start_nbp ( void ) { * Notify BIOS of existence of network device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int pxe_notify ( struct net_device *netdev ) { +static int pxe_notify ( struct net_device *netdev, void *priv __unused ) { /* Do nothing if we already have a network device */ if ( pxe_netdev ) diff --git a/src/arch/x86/interface/vmware/guestinfo.c b/src/arch/x86/interface/vmware/guestinfo.c index a0530c8d1..b52c2e87b 100644 --- a/src/arch/x86/interface/vmware/guestinfo.c +++ b/src/arch/x86/interface/vmware/guestinfo.c @@ -207,9 +207,11 @@ struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL ) = { * Create per-netdevice GuestInfo settings * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int guestinfo_net_probe ( struct net_device *netdev ) { +static int guestinfo_net_probe ( struct net_device *netdev, + void *priv __unused ) { struct settings *settings; int rc; @@ -247,8 +249,10 @@ static int guestinfo_net_probe ( struct net_device *netdev ) { * Remove per-netdevice GuestInfo settings * * @v netdev Network device + * @v priv Private data */ -static void guestinfo_net_remove ( struct net_device *netdev ) { +static void guestinfo_net_remove ( struct net_device *netdev, + void *priv __unused ) { struct settings *parent = netdev_settings ( netdev ); struct settings *settings; diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c index 60213f02d..57226e165 100644 --- a/src/core/cachedhcp.c +++ b/src/core/cachedhcp.c @@ -295,9 +295,10 @@ struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = { * Apply cached DHCPACK to network device, if applicable * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int cachedhcp_probe ( struct net_device *netdev ) { +static int cachedhcp_probe ( struct net_device *netdev, void *priv __unused ) { /* Apply cached DHCPACK to network device, if applicable */ return cachedhcp_apply ( &cached_dhcpack, netdev ); diff --git a/src/drivers/net/netfront.c b/src/drivers/net/netfront.c index 90930a5a3..12713c5b4 100644 --- a/src/drivers/net/netfront.c +++ b/src/drivers/net/netfront.c @@ -1056,9 +1056,11 @@ struct xen_driver netfront_driver __xen_driver = { * Inhibit emulated PCI devices * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int netfront_net_probe ( struct net_device *netdev ) { +static int netfront_net_probe ( struct net_device *netdev, + void *priv __unused ) { struct netfront_nic *netfront; /* Inhibit emulated PCI devices matching an existing netfront device */ diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h index a65dbfd23..caa83b44b 100644 --- a/src/include/ipxe/netdevice.h +++ b/src/include/ipxe/netdevice.h @@ -473,22 +473,27 @@ struct net_device { struct net_driver { /** Name */ const char *name; + /** Size of private data */ + size_t priv_len; /** Probe device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ - int ( * probe ) ( struct net_device *netdev ); + int ( * probe ) ( struct net_device *netdev, void *priv ); /** Notify of device or link state change * * @v netdev Network device + * @v priv Private data */ - void ( * notify ) ( struct net_device *netdev ); + void ( * notify ) ( struct net_device *netdev, void *priv ); /** Remove device * * @v netdev Network device + * @v priv Private data */ - void ( * remove ) ( struct net_device *netdev ); + void ( * remove ) ( struct net_device *netdev, void *priv ); }; /** Network driver table */ @@ -688,6 +693,8 @@ netdev_rx_frozen ( struct net_device *netdev ) { return ( netdev->state & NETDEV_RX_FROZEN ); } +extern void * netdev_priv ( struct net_device *netdev, + struct net_driver *driver ); extern void netdev_rx_freeze ( struct net_device *netdev ); extern void netdev_rx_unfreeze ( struct net_device *netdev ); extern void netdev_link_err ( struct net_device *netdev, int rc ); diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index c4f7d4ea8..8443be997 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -1777,9 +1777,10 @@ static struct efi_snp_device * efi_snp_demux ( struct net_device *netdev ) { * Create SNP device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int efi_snp_probe ( struct net_device *netdev ) { +static int efi_snp_probe ( struct net_device *netdev, void *priv __unused ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_device *efidev; struct efi_snp_device *snpdev; @@ -2017,8 +2018,9 @@ static int efi_snp_probe ( struct net_device *netdev ) { * Handle SNP device or link state change * * @v netdev Network device + * @v priv Private data */ -static void efi_snp_notify ( struct net_device *netdev ) { +static void efi_snp_notify ( struct net_device *netdev, void *priv __unused ) { struct efi_snp_device *snpdev; /* Locate SNP device */ @@ -2042,8 +2044,9 @@ static void efi_snp_notify ( struct net_device *netdev ) { * Destroy SNP device * * @v netdev Network device + * @v priv Private data */ -static void efi_snp_remove ( struct net_device *netdev ) { +static void efi_snp_remove ( struct net_device *netdev, void *priv __unused ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_snp_device *snpdev; int leak = efi_shutdown_in_progress; diff --git a/src/net/fcoe.c b/src/net/fcoe.c index f910eeead..70804dd03 100644 --- a/src/net/fcoe.c +++ b/src/net/fcoe.c @@ -1110,9 +1110,10 @@ static void fcoe_expired ( struct retry_timer *timer, int over __unused ) { * Create FCoE port * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int fcoe_probe ( struct net_device *netdev ) { +static int fcoe_probe ( struct net_device *netdev, void *priv __unused ) { struct ll_protocol *ll_protocol = netdev->ll_protocol; struct fcoe_port *fcoe; int rc; @@ -1162,8 +1163,9 @@ static int fcoe_probe ( struct net_device *netdev ) { * Handle FCoE port device or link state change * * @v netdev Network device + * @v priv Private data */ -static void fcoe_notify ( struct net_device *netdev ) { +static void fcoe_notify ( struct net_device *netdev, void *priv __unused ) { struct fcoe_port *fcoe; /* Sanity check */ @@ -1185,8 +1187,9 @@ static void fcoe_notify ( struct net_device *netdev ) { * Destroy FCoE port * * @v netdev Network device + * @v priv Private data */ -static void fcoe_remove ( struct net_device *netdev ) { +static void fcoe_remove ( struct net_device *netdev, void *priv __unused ) { struct fcoe_port *fcoe; /* Sanity check */ diff --git a/src/net/infiniband/xsigo.c b/src/net/infiniband/xsigo.c index 4f5c618d7..5e805fa02 100644 --- a/src/net/infiniband/xsigo.c +++ b/src/net/infiniband/xsigo.c @@ -1829,8 +1829,10 @@ struct ib_driver xsigo_ib_driver __ib_driver = { * Handle device or link status change * * @v netdev Network device + * @v priv Private data */ -static void xsigo_net_notify ( struct net_device *netdev ) { +static void xsigo_net_notify ( struct net_device *netdev, + void *priv __unused ) { struct xsigo_device *xdev; struct ib_device *ibdev; struct xsigo_manager *xcm; diff --git a/src/net/ipv6.c b/src/net/ipv6.c index ef5e51daa..a0173dfb1 100644 --- a/src/net/ipv6.c +++ b/src/net/ipv6.c @@ -1224,9 +1224,11 @@ struct ipv6_settings { * Register IPv6 link-local address settings * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int ipv6_register_settings ( struct net_device *netdev ) { +static int ipv6_register_settings ( struct net_device *netdev, + void *priv __unused ) { struct settings *parent = netdev_settings ( netdev ); struct ipv6_settings *ipv6set; int rc; diff --git a/src/net/lldp.c b/src/net/lldp.c index 72e3ecdf6..2ef32cb0c 100644 --- a/src/net/lldp.c +++ b/src/net/lldp.c @@ -296,9 +296,10 @@ struct net_protocol lldp_protocol __net_protocol = { * Create LLDP settings block * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int lldp_probe ( struct net_device *netdev ) { +static int lldp_probe ( struct net_device *netdev, void *priv __unused ) { struct lldp_settings *lldpset; int rc; diff --git a/src/net/neighbour.c b/src/net/neighbour.c index 7f66d9992..13a8bc3ba 100644 --- a/src/net/neighbour.c +++ b/src/net/neighbour.c @@ -383,8 +383,9 @@ int neighbour_define ( struct net_device *netdev, * Update neighbour cache on network device state change or removal * * @v netdev Network device + * @v priv Private data */ -static void neighbour_flush ( struct net_device *netdev ) { +static void neighbour_flush ( struct net_device *netdev, void *priv __unused ) { struct neighbour *neighbour; struct neighbour *tmp; diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 915178218..a9ed18134 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -109,6 +109,51 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) { return 0; } +/** + * Get offset of network device driver private data + * + * @v driver Upper-layer driver, or NULL for device driver + * @ret offset Offset of driver private data + */ +static size_t netdev_priv_offset ( struct net_driver *driver ) { + struct net_device *netdev; + unsigned int num_configs; + size_t offset; + + /* Allow space for network device */ + offset = sizeof ( *netdev ); + + /* Allow space for configurations */ + num_configs = table_num_entries ( NET_DEVICE_CONFIGURATORS ); + offset += ( num_configs * sizeof ( netdev->configs[0] ) ); + + /* Place variable-length device driver private data at end */ + if ( ! driver ) + driver = table_end ( NET_DRIVERS ); + + /* Allow space for preceding upper-layer drivers' private data */ + for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) { + offset += driver->priv_len; + } + + /* Sanity check */ + assert ( ( offset & ( sizeof ( void * ) - 1 ) ) == 0 ); + + return offset; +} + +/** + * Get network device driver private data + * + * @v netdev Network device + * @v driver Upper-layer driver, or NULL for device driver + * @ret priv Driver private data + */ +void * netdev_priv ( struct net_device *netdev, struct net_driver *driver ) { + + return ( ( ( void * ) netdev ) + netdev_priv_offset ( driver ) ); +} + /** * Notify drivers of network device or link state change * @@ -116,10 +161,12 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) { */ static void netdev_notify ( struct net_device *netdev ) { struct net_driver *driver; + void *priv; for_each_table_entry ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->notify ) - driver->notify ( netdev ); + driver->notify ( netdev, priv ); } } @@ -675,14 +722,8 @@ struct net_device * alloc_netdev ( size_t priv_len ) { struct net_device *netdev; struct net_device_configurator *configurator; struct net_device_configuration *config; - unsigned int num_configs; - size_t confs_len; - size_t total_len; - num_configs = table_num_entries ( NET_DEVICE_CONFIGURATORS ); - confs_len = ( num_configs * sizeof ( netdev->configs[0] ) ); - total_len = ( sizeof ( *netdev ) + confs_len + priv_len ); - netdev = zalloc ( total_len ); + netdev = zalloc ( netdev_priv_offset ( NULL ) + priv_len ); if ( netdev ) { ref_init ( &netdev->refcnt, free_netdev ); netdev->link_rc = -EUNKNOWN_LINK_STATUS; @@ -701,8 +742,7 @@ struct net_device * alloc_netdev ( size_t priv_len ) { &netdev->refcnt ); config++; } - netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) + - confs_len ); + netdev->priv = netdev_priv ( netdev, NULL ); } return netdev; } @@ -722,6 +762,7 @@ int register_netdev ( struct net_device *netdev ) { struct net_device *duplicate; unsigned int i; uint32_t seed; + void *priv; int rc; /* Set initial link-layer address, if not already set */ @@ -784,7 +825,9 @@ int register_netdev ( struct net_device *netdev ) { /* Probe device */ for_each_table_entry ( driver, NET_DRIVERS ) { - if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) { + priv = netdev_priv ( netdev, driver ); + if ( driver->probe && + ( rc = driver->probe ( netdev, priv ) ) != 0 ) { DBGC ( netdev, "NETDEV %s could not add %s device: " "%s\n", netdev->name, driver->name, strerror ( rc ) ); @@ -796,8 +839,9 @@ int register_netdev ( struct net_device *netdev ) { err_probe: for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->remove ) - driver->remove ( netdev ); + driver->remove ( netdev, priv ); } clear_settings ( netdev_settings ( netdev ) ); unregister_settings ( netdev_settings ( netdev ) ); @@ -896,14 +940,16 @@ void netdev_close ( struct net_device *netdev ) { */ void unregister_netdev ( struct net_device *netdev ) { struct net_driver *driver; + void *priv; /* Ensure device is closed */ netdev_close ( netdev ); /* Remove device */ for_each_table_entry_reverse ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->remove ) - driver->remove ( netdev ); + driver->remove ( netdev, priv ); } /* Unregister per-netdev configuration settings */ diff --git a/src/net/vlan.c b/src/net/vlan.c index d73a95711..c61bb850e 100644 --- a/src/net/vlan.c +++ b/src/net/vlan.c @@ -470,9 +470,10 @@ void vlan_auto ( const void *ll_addr, unsigned int tag ) { * Create automatic VLAN device * * @v trunk Trunk network device + * @v priv Private data * @ret rc Return status code */ -static int vlan_probe ( struct net_device *trunk ) { +static int vlan_probe ( struct net_device *trunk, void *priv __unused ) { int rc; /* Do nothing unless an automatic VLAN exists */ @@ -498,8 +499,9 @@ static int vlan_probe ( struct net_device *trunk ) { * Handle trunk network device link state change * * @v trunk Trunk network device + * @v priv Private data */ -static void vlan_notify ( struct net_device *trunk ) { +static void vlan_notify ( struct net_device *trunk, void *priv __unused ) { struct net_device *netdev; struct vlan_device *vlan; @@ -538,8 +540,9 @@ static int vlan_remove_first ( struct net_device *trunk ) { * Destroy all VLAN devices for a given trunk * * @v trunk Trunk network device + * @v priv Private data */ -static void vlan_remove ( struct net_device *trunk ) { +static void vlan_remove ( struct net_device *trunk, void *priv __unused ) { /* Remove all VLAN devices attached to this trunk, safe * against arbitrary net device removal. -- cgit v1.2.3-55-g7522 From 8cbf248198f3bc66c52b2340b4decf293af8af47 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 13 Sep 2023 22:43:24 +0100 Subject: [vmware] Use driver-private data to hold GuestInfo settings block Simplify the per-netdevice GuestInfo settings code by using driver-private data to hold the settings block, instead of using a separate allocation. The settings block (if existent) will be automatically unregistered when the parent network device settings block is unregistered, and no longer needs to be separately freed. The guestinfo_net_remove() function may therefore be omitted completely. Signed-off-by: Michael Brown --- src/arch/x86/interface/vmware/guestinfo.c | 48 +++++-------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) (limited to 'src/arch/x86/interface') diff --git a/src/arch/x86/interface/vmware/guestinfo.c b/src/arch/x86/interface/vmware/guestinfo.c index b52c2e87b..4134515c1 100644 --- a/src/arch/x86/interface/vmware/guestinfo.c +++ b/src/arch/x86/interface/vmware/guestinfo.c @@ -210,66 +210,32 @@ struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL ) = { * @v priv Private data * @ret rc Return status code */ -static int guestinfo_net_probe ( struct net_device *netdev, - void *priv __unused ) { - struct settings *settings; +static int guestinfo_net_probe ( struct net_device *netdev, void *priv ) { + struct settings *settings = priv; int rc; /* Do nothing unless we have a GuestInfo channel available */ if ( guestinfo_channel < 0 ) return 0; - /* Allocate and initialise settings block */ - settings = zalloc ( sizeof ( *settings ) ); - if ( ! settings ) { - rc = -ENOMEM; - goto err_alloc; - } - settings_init ( settings, &guestinfo_settings_operations, NULL, NULL ); - - /* Register settings */ + /* Initialise and register settings */ + settings_init ( settings, &guestinfo_settings_operations, + &netdev->refcnt, NULL ); if ( ( rc = register_settings ( settings, netdev_settings ( netdev ), "vmware" ) ) != 0 ) { DBGC ( settings, "GuestInfo %p could not register for %s: %s\n", settings, netdev->name, strerror ( rc ) ); - goto err_register; + return rc; } DBGC ( settings, "GuestInfo %p registered for %s\n", settings, netdev->name ); return 0; - - err_register: - free ( settings ); - err_alloc: - return rc; -} - -/** - * Remove per-netdevice GuestInfo settings - * - * @v netdev Network device - * @v priv Private data - */ -static void guestinfo_net_remove ( struct net_device *netdev, - void *priv __unused ) { - struct settings *parent = netdev_settings ( netdev ); - struct settings *settings; - - list_for_each_entry ( settings, &parent->children, siblings ) { - if ( settings->op == &guestinfo_settings_operations ) { - DBGC ( settings, "GuestInfo %p unregistered for %s\n", - settings, netdev->name ); - unregister_settings ( settings ); - free ( settings ); - return; - } - } } /** GuestInfo per-netdevice driver */ struct net_driver guestinfo_net_driver __net_driver = { .name = "GuestInfo", + .priv_len = sizeof ( struct settings ), .probe = guestinfo_net_probe, - .remove = guestinfo_net_remove, }; -- cgit v1.2.3-55-g7522