You need to sign in or sign up before continuing.
提交 d8254e0e 编写于 作者: D Dmitry Torokhov 提交者: Rafael J. Wysocki

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: NDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 62c6dae0
...@@ -312,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node) ...@@ -312,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node)
struct list_head *pos; struct list_head *pos;
struct pnp_dev *dev; struct pnp_dev *dev;
char id[8]; char id[8];
int error;
/* check if the device is already added */ /* check if the device is already added */
list_for_each(pos, &pnpbios_protocol.devices) { list_for_each(pos, &pnpbios_protocol.devices) {
dev = list_entry(pos, struct pnp_dev, protocol_list); dev = list_entry(pos, struct pnp_dev, protocol_list);
if (dev->number == node->handle) if (dev->number == node->handle)
return -1; return -EEXIST;
} }
pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id); pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id); dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
if (!dev) if (!dev)
return -1; return -ENOMEM;
pnpbios_parse_data_stream(dev, node); pnpbios_parse_data_stream(dev, node);
dev->active = pnp_is_active(dev); dev->active = pnp_is_active(dev);
...@@ -342,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node) ...@@ -342,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node)
if (!dev->active) if (!dev->active)
pnp_init_resources(dev); pnp_init_resources(dev);
pnp_add_device(dev); error = pnp_add_device(dev);
if (error) {
put_device(&dev->dev);
return error;
}
pnpbios_interface_attach_device(node); pnpbios_interface_attach_device(node);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册