Commit 6bf2aab2 authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by Len Brown

PNP: add pnp_alloc_card()

Add pnp_alloc_card() to allocate a struct pnp_card and fill in the
protocol, instance number, and initial PNP ID.  Now it is always
valid to use dev_printk() on any pnp_card pointer.
Signed-off-by: default avatarBjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: default avatarRene Herman <rene.herman@gmail.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 068076d5
...@@ -3,6 +3,7 @@ void *pnp_alloc(long size); ...@@ -3,6 +3,7 @@ void *pnp_alloc(long size);
#define PNP_EISA_ID_MASK 0x7fffffff #define PNP_EISA_ID_MASK 0x7fffffff
void pnp_eisa_id_to_string(u32 id, char *str); void pnp_eisa_id_to_string(u32 id, char *str);
struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid); struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id); struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id); struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
int pnp_interface_attach_device(struct pnp_dev *dev); int pnp_interface_attach_device(struct pnp_dev *dev);
......
...@@ -151,6 +151,31 @@ static void pnp_release_card(struct device *dmdev) ...@@ -151,6 +151,31 @@ static void pnp_release_card(struct device *dmdev)
kfree(card); kfree(card);
} }
struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
{
struct pnp_card *card;
struct pnp_id *dev_id;
card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
if (!card)
return NULL;
card->protocol = protocol;
card->number = id;
card->dev.parent = &card->protocol->dev;
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
card->number);
dev_id = pnp_add_card_id(card, pnpid);
if (!dev_id) {
kfree(card);
return NULL;
}
return card;
}
static ssize_t pnp_show_card_name(struct device *dmdev, static ssize_t pnp_show_card_name(struct device *dmdev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -206,9 +231,6 @@ int pnp_add_card(struct pnp_card *card) ...@@ -206,9 +231,6 @@ int pnp_add_card(struct pnp_card *card)
int error; int error;
struct list_head *pos, *temp; struct list_head *pos, *temp;
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
card->number);
card->dev.parent = &card->protocol->dev;
card->dev.bus = NULL; card->dev.bus = NULL;
card->dev.release = &pnp_release_card; card->dev.release = &pnp_release_card;
error = device_register(&card->dev); error = device_register(&card->dev);
......
...@@ -840,16 +840,14 @@ static int __init isapnp_build_device_list(void) ...@@ -840,16 +840,14 @@ static int __init isapnp_build_device_list(void)
header[5], header[6], header[7], header[8]); header[5], header[6], header[7], header[8]);
printk(KERN_DEBUG "checksum = 0x%x\n", checksum); printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
#endif #endif
if ((card =
kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
continue;
card->number = csn;
INIT_LIST_HEAD(&card->devices);
eisa_id = header[0] | header[1] << 8 | eisa_id = header[0] | header[1] << 8 |
header[2] << 16 | header[3] << 24; header[2] << 16 | header[3] << 24;
pnp_eisa_id_to_string(eisa_id, id); pnp_eisa_id_to_string(eisa_id, id);
pnp_add_card_id(card, id); card = pnp_alloc_card(&isapnp_protocol, csn, id);
if (!card)
continue;
INIT_LIST_HEAD(&card->devices);
card->serial = card->serial =
(header[7] << 24) | (header[6] << 16) | (header[5] << 8) | (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
header[4]; header[4];
...@@ -860,7 +858,6 @@ static int __init isapnp_build_device_list(void) ...@@ -860,7 +858,6 @@ static int __init isapnp_build_device_list(void)
"isapnp: checksum for device %i is not valid (0x%x)\n", "isapnp: checksum for device %i is not valid (0x%x)\n",
csn, isapnp_checksum_value); csn, isapnp_checksum_value);
card->checksum = isapnp_checksum_value; card->checksum = isapnp_checksum_value;
card->protocol = &isapnp_protocol;
pnp_add_card(card); pnp_add_card(card);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment