aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-04-28 18:33:58 -0400
committerLen Brown <len.brown@intel.com>2008-04-29 03:22:17 -0400
commit6bf2aab24a5dc26bf8274c4b9dbbed8ca99ae82c (patch)
tree910e6795cf929481cecb00fc5ebad43121beba56
parent068076d5517009654376ceda75ff44af0feb9b1d (diff)
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: Bjorn Helgaas <bjorn.helgaas@hp.com> Acked-By: Rene Herman <rene.herman@gmail.com> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--drivers/pnp/base.h1
-rw-r--r--drivers/pnp/card.c28
-rw-r--r--drivers/pnp/isapnp/core.c13
3 files changed, 31 insertions, 11 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 37f7d85fc4bc..a83cdcfee165 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -3,6 +3,7 @@ void *pnp_alloc(long size);
3#define PNP_EISA_ID_MASK 0x7fffffff 3#define PNP_EISA_ID_MASK 0x7fffffff
4void pnp_eisa_id_to_string(u32 id, char *str); 4void pnp_eisa_id_to_string(u32 id, char *str);
5struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid); 5struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
6struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
6struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id); 7struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
7struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id); 8struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
8int pnp_interface_attach_device(struct pnp_dev *dev); 9int pnp_interface_attach_device(struct pnp_dev *dev);
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index d606a163b1d7..a762a4176736 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -151,6 +151,31 @@ static void pnp_release_card(struct device *dmdev)
151 kfree(card); 151 kfree(card);
152} 152}
153 153
154struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
155{
156 struct pnp_card *card;
157 struct pnp_id *dev_id;
158
159 card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
160 if (!card)
161 return NULL;
162
163 card->protocol = protocol;
164 card->number = id;
165
166 card->dev.parent = &card->protocol->dev;
167 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
168 card->number);
169
170 dev_id = pnp_add_card_id(card, pnpid);
171 if (!dev_id) {
172 kfree(card);
173 return NULL;
174 }
175
176 return card;
177}
178
154static ssize_t pnp_show_card_name(struct device *dmdev, 179static ssize_t pnp_show_card_name(struct device *dmdev,
155 struct device_attribute *attr, char *buf) 180 struct device_attribute *attr, char *buf)
156{ 181{
@@ -206,9 +231,6 @@ int pnp_add_card(struct pnp_card *card)
206 int error; 231 int error;
207 struct list_head *pos, *temp; 232 struct list_head *pos, *temp;
208 233
209 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
210 card->number);
211 card->dev.parent = &card->protocol->dev;
212 card->dev.bus = NULL; 234 card->dev.bus = NULL;
213 card->dev.release = &pnp_release_card; 235 card->dev.release = &pnp_release_card;
214 error = device_register(&card->dev); 236 error = device_register(&card->dev);
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 3a326f9305f6..883577a93d6a 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -840,16 +840,14 @@ static int __init isapnp_build_device_list(void)
840 header[5], header[6], header[7], header[8]); 840 header[5], header[6], header[7], header[8]);
841 printk(KERN_DEBUG "checksum = 0x%x\n", checksum); 841 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
842#endif 842#endif
843 if ((card =
844 kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
845 continue;
846
847 card->number = csn;
848 INIT_LIST_HEAD(&card->devices);
849 eisa_id = header[0] | header[1] << 8 | 843 eisa_id = header[0] | header[1] << 8 |
850 header[2] << 16 | header[3] << 24; 844 header[2] << 16 | header[3] << 24;
851 pnp_eisa_id_to_string(eisa_id, id); 845 pnp_eisa_id_to_string(eisa_id, id);
852 pnp_add_card_id(card, id); 846 card = pnp_alloc_card(&isapnp_protocol, csn, id);
847 if (!card)
848 continue;
849
850 INIT_LIST_HEAD(&card->devices);
853 card->serial = 851 card->serial =
854 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | 852 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
855 header[4]; 853 header[4];
@@ -860,7 +858,6 @@ static int __init isapnp_build_device_list(void)
860 "isapnp: checksum for device %i is not valid (0x%x)\n", 858 "isapnp: checksum for device %i is not valid (0x%x)\n",
861 csn, isapnp_checksum_value); 859 csn, isapnp_checksum_value);
862 card->checksum = isapnp_checksum_value; 860 card->checksum = isapnp_checksum_value;
863 card->protocol = &isapnp_protocol;
864 861
865 pnp_add_card(card); 862 pnp_add_card(card);
866 } 863 }