Skip to content

Commit 772defc

Browse files
Bjorn Helgaaslenb
authored andcommitted
PNP: change pnp_add_id() to allocate its own pnp_id structures
This moves some of the pnp_id knowledge out of the backends and into the PNP core. Signed-off-by: Bjorn Helgaas <[email protected]> Acked-By: Rene Herman <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 1692b27 commit 772defc

File tree

6 files changed

+36
-48
lines changed

6 files changed

+36
-48
lines changed

drivers/pnp/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern spinlock_t pnp_lock;
22
void *pnp_alloc(long size);
3-
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
3+
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
44
int pnp_interface_attach_device(struct pnp_dev *dev);
55
void pnp_fixup_device(struct pnp_dev *dev);
66
void pnp_free_option(struct pnp_option *option);

drivers/pnp/driver.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,36 @@ void pnp_unregister_driver(struct pnp_driver *drv)
226226

227227
/**
228228
* pnp_add_id - adds an EISA id to the specified device
229-
* @id: pointer to a pnp_id structure
230229
* @dev: pointer to the desired device
230+
* @id: pointer to an EISA id string
231231
*/
232-
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
232+
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id)
233233
{
234-
struct pnp_id *ptr;
234+
struct pnp_id *dev_id, *ptr;
235235

236-
id->next = NULL;
236+
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
237+
if (!dev_id)
238+
return NULL;
239+
240+
dev_id->id[0] = id[0];
241+
dev_id->id[1] = id[1];
242+
dev_id->id[2] = id[2];
243+
dev_id->id[3] = tolower(id[3]);
244+
dev_id->id[4] = tolower(id[4]);
245+
dev_id->id[5] = tolower(id[5]);
246+
dev_id->id[6] = tolower(id[6]);
247+
dev_id->id[7] = '\0';
248+
249+
dev_id->next = NULL;
237250
ptr = dev->id;
238251
while (ptr && ptr->next)
239252
ptr = ptr->next;
240253
if (ptr)
241-
ptr->next = id;
254+
ptr->next = dev_id;
242255
else
243-
dev->id = id;
244-
return 0;
256+
dev->id = dev_id;
257+
258+
return dev_id;
245259
}
246260

247261
EXPORT_SYMBOL(pnp_register_driver);

drivers/pnp/isapnp/core.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include <linux/mutex.h>
4545
#include <asm/io.h>
4646

47+
#include "../base.h"
48+
4749
#if 0
4850
#define ISAPNP_REGION_OK
4951
#endif
@@ -401,20 +403,16 @@ static void __init isapnp_skip_bytes(int count)
401403
static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
402404
unsigned short device)
403405
{
404-
struct pnp_id *id;
406+
char id[8];
405407

406-
if (!dev)
407-
return;
408-
id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
409-
if (!id)
410-
return;
411-
sprintf(id->id, "%c%c%c%x%x%x%x",
408+
sprintf(id, "%c%c%c%x%x%x%x",
412409
'A' + ((vendor >> 2) & 0x3f) - 1,
413410
'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
414411
'A' + ((vendor >> 8) & 0x1f) - 1,
415412
(device >> 4) & 0x0f,
416413
device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
417-
pnp_add_id(id, dev);
414+
415+
pnp_add_id(dev, id);
418416
}
419417

420418
/*

drivers/pnp/pnpacpi/core.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ static int __init ispnpidacpi(char *id)
7373
return 1;
7474
}
7575

76-
static void __init pnpidacpi_to_pnpid(char *id, char *str)
77-
{
78-
str[0] = id[0];
79-
str[1] = id[1];
80-
str[2] = id[2];
81-
str[3] = tolower(id[3]);
82-
str[4] = tolower(id[4]);
83-
str[5] = tolower(id[5]);
84-
str[6] = tolower(id[6]);
85-
str[7] = '\0';
86-
}
87-
8876
static int pnpacpi_get_resources(struct pnp_dev *dev,
8977
struct pnp_resource_table *res)
9078
{
@@ -201,12 +189,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
201189

202190
dev->number = num;
203191

204-
/* set the initial values for the PnP device */
205-
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
192+
dev_id = pnp_add_id(dev, acpi_device_hid(device));
206193
if (!dev_id)
207194
goto err;
208-
pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
209-
pnp_add_id(dev_id, dev);
210195

211196
if (dev->active) {
212197
/* parse allocated resource */
@@ -227,20 +212,14 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
227212
}
228213
}
229214

230-
/* parse compatible ids */
231215
if (device->flags.compatible_ids) {
232216
struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
233217
int i;
234218

235219
for (i = 0; i < cid_list->count; i++) {
236220
if (!ispnpidacpi(cid_list->id[i].value))
237221
continue;
238-
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
239-
if (!dev_id)
240-
continue;
241-
242-
pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
243-
pnp_add_id(dev_id, dev);
222+
pnp_add_id(dev, cid_list->id[i].value);
244223
}
245224
}
246225

drivers/pnp/pnpbios/core.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,14 @@ static int __init insert_device(struct pnp_bios_node *node)
332332
if (!dev)
333333
return -1;
334334

335-
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
335+
pnpid32_to_pnpid(node->eisa_id, id);
336+
dev_id = pnp_add_id(dev, id);
336337
if (!dev_id) {
337338
kfree(dev);
338339
return -1;
339340
}
340341

341342
dev->number = node->handle;
342-
pnpid32_to_pnpid(node->eisa_id, id);
343-
memcpy(dev_id->id, id, 7);
344-
pnp_add_id(dev_id, dev);
345343
pnpbios_parse_data_stream(dev, node);
346344
dev->active = pnp_is_active(dev);
347345
dev->flags = node->flags;

drivers/pnp/pnpbios/rsparser.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
1616
}
1717
#endif /* CONFIG_PCI */
1818

19+
#include "../base.h"
1920
#include "pnpbios.h"
2021

2122
/* standard resource tags */
@@ -548,13 +549,11 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
548549
case SMALL_TAG_COMPATDEVID: /* compatible ID */
549550
if (len != 4)
550551
goto len_err;
551-
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
552-
if (!dev_id)
553-
return NULL;
554552
pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
555553
24, id);
556-
memcpy(&dev_id->id, id, 7);
557-
pnp_add_id(dev_id, dev);
554+
dev_id = pnp_add_id(dev, id);
555+
if (!dev_id)
556+
return NULL;
558557
break;
559558

560559
case SMALL_TAG_END:

0 commit comments

Comments
 (0)