From 249135d1a2ea3c1719c48d31351413d55d2fdef4 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 15 Dec 2013 04:10:11 -0800 Subject: PNPACPI: check return value of pnp_add_device() pnp_add_device() may fail so we need to handle errors and avoid leaking memory. Also, do not use ACPI-specific return codes (AE_OK) but rather standard one (0). Signed-off-by: Dmitry Torokhov Signed-off-by: Rafael J. Wysocki --- drivers/pnp/pnpacpi/core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'drivers/pnp') diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 14655a0f0431..4bd4c54ad205 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c @@ -242,6 +242,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device) struct pnp_dev *dev; char *pnpid; struct acpi_hardware_id *id; + int error; /* Skip devices that are already bound */ if (device->physical_node_count) @@ -300,10 +301,16 @@ static int __init pnpacpi_add_device(struct acpi_device *device) /* clear out the damaged flags */ if (!dev->active) pnp_init_resources(dev); - pnp_add_device(dev); + + error = pnp_add_device(dev); + if (error) { + put_device(&dev->dev); + return error; + } + num++; - return AE_OK; + return 0; } static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, -- cgit v1.2.3 From 75365d04cd2d6fe04c9c52c69fd97b2d0a6c82ba Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Thu, 19 Dec 2013 16:03:36 +0100 Subject: PNP / card: add missing put_device() call This is required so that we give up the last reference to the device. Signed-off-by: Levente Kurusa Signed-off-by: Rafael J. Wysocki --- drivers/pnp/card.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/pnp') diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c index bc00693d0c79..874c236ac1a7 100644 --- a/drivers/pnp/card.c +++ b/drivers/pnp/card.c @@ -239,6 +239,7 @@ int pnp_add_card(struct pnp_card *card) error = device_register(&card->dev); if (error) { dev_err(&card->dev, "could not register (err=%d)\n", error); + put_device(&card->dev); return error; } -- cgit v1.2.3 From 62c6dae02d4fe2bfa6bc699ae456ff1c50d10bd0 Mon Sep 17 00:00:00 2001 From: Rashika Kheria Date: Sat, 14 Dec 2013 18:50:56 +0530 Subject: PNP: Mark the function pnp_build_option() as static in resource.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch marks the function pnp_build_option() as static in resource.c because it is not used outside this file. Thus, it also eliminates the following warning in resource.c: drivers/pnp/resource.c:34:20: warning: no previous prototype for ‘pnp_build_option’ [-Wmissing-prototypes] Signed-off-by: Rashika Kheria Reviewed-by: Josh Triplett Signed-off-by: Rafael J. Wysocki --- drivers/pnp/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/pnp') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index d95e101ffb43..bacddd102ae9 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -31,7 +31,7 @@ static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some * option registration */ -struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type, +static struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type, unsigned int option_flags) { struct pnp_option *option; -- cgit v1.2.3 From d8254e0e72c8cc6131f789f8645338b719f57648 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 7 Jan 2014 00:16:37 +0100 Subject: 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 Signed-off-by: Rafael J. Wysocki --- drivers/pnp/pnpbios/core.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/pnp') 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) 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; -- cgit v1.2.3