drivers/firmware/google/vpd.c
Source file repositories/reference/linux-study-clean/drivers/firmware/google/vpd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/google/vpd.c- Extension
.c- Size
- 7079 bytes
- Lines
- 329
- Domain
- Driver Families
- Bucket
- drivers/firmware
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ctype.hlinux/init.hlinux/io.hlinux/kernel.hlinux/kobject.hlinux/list.hlinux/mod_devicetable.hlinux/module.hlinux/of_address.hlinux/platform_device.hlinux/slab.hlinux/sysfs.hcoreboot_table.hvpd_decode.h
Detected Declarations
struct vpd_cbmemstruct vpd_sectionstruct vpd_attrib_infofunction vpd_attrib_readfunction vpd_section_check_key_namefunction vpd_section_attrib_addfunction vpd_section_attrib_destroyfunction list_for_each_entry_safefunction vpd_section_readfunction vpd_section_create_attribsfunction vpd_section_initfunction vpd_section_destroyfunction vpd_sections_initfunction vpd_probefunction vpd_remove
Annotated Snippet
struct vpd_cbmem {
u32 magic;
u32 version;
u32 ro_size;
u32 rw_size;
u8 blob[];
};
struct vpd_section {
bool enabled;
const char *name;
char *raw_name; /* the string name_raw */
struct kobject *kobj; /* vpd/name directory */
char *baseaddr;
struct bin_attribute bin_attr; /* vpd/name_raw bin_attribute */
struct list_head attribs; /* key/value in vpd_attrib_info list */
};
struct vpd_attrib_info {
char *key;
const char *value;
struct bin_attribute bin_attr;
struct list_head list;
};
static struct vpd_section ro_vpd;
static struct vpd_section rw_vpd;
static ssize_t vpd_attrib_read(struct file *filp, struct kobject *kobp,
const struct bin_attribute *bin_attr, char *buf,
loff_t pos, size_t count)
{
struct vpd_attrib_info *info = bin_attr->private;
return memory_read_from_buffer(buf, count, &pos, info->value,
info->bin_attr.size);
}
/*
* vpd_section_check_key_name()
*
* The VPD specification supports only [a-zA-Z0-9_]+ characters in key names but
* old firmware versions may have entries like "S/N" which are problematic when
* exporting them as sysfs attributes. These keys present in old firmwares are
* ignored.
*
* Returns VPD_OK for a valid key name, VPD_FAIL otherwise.
*
* @key: The key name to check
* @key_len: key name length
*/
static int vpd_section_check_key_name(const u8 *key, s32 key_len)
{
int c;
while (key_len-- > 0) {
c = *key++;
if (!isalnum(c) && c != '_')
return VPD_FAIL;
}
return VPD_OK;
}
static int vpd_section_attrib_add(const u8 *key, u32 key_len,
const u8 *value, u32 value_len,
void *arg)
{
int ret;
struct vpd_section *sec = arg;
struct vpd_attrib_info *info;
/*
* Return VPD_OK immediately to decode next entry if the current key
* name contains invalid characters.
*/
if (vpd_section_check_key_name(key, key_len) != VPD_OK)
return VPD_OK;
info = kzalloc_obj(*info);
if (!info)
return -ENOMEM;
info->key = kstrndup(key, key_len, GFP_KERNEL);
if (!info->key) {
ret = -ENOMEM;
goto free_info;
}
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/init.h`, `linux/io.h`, `linux/kernel.h`, `linux/kobject.h`, `linux/list.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct vpd_cbmem`, `struct vpd_section`, `struct vpd_attrib_info`, `function vpd_attrib_read`, `function vpd_section_check_key_name`, `function vpd_section_attrib_add`, `function vpd_section_attrib_destroy`, `function list_for_each_entry_safe`, `function vpd_section_read`, `function vpd_section_create_attribs`.
- Atlas domain: Driver Families / drivers/firmware.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.