From f5fd4dec3bab362a2ff7844859914e1f191fb905 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Mar 2011 16:56:35 +0000 Subject: [settings] Formalise notion of setting applicability Expose a function setting_applies() to allow a caller to determine whether or not a particular setting is applicable to a particular settings block. Restrict DHCP-backed settings blocks to accepting only DHCP-based settings. Restrict network device settings blocks to accepting only DHCP-based settings and network device-specific settings such as "mac". Inspired-by: Glenn Brown Signed-off-by: Michael Brown --- src/interface/smbios/smbios_settings.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/interface/smbios') diff --git a/src/interface/smbios/smbios_settings.c b/src/interface/smbios/smbios_settings.c index bb7c18dd8..6594c94b6 100644 --- a/src/interface/smbios/smbios_settings.c +++ b/src/interface/smbios/smbios_settings.c @@ -63,6 +63,22 @@ FILE_LICENCE ( GPL2_OR_LATER ); ( (_type) << 16 ) | \ ( offsetof ( _structure, _field ) << 8 ) ) +/** + * Check applicability of SMBIOS setting + * + * @v settings Settings block + * @v setting Setting + * @ret applies Setting applies within this settings block + */ +static int smbios_applies ( struct settings *settings __unused, + struct setting *setting ) { + unsigned int tag_magic; + + /* Check tag magic */ + tag_magic = ( setting->tag >> 24 ); + return ( tag_magic == SMBIOS_TAG_MAGIC ); +} + /** * Fetch value of SMBIOS setting * @@ -87,8 +103,7 @@ static int smbios_fetch ( struct settings *settings __unused, tag_type = ( ( setting->tag >> 16 ) & 0xff ); tag_offset = ( ( setting->tag >> 8 ) & 0xff ); tag_len = ( setting->tag & 0xff ); - if ( tag_magic != SMBIOS_TAG_MAGIC ) - return -ENOENT; + assert ( tag_magic == SMBIOS_TAG_MAGIC ); /* Find SMBIOS structure */ if ( ( rc = find_smbios_structure ( tag_type, &structure ) ) != 0 ) @@ -119,6 +134,7 @@ static int smbios_fetch ( struct settings *settings __unused, /** SMBIOS settings operations */ static struct settings_operations smbios_settings_operations = { + .applies = smbios_applies, .fetch = smbios_fetch, }; -- cgit v1.2.3-55-g7522