Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firmware/memmap: cleanup

Various cleanup the drivers/firmware/memmap (after review by AKPM):

- fix kdoc to conform to the standard
- move kdoc from header to implementation files
- remove superfluous WARN_ON() after kmalloc()
- WARN_ON(x); if (!x) -> if(!WARN_ON(x))
- improve some comments

Signed-off-by: Bernhard Walle <bwalle@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Bernhard Walle and committed by
Linus Torvalds
31bad924 bdd87354

+43 -44
+43 -18
drivers/firmware/memmap.c
··· 84 84 */ 85 85 86 86 /* 87 - * Firmware memory map entries 87 + * Firmware memory map entries. No locking is needed because the 88 + * firmware_map_add() and firmware_map_add_early() functions are called 89 + * in firmware initialisation code in one single thread of execution. 88 90 */ 89 91 static LIST_HEAD(map_entries); 90 92 91 93 /** 92 - * Common implementation of firmware_map_add() and firmware_map_add_early() 93 - * which expects a pre-allocated struct firmware_map_entry. 94 - * 94 + * firmware_map_add_entry() - Does the real work to add a firmware memmap entry. 95 95 * @start: Start of the memory range. 96 96 * @end: End of the memory range (inclusive). 97 97 * @type: Type of the memory range. 98 98 * @entry: Pre-allocated (either kmalloc() or bootmem allocator), uninitialised 99 99 * entry. 100 - */ 100 + * 101 + * Common implementation of firmware_map_add() and firmware_map_add_early() 102 + * which expects a pre-allocated struct firmware_map_entry. 103 + **/ 101 104 static int firmware_map_add_entry(resource_size_t start, resource_size_t end, 102 105 const char *type, 103 106 struct firmware_map_entry *entry) ··· 118 115 return 0; 119 116 } 120 117 121 - /* 122 - * See <linux/firmware-map.h> for documentation. 123 - */ 118 + /** 119 + * firmware_map_add() - Adds a firmware mapping entry. 120 + * @start: Start of the memory range. 121 + * @end: End of the memory range (inclusive). 122 + * @type: Type of the memory range. 123 + * 124 + * This function uses kmalloc() for memory 125 + * allocation. Use firmware_map_add_early() if you want to use the bootmem 126 + * allocator. 127 + * 128 + * That function must be called before late_initcall. 129 + * 130 + * Returns 0 on success, or -ENOMEM if no memory could be allocated. 131 + **/ 124 132 int firmware_map_add(resource_size_t start, resource_size_t end, 125 133 const char *type) 126 134 { 127 135 struct firmware_map_entry *entry; 128 136 129 137 entry = kmalloc(sizeof(struct firmware_map_entry), GFP_ATOMIC); 130 - WARN_ON(!entry); 131 138 if (!entry) 132 139 return -ENOMEM; 133 140 134 141 return firmware_map_add_entry(start, end, type, entry); 135 142 } 136 143 137 - /* 138 - * See <linux/firmware-map.h> for documentation. 139 - */ 144 + /** 145 + * firmware_map_add_early() - Adds a firmware mapping entry. 146 + * @start: Start of the memory range. 147 + * @end: End of the memory range (inclusive). 148 + * @type: Type of the memory range. 149 + * 150 + * Adds a firmware mapping entry. This function uses the bootmem allocator 151 + * for memory allocation. Use firmware_map_add() if you want to use kmalloc(). 152 + * 153 + * That function must be called before late_initcall. 154 + * 155 + * Returns 0 on success, or -ENOMEM if no memory could be allocated. 156 + **/ 140 157 int __init firmware_map_add_early(resource_size_t start, resource_size_t end, 141 158 const char *type) 142 159 { 143 160 struct firmware_map_entry *entry; 144 161 145 162 entry = alloc_bootmem_low(sizeof(struct firmware_map_entry)); 146 - WARN_ON(!entry); 147 - if (!entry) 163 + if (WARN_ON(!entry)) 148 164 return -ENOMEM; 149 165 150 166 return firmware_map_add_entry(start, end, type, entry); ··· 205 183 /* 206 184 * Initialises stuff and adds the entries in the map_entries list to 207 185 * sysfs. Important is that firmware_map_add() and firmware_map_add_early() 208 - * must be called before late_initcall. 186 + * must be called before late_initcall. That's just because that function 187 + * is called as late_initcall() function, which means that if you call 188 + * firmware_map_add() or firmware_map_add_early() afterwards, the entries 189 + * are not added to sysfs. 209 190 */ 210 191 static int __init memmap_init(void) 211 192 { ··· 217 192 struct kset *memmap_kset; 218 193 219 194 memmap_kset = kset_create_and_add("memmap", NULL, firmware_kobj); 220 - WARN_ON(!memmap_kset); 221 - if (!memmap_kset) 195 + if (WARN_ON(!memmap_kset)) 222 196 return -ENOMEM; 223 197 224 198 list_for_each_entry(entry, &map_entries, list) { 225 199 entry->kobj.kset = memmap_kset; 226 - kobject_add(&entry->kobj, NULL, "%d", i++); 200 + if (kobject_add(&entry->kobj, NULL, "%d", i++)) 201 + kobject_put(&entry->kobj); 227 202 } 228 203 229 204 return 0;
-26
include/linux/firmware-map.h
··· 24 24 */ 25 25 #ifdef CONFIG_FIRMWARE_MEMMAP 26 26 27 - /** 28 - * Adds a firmware mapping entry. This function uses kmalloc() for memory 29 - * allocation. Use firmware_map_add_early() if you want to use the bootmem 30 - * allocator. 31 - * 32 - * That function must be called before late_initcall. 33 - * 34 - * @start: Start of the memory range. 35 - * @end: End of the memory range (inclusive). 36 - * @type: Type of the memory range. 37 - * 38 - * Returns 0 on success, or -ENOMEM if no memory could be allocated. 39 - */ 40 27 int firmware_map_add(resource_size_t start, resource_size_t end, 41 28 const char *type); 42 - 43 - /** 44 - * Adds a firmware mapping entry. This function uses the bootmem allocator 45 - * for memory allocation. Use firmware_map_add() if you want to use kmalloc(). 46 - * 47 - * That function must be called before late_initcall. 48 - * 49 - * @start: Start of the memory range. 50 - * @end: End of the memory range (inclusive). 51 - * @type: Type of the memory range. 52 - * 53 - * Returns 0 on success, or -ENOMEM if no memory could be allocated. 54 - */ 55 29 int firmware_map_add_early(resource_size_t start, resource_size_t end, 56 30 const char *type); 57 31