diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2007-10-17 02:31:11 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-17 11:43:04 -0400 |
commit | 36405e96c8090fc8fc05d56755645a5821c98992 (patch) | |
tree | f42a54834a6200e04483b703c1395cdb2bb109b1 /drivers/pnp | |
parent | b933e19d32edce2f310dfe0fd943e32ff9798b60 (diff) |
PNP: simplify PNPBIOS insert_device
Hoist the struct pnp_dev alloc up into the function where it's used.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Adam Belay <ambx1@neo.rr.com>
Cc: Len Brown <lenb@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/pnp')
-rw-r--r-- | drivers/pnp/pnpbios/core.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index 4e9fd37cff35..e33e03f71084 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c | |||
@@ -315,25 +315,31 @@ struct pnp_protocol pnpbios_protocol = { | |||
315 | .disable = pnpbios_disable_resources, | 315 | .disable = pnpbios_disable_resources, |
316 | }; | 316 | }; |
317 | 317 | ||
318 | static int insert_device(struct pnp_dev *dev, struct pnp_bios_node *node) | 318 | static int insert_device(struct pnp_bios_node *node) |
319 | { | 319 | { |
320 | struct list_head *pos; | 320 | struct list_head *pos; |
321 | struct pnp_dev *pnp_dev; | 321 | struct pnp_dev *dev; |
322 | struct pnp_id *dev_id; | 322 | struct pnp_id *dev_id; |
323 | char id[8]; | 323 | char id[8]; |
324 | 324 | ||
325 | /* check if the device is already added */ | 325 | /* check if the device is already added */ |
326 | dev->number = node->handle; | ||
327 | list_for_each(pos, &pnpbios_protocol.devices) { | 326 | list_for_each(pos, &pnpbios_protocol.devices) { |
328 | pnp_dev = list_entry(pos, struct pnp_dev, protocol_list); | 327 | dev = list_entry(pos, struct pnp_dev, protocol_list); |
329 | if (dev->number == pnp_dev->number) | 328 | if (dev->number == node->handle) |
330 | return -1; | 329 | return -1; |
331 | } | 330 | } |
332 | 331 | ||
333 | /* set the initial values for the PnP device */ | 332 | dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); |
333 | if (!dev) | ||
334 | return -1; | ||
335 | |||
334 | dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); | 336 | dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); |
335 | if (!dev_id) | 337 | if (!dev_id) { |
338 | kfree(dev); | ||
336 | return -1; | 339 | return -1; |
340 | } | ||
341 | |||
342 | dev->number = node->handle; | ||
337 | pnpid32_to_pnpid(node->eisa_id, id); | 343 | pnpid32_to_pnpid(node->eisa_id, id); |
338 | memcpy(dev_id->id, id, 7); | 344 | memcpy(dev_id->id, id, 7); |
339 | pnp_add_id(dev_id, dev); | 345 | pnp_add_id(dev_id, dev); |
@@ -367,7 +373,6 @@ static void __init build_devlist(void) | |||
367 | unsigned int nodes_got = 0; | 373 | unsigned int nodes_got = 0; |
368 | unsigned int devs = 0; | 374 | unsigned int devs = 0; |
369 | struct pnp_bios_node *node; | 375 | struct pnp_bios_node *node; |
370 | struct pnp_dev *dev; | ||
371 | 376 | ||
372 | node = kzalloc(node_info.max_node_size, GFP_KERNEL); | 377 | node = kzalloc(node_info.max_node_size, GFP_KERNEL); |
373 | if (!node) | 378 | if (!node) |
@@ -388,12 +393,7 @@ static void __init build_devlist(void) | |||
388 | break; | 393 | break; |
389 | } | 394 | } |
390 | nodes_got++; | 395 | nodes_got++; |
391 | dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); | 396 | if (insert_device(node) == 0) |
392 | if (!dev) | ||
393 | break; | ||
394 | if (insert_device(dev, node) < 0) | ||
395 | kfree(dev); | ||
396 | else | ||
397 | devs++; | 397 | devs++; |
398 | if (nodenum <= thisnodenum) { | 398 | if (nodenum <= thisnodenum) { |
399 | printk(KERN_ERR | 399 | printk(KERN_ERR |