All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI : dock: add error handling for acpi_bus_get_device
@ 2018-06-12  4:38 ` Zhouyang Jia
  0 siblings, 0 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12  4:38 UTC (permalink / raw)
  Cc: Zhouyang Jia, Rafael J. Wysocki, Len Brown, linux-acpi, linux-kernel

When acpi_bus_get_device fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling acpi_bus_get_device.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/acpi/dock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index e3fc1f0..02fc134 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -504,7 +504,9 @@ static ssize_t show_docked(struct device *dev,
 	struct dock_station *dock_station = dev->platform_data;
 	struct acpi_device *adev = NULL;
 
-	acpi_bus_get_device(dock_station->handle, &adev);
+	if (acpi_bus_get_device(dock_station->handle, &adev))
+		return -ENODEV;
+
 	return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
 }
 static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] ACPI : dock: add error handling for acpi_bus_get_device
@ 2018-06-12  4:38 ` Zhouyang Jia
  0 siblings, 0 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12  4:38 UTC (permalink / raw)
  Cc: Zhouyang Jia, Rafael J. Wysocki, Len Brown, linux-acpi, linux-kernel

When acpi_bus_get_device fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling acpi_bus_get_device.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/acpi/dock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index e3fc1f0..02fc134 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -504,7 +504,9 @@ static ssize_t show_docked(struct device *dev,
 	struct dock_station *dock_station = dev->platform_data;
 	struct acpi_device *adev = NULL;
 
-	acpi_bus_get_device(dock_station->handle, &adev);
+	if (acpi_bus_get_device(dock_station->handle, &adev))
+		return -ENODEV;
+
 	return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
 }
 static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ACPI : dock: add error handling for acpi_bus_get_device
  2018-06-12  4:38 ` Zhouyang Jia
  (?)
@ 2018-06-14  7:54 ` Rafael J. Wysocki
  -1 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2018-06-14  7:54 UTC (permalink / raw)
  To: Zhouyang Jia
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List,
	Linux Kernel Mailing List

On Tue, Jun 12, 2018 at 6:38 AM, Zhouyang Jia <jiazhouyang09@gmail.com> wrote:
> When acpi_bus_get_device fails, the lack of error-handling code may
> cause unexpected results.

It is perfectly predictable in this particular case: adev will be NULL
and acpi_device_enumerated(adev) will return false.

> This patch adds error-handling code after calling acpi_bus_get_device.

Which is not necessary.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-14  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12  4:38 [PATCH] ACPI : dock: add error handling for acpi_bus_get_device Zhouyang Jia
2018-06-12  4:38 ` Zhouyang Jia
2018-06-14  7:54 ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.