aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware')
-rw-r--r--drivers/firmware/dmi_scan.c74
1 files changed, 44 insertions, 30 deletions
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 653265a40b7f..de3027521bfa 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -10,10 +10,9 @@
10 10
11static char dmi_empty_string[] = " "; 11static char dmi_empty_string[] = " ";
12 12
13static char * __init dmi_string(const struct dmi_header *dm, u8 s) 13static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
14{ 14{
15 const u8 *bp = ((u8 *) dm) + dm->length; 15 const u8 *bp = ((u8 *) dm) + dm->length;
16 char *str = "";
17 16
18 if (s) { 17 if (s) {
19 s--; 18 s--;
@@ -28,14 +27,29 @@ static char * __init dmi_string(const struct dmi_header *dm, u8 s)
28 27
29 if (!memcmp(bp, dmi_empty_string, cmp_len)) 28 if (!memcmp(bp, dmi_empty_string, cmp_len))
30 return dmi_empty_string; 29 return dmi_empty_string;
31 str = dmi_alloc(len); 30 return bp;
32 if (str != NULL)
33 strcpy(str, bp);
34 else
35 printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
36 } 31 }
37 } 32 }
38 33
34 return "";
35}
36
37static char * __init dmi_string(const struct dmi_header *dm, u8 s)
38{
39 const char *bp = dmi_string_nosave(dm, s);
40 char *str;
41 size_t len;
42
43 if (bp == dmi_empty_string)
44 return dmi_empty_string;
45
46 len = strlen(bp) + 1;
47 str = dmi_alloc(len);
48 if (str != NULL)
49 strcpy(str, bp);
50 else
51 printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
52
39 return str; 53 return str;
40} 54}
41 55
@@ -167,10 +181,30 @@ static void __init dmi_save_type(const struct dmi_header *dm, int slot, int inde
167 dmi_ident[slot] = s; 181 dmi_ident[slot] = s;
168} 182}
169 183
184static void __init dmi_save_one_device(int type, const char *name)
185{
186 struct dmi_device *dev;
187
188 /* No duplicate device */
189 if (dmi_find_device(type, name, NULL))
190 return;
191
192 dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
193 if (!dev) {
194 printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
195 return;
196 }
197
198 dev->type = type;
199 strcpy((char *)(dev + 1), name);
200 dev->name = (char *)(dev + 1);
201 dev->device_data = NULL;
202 list_add(&dev->list, &dmi_devices);
203}
204
170static void __init dmi_save_devices(const struct dmi_header *dm) 205static void __init dmi_save_devices(const struct dmi_header *dm)
171{ 206{
172 int i, count = (dm->length - sizeof(struct dmi_header)) / 2; 207 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
173 struct dmi_device *dev;
174 208
175 for (i = 0; i < count; i++) { 209 for (i = 0; i < count; i++) {
176 const char *d = (char *)(dm + 1) + (i * 2); 210 const char *d = (char *)(dm + 1) + (i * 2);
@@ -179,16 +213,7 @@ static void __init dmi_save_devices(const struct dmi_header *dm)
179 if ((*d & 0x80) == 0) 213 if ((*d & 0x80) == 0)
180 continue; 214 continue;
181 215
182 dev = dmi_alloc(sizeof(*dev)); 216 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
183 if (!dev) {
184 printk(KERN_ERR "dmi_save_devices: out of memory.\n");
185 break;
186 }
187
188 dev->type = *d++ & 0x7f;
189 dev->name = dmi_string(dm, *d);
190 dev->device_data = NULL;
191 list_add(&dev->list, &dmi_devices);
192 } 217 }
193} 218}
194 219
@@ -253,23 +278,12 @@ static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
253static void __init dmi_save_extended_devices(const struct dmi_header *dm) 278static void __init dmi_save_extended_devices(const struct dmi_header *dm)
254{ 279{
255 const u8 *d = (u8*) dm + 5; 280 const u8 *d = (u8*) dm + 5;
256 struct dmi_device *dev;
257 281
258 /* Skip disabled device */ 282 /* Skip disabled device */
259 if ((*d & 0x80) == 0) 283 if ((*d & 0x80) == 0)
260 return; 284 return;
261 285
262 dev = dmi_alloc(sizeof(*dev)); 286 dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
263 if (!dev) {
264 printk(KERN_ERR "dmi_save_extended_devices: out of memory.\n");
265 return;
266 }
267
268 dev->type = *d-- & 0x7f;
269 dev->name = dmi_string(dm, *d);
270 dev->device_data = NULL;
271
272 list_add(&dev->list, &dmi_devices);
273} 287}
274 288
275/* 289/*