diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-01-06 18:16:37 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-01-06 18:16:37 -0500 |
commit | d8254e0e72c8cc6131f789f8645338b719f57648 (patch) | |
tree | 0189fc5518d6d0d8fb2c909eefaac92e0a7723bd /drivers/pnp/pnpbios | |
parent | 62c6dae02d4fe2bfa6bc699ae456ff1c50d10bd0 (diff) |
PNPBIOS: check return value of pnp_add_device()
pnp_add_device() may fail so we need to handle errors and avoid leaking
memory.
Also, when pnp_alloc_dev fails, return -ENOMEM rather than -1.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/pnp/pnpbios')
-rw-r--r-- | drivers/pnp/pnpbios/core.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index 9b86a01af631..074569e77d22 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c | |||
@@ -312,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node) | |||
312 | struct list_head *pos; | 312 | struct list_head *pos; |
313 | struct pnp_dev *dev; | 313 | struct pnp_dev *dev; |
314 | char id[8]; | 314 | char id[8]; |
315 | int error; | ||
315 | 316 | ||
316 | /* check if the device is already added */ | 317 | /* check if the device is already added */ |
317 | list_for_each(pos, &pnpbios_protocol.devices) { | 318 | list_for_each(pos, &pnpbios_protocol.devices) { |
318 | dev = list_entry(pos, struct pnp_dev, protocol_list); | 319 | dev = list_entry(pos, struct pnp_dev, protocol_list); |
319 | if (dev->number == node->handle) | 320 | if (dev->number == node->handle) |
320 | return -1; | 321 | return -EEXIST; |
321 | } | 322 | } |
322 | 323 | ||
323 | pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id); | 324 | pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id); |
324 | dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id); | 325 | dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id); |
325 | if (!dev) | 326 | if (!dev) |
326 | return -1; | 327 | return -ENOMEM; |
327 | 328 | ||
328 | pnpbios_parse_data_stream(dev, node); | 329 | pnpbios_parse_data_stream(dev, node); |
329 | dev->active = pnp_is_active(dev); | 330 | dev->active = pnp_is_active(dev); |
@@ -342,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node) | |||
342 | if (!dev->active) | 343 | if (!dev->active) |
343 | pnp_init_resources(dev); | 344 | pnp_init_resources(dev); |
344 | 345 | ||
345 | pnp_add_device(dev); | 346 | error = pnp_add_device(dev); |
347 | if (error) { | ||
348 | put_device(&dev->dev); | ||
349 | return error; | ||
350 | } | ||
351 | |||
346 | pnpbios_interface_attach_device(node); | 352 | pnpbios_interface_attach_device(node); |
347 | 353 | ||
348 | return 0; | 354 | return 0; |