Skip to contentSkip to conversation

PNPBIOS: check return value of pnp_add_device()

PATCH In review Dmitry Torokhov 2 participants 4 messages Dec 15, 2013 – Jan 6, 2014 Pnp support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/pnp/pnpbios/core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/pnp/pnpbios/core.c +9 -3
index 9b86a01..074569e 100644
@@ -312,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node)
 	struct list_head *pos;
 	struct pnp_dev *dev;
 	char id[8];
+	int error;
 
 	/* check if the device is already added */
 	list_for_each(pos, &pnpbios_protocol.devices) {
 		dev = list_entry(pos, struct pnp_dev, protocol_list);
 		if (dev->number == node->handle)
-			return -1;
+			return -EEXIST;
 	}
 
 	pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
 	dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
 	if (!dev)
-		return -1;
+		return -ENOMEM;
 
 	pnpbios_parse_data_stream(dev, node);
 	dev->active = pnp_is_active(dev);
@@ -342,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node)
 	if (!dev->active)
 		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);
 
 	return 0;
Signature · 5 lines
1.8.3.1


-- 
Dmitry
#1 lore raw

Hi Rafael,

Quoted 6 lines · Dmitry Torokhov

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.

Any issues with this patch and a similar one to PNPACPI?

Thanks!

Quoted 50 lines
---
 drivers/pnp/pnpbios/core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/pnp/pnpbios/core.c +9 -3
index 9b86a01..074569e 100644
@@ -312,18 +312,19 @@ static int __init insert_device(struct pnp_bios_node *node)
 	struct list_head *pos;
 	struct pnp_dev *dev;
 	char id[8];
+	int error;
 
 	/* check if the device is already added */
 	list_for_each(pos, &pnpbios_protocol.devices) {
 		dev = list_entry(pos, struct pnp_dev, protocol_list);
 		if (dev->number == node->handle)
-			return -1;
+			return -EEXIST;
 	}
 
 	pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
 	dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
 	if (!dev)
-		return -1;
+		return -ENOMEM;
 
 	pnpbios_parse_data_stream(dev, node);
 	dev->active = pnp_is_active(dev);
@@ -342,7 +343,12 @@ static int __init insert_device(struct pnp_bios_node *node)
 	if (!dev->active)
 		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);
 
 	return 0;
Signature · 5 lines
1.8.3.1


-- 
Dmitry
Signature · 1 line
Dmitry
#2 lore raw

Hi Dmitry,

I've just queued up your patch for 3.14 (the other one has already been in my tree for a while).

Thanks,
Rafael

#3 lore raw
Quoted 4 lines · Rafael J. Wysocki

Hi Dmitry,

I've just queued up your patch for 3.14 (the other one has already been in my tree for a while).

Cool, thanks!

Signature · 1 line
Dmitry