aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/dmi_scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware/dmi_scan.c')
-rw-r--r--drivers/firmware/dmi_scan.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 653265a40b7f..4072449ad1cd 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,23 +213,10 @@ 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
195static struct dmi_device empty_oem_string_dev = {
196 .name = dmi_empty_string,
197};
198
199static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) 220static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
200{ 221{
201 int i, count = *(u8 *)(dm + 1); 222 int i, count = *(u8 *)(dm + 1);
@@ -204,10 +225,8 @@ static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
204 for (i = 1; i <= count; i++) { 225 for (i = 1; i <= count; i++) {
205 char *devname = dmi_string(dm, i); 226 char *devname = dmi_string(dm, i);
206 227
207 if (!strcmp(devname, dmi_empty_string)) { 228 if (devname == dmi_empty_string)
208 list_add(&empty_oem_string_dev.list, &dmi_devices);
209 continue; 229 continue;
210 }
211 230
212 dev = dmi_alloc(sizeof(*dev)); 231 dev = dmi_alloc(sizeof(*dev));
213 if (!dev) { 232 if (!dev) {
@@ -253,23 +272,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) 272static void __init dmi_save_extended_devices(const struct dmi_header *dm)
254{ 273{
255 const u8 *d = (u8*) dm + 5; 274 const u8 *d = (u8*) dm + 5;
256 struct dmi_device *dev;
257 275
258 /* Skip disabled device */ 276 /* Skip disabled device */
259 if ((*d & 0x80) == 0) 277 if ((*d & 0x80) == 0)
260 return; 278 return;
261 279
262 dev = dmi_alloc(sizeof(*dev)); 280 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} 281}
274 282
275/* 283/*