From 67b45186a572fb051e73fd88d4fc580a0d4d2f6b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 1 Dec 2010 16:34:23 +0000 Subject: [PATCH] [settings] Apply settings block name in register_settings() Pass the settings block name as a parameter to register_settings(), rather than defining it with settings_init() (and then possibly changing it by directly manipulating settings->name). Signed-off-by: Michael Brown --- src/core/nvo.c | 5 ++--- src/core/settings.c | 11 ++++++++--- src/drivers/net/phantom/phantom.c | 4 ++-- src/include/ipxe/netdevice.h | 3 +-- src/include/ipxe/settings.h | 11 +++-------- src/interface/smbios/smbios_settings.c | 4 ++-- src/net/cachedhcp.c | 3 ++- src/net/dhcppkt.c | 3 +-- src/net/netdevice.c | 2 +- src/net/udp/dhcp.c | 16 ++++++++-------- 10 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/core/nvo.c b/src/core/nvo.c index 00f2d9ff..1a886c0f 100644 --- a/src/core/nvo.c +++ b/src/core/nvo.c @@ -204,8 +204,7 @@ void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs, struct nvo_fragment *fragments, struct refcnt *refcnt ) { nvo->nvs = nvs; nvo->fragments = fragments; - settings_init ( &nvo->settings, &nvo_settings_operations, refcnt, - "nvo", 0 ); + settings_init ( &nvo->settings, &nvo_settings_operations, refcnt, 0 ); } /** @@ -250,7 +249,7 @@ int register_nvo ( struct nvo_block *nvo, struct settings *parent ) { /* Verify and register options */ nvo_init_dhcpopts ( nvo ); - if ( ( rc = register_settings ( &nvo->settings, parent ) ) != 0 ) + if ( ( rc = register_settings ( &nvo->settings, parent, "nvo" ) ) != 0 ) goto err_register; DBGC ( nvo, "NVO %p registered\n", nvo ); diff --git a/src/core/settings.c b/src/core/settings.c index 8a3660ef..816ae141 100644 --- a/src/core/settings.c +++ b/src/core/settings.c @@ -281,9 +281,9 @@ static struct settings * autovivify_child_settings ( struct settings *parent, return NULL; } memcpy ( new_child->name, name, sizeof ( new_child->name ) ); - generic_settings_init ( &new_child->generic, NULL, new_child->name ); + generic_settings_init ( &new_child->generic, NULL ); settings = &new_child->generic.settings; - register_settings ( settings, parent ); + register_settings ( settings, parent, new_child->name ); return settings; } @@ -422,9 +422,11 @@ static void reprioritise_settings ( struct settings *settings ) { * * @v settings Settings block * @v parent Parent settings block, or NULL + * @v name Settings block name * @ret rc Return status code */ -int register_settings ( struct settings *settings, struct settings *parent ) { +int register_settings ( struct settings *settings, struct settings *parent, + const char *name ) { struct settings *old_settings; /* NULL parent => add to settings root */ @@ -432,6 +434,9 @@ int register_settings ( struct settings *settings, struct settings *parent ) { if ( parent == NULL ) parent = &settings_root; + /* Apply settings block name */ + settings->name = name; + /* Remove any existing settings with the same name */ if ( ( old_settings = find_child_settings ( parent, settings->name ) )) unregister_settings ( old_settings ); diff --git a/src/drivers/net/phantom/phantom.c b/src/drivers/net/phantom/phantom.c index 665bbb02..f6b2f006 100644 --- a/src/drivers/net/phantom/phantom.c +++ b/src/drivers/net/phantom/phantom.c @@ -2061,7 +2061,7 @@ static int phantom_probe ( struct pci_device *pci, assert ( phantom->port < PHN_MAX_NUM_PORTS ); settings_init ( &phantom->settings, &phantom_settings_operations, - &netdev->refcnt, "clp", PHN_CLP_TAG_MAGIC ); + &netdev->refcnt, PHN_CLP_TAG_MAGIC ); /* Fix up PCI device */ adjust_pci_device ( pci ); @@ -2111,7 +2111,7 @@ static int phantom_probe ( struct pci_device *pci, /* Register settings blocks */ parent_settings = netdev_settings ( netdev ); if ( ( rc = register_settings ( &phantom->settings, - parent_settings ) ) != 0 ) { + parent_settings, "clp" ) ) != 0 ) { DBGC ( phantom, "Phantom %p could not register settings: " "%s\n", phantom, strerror ( rc ) ); goto err_register_settings; diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h index 6986233e..a7852a81 100644 --- a/src/include/ipxe/netdevice.h +++ b/src/include/ipxe/netdevice.h @@ -489,8 +489,7 @@ netdev_settings ( struct net_device *netdev ) { */ static inline __attribute__ (( always_inline )) void netdev_settings_init ( struct net_device *netdev ) { - generic_settings_init ( &netdev->settings, - &netdev->refcnt, netdev->name ); + generic_settings_init ( &netdev->settings, &netdev->refcnt ); netdev->settings.settings.op = &netdev_settings_operations; } diff --git a/src/include/ipxe/settings.h b/src/include/ipxe/settings.h index 3bf3da6b..db20be5e 100644 --- a/src/include/ipxe/settings.h +++ b/src/include/ipxe/settings.h @@ -178,7 +178,7 @@ extern int generic_settings_fetch ( struct settings *settings, extern void generic_settings_clear ( struct settings *settings ); extern int register_settings ( struct settings *settings, - struct settings *parent ); + struct settings *parent, const char *name ); extern void unregister_settings ( struct settings *settings ); extern int store_setting ( struct settings *settings, struct setting *setting, @@ -252,19 +252,16 @@ extern struct setting user_class_setting __setting; * @v settings Settings block * @v op Settings block operations * @v refcnt Containing object reference counter, or NULL - * @v name Settings block name * @v tag_magic Tag magic */ static inline void settings_init ( struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, - const char *name, unsigned int tag_magic ) { INIT_LIST_HEAD ( &settings->siblings ); INIT_LIST_HEAD ( &settings->children ); settings->op = op; settings->refcnt = refcnt; - settings->name = name; settings->tag_magic = tag_magic; } @@ -273,13 +270,11 @@ static inline void settings_init ( struct settings *settings, * * @v generics Generic settings block * @v refcnt Containing object reference counter, or NULL - * @v name Settings block name */ static inline void generic_settings_init ( struct generic_settings *generics, - struct refcnt *refcnt, - const char *name ) { + struct refcnt *refcnt ) { settings_init ( &generics->settings, &generic_settings_operations, - refcnt, name, 0 ); + refcnt, 0 ); INIT_LIST_HEAD ( &generics->list ); } diff --git a/src/interface/smbios/smbios_settings.c b/src/interface/smbios/smbios_settings.c index 09e1a578..bb7c18dd 100644 --- a/src/interface/smbios/smbios_settings.c +++ b/src/interface/smbios/smbios_settings.c @@ -125,7 +125,6 @@ static struct settings_operations smbios_settings_operations = { /** SMBIOS settings */ static struct settings smbios_settings = { .refcnt = NULL, - .name = "smbios", .tag_magic = SMBIOS_EMPTY_TAG, .siblings = LIST_HEAD_INIT ( smbios_settings.siblings ), .children = LIST_HEAD_INIT ( smbios_settings.children ), @@ -136,7 +135,8 @@ static struct settings smbios_settings = { static void smbios_init ( void ) { int rc; - if ( ( rc = register_settings ( &smbios_settings, NULL ) ) != 0 ) { + if ( ( rc = register_settings ( &smbios_settings, NULL, + "smbios" ) ) != 0 ) { DBG ( "SMBIOS could not register settings: %s\n", strerror ( rc ) ); return; diff --git a/src/net/cachedhcp.c b/src/net/cachedhcp.c index 299b164c..294624c8 100644 --- a/src/net/cachedhcp.c +++ b/src/net/cachedhcp.c @@ -66,7 +66,8 @@ void store_cached_dhcpack ( userptr_t data, size_t len ) { * device, which is usually what we want. */ parent = netdev_settings ( last_opened_netdev() ); - if ( ( rc = register_settings ( &dhcppkt->settings, parent ) ) != 0 ) + if ( ( rc = register_settings ( &dhcppkt->settings, parent, + DHCP_SETTINGS_NAME ) ) != 0 ) DBG ( "DHCP could not register cached settings: %s\n", strerror ( rc ) ); diff --git a/src/net/dhcppkt.c b/src/net/dhcppkt.c index b2a33363..b68f4e08 100644 --- a/src/net/dhcppkt.c +++ b/src/net/dhcppkt.c @@ -279,6 +279,5 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data, dhcppkt->len = ( offsetof ( struct dhcphdr, options ) + dhcppkt->options.len ); settings_init ( &dhcppkt->settings, - &dhcppkt_settings_operations, &dhcppkt->refcnt, - DHCP_SETTINGS_NAME, 0 ); + &dhcppkt_settings_operations, &dhcppkt->refcnt, 0 ); } diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 37887073..c7e907ad 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -422,7 +422,7 @@ int register_netdev ( struct net_device *netdev ) { /* Register per-netdev configuration settings */ if ( ( rc = register_settings ( netdev_settings ( netdev ), - NULL ) ) != 0 ) { + NULL, netdev->name ) ) != 0 ) { DBGC ( netdev, "NETDEV %s could not register settings: %s\n", netdev->name, strerror ( rc ) ); goto err_register_settings; diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index 443ae3aa..0524385a 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -553,7 +553,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp, /* Register settings */ parent = netdev_settings ( dhcp->netdev ); settings = &dhcppkt->settings; - if ( ( rc = register_settings ( settings, parent ) ) != 0 ) { + if ( ( rc = register_settings ( settings, parent, + DHCP_SETTINGS_NAME ) ) != 0 ) { DBGC ( dhcp, "DHCP %p could not register settings: %s\n", dhcp, strerror ( rc ) ); dhcp_finished ( dhcp, rc ); @@ -568,9 +569,8 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp, * without performing a ProxyDHCPREQUEST */ settings = &dhcp->proxy_offer->settings; - settings->name = PROXYDHCP_SETTINGS_NAME; - if ( ( rc = register_settings ( settings, - NULL ) ) != 0 ) { + if ( ( rc = register_settings ( settings, NULL, + PROXYDHCP_SETTINGS_NAME ) ) != 0 ) { DBGC ( dhcp, "DHCP %p could not register " "proxy settings: %s\n", dhcp, strerror ( rc ) ); @@ -670,8 +670,8 @@ static void dhcp_proxy_rx ( struct dhcp_session *dhcp, return; /* Register settings */ - settings->name = PROXYDHCP_SETTINGS_NAME; - if ( ( rc = register_settings ( settings, NULL ) ) != 0 ) { + if ( ( rc = register_settings ( settings, NULL, + PROXYDHCP_SETTINGS_NAME ) ) != 0 ) { DBGC ( dhcp, "DHCP %p could not register proxy settings: %s\n", dhcp, strerror ( rc ) ); dhcp_finished ( dhcp, rc ); @@ -809,8 +809,8 @@ static void dhcp_pxebs_rx ( struct dhcp_session *dhcp, return; /* Register settings */ - dhcppkt->settings.name = PXEBS_SETTINGS_NAME; - if ( ( rc = register_settings ( &dhcppkt->settings, NULL ) ) != 0 ) { + if ( ( rc = register_settings ( &dhcppkt->settings, NULL, + PXEBS_SETTINGS_NAME ) ) != 0 ) { DBGC ( dhcp, "DHCP %p could not register settings: %s\n", dhcp, strerror ( rc ) ); dhcp_finished ( dhcp, rc );