2012-10-24 06:13:10

by Tang Chen

[permalink] [raw]
Subject: [PATCH v3] Fix a hard coding style when determining if a device is a container.

"ACPI0004","PNP0A05" and "PNP0A06" are all defined in array
container_device_ids[], so use it, but not the hard coding style.

Also, introduce a new api is_container_device() to determine if a
device is a container device.

change log v2 -> v3:

1. change the is_container_device()'s return value type from int to bool.

Signed-off-by: Tang Chen <[email protected]>
Signed-off-by: Yasuaki Ishimatsu <[email protected]>
---
drivers/acpi/container.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 1f9f7d7..69e2d6b 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -92,6 +92,19 @@ static int is_device_present(acpi_handle handle)
return ((sta & ACPI_STA_DEVICE_PRESENT) == ACPI_STA_DEVICE_PRESENT);
}

+static bool is_container_device(const char *hid)
+{
+ const struct acpi_device_id *container_id;
+
+ for (container_id = container_device_ids;
+ container_id->id[0]; container_id++) {
+ if (!strcmp((char *)container_id->id, hid))
+ return true;
+ }
+
+ return false;
+}
+
/*******************************************************************/
static int acpi_container_add(struct acpi_device *device)
{
@@ -232,10 +245,8 @@ container_walk_namespace_cb(acpi_handle handle,
goto end;
}

- if (strcmp(hid, "ACPI0004") && strcmp(hid, "PNP0A05") &&
- strcmp(hid, "PNP0A06")) {
+ if (!is_container_device(hid))
goto end;
- }

switch (*action) {
case INSTALL_NOTIFY_HANDLER:
--
1.7.1


2012-10-24 21:04:15

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v3] Fix a hard coding style when determining if a device is a container.

On Wed, Oct 24, 2012 at 12:11 AM, Tang Chen <[email protected]> wrote:
> "ACPI0004","PNP0A05" and "PNP0A06" are all defined in array
> container_device_ids[], so use it, but not the hard coding style.
>
> Also, introduce a new api is_container_device() to determine if a
> device is a container device.
>
> change log v2 -> v3:
>
> 1. change the is_container_device()'s return value type from int to bool.

No need to keep this level of detail in the permanent git changelogs.

> Signed-off-by: Tang Chen <[email protected]>
> Signed-off-by: Yasuaki Ishimatsu <[email protected]>

Reviewed-by: Bjorn Helgaas <[email protected]>

> ---
> drivers/acpi/container.c | 17 ++++++++++++++---
> 1 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
> index 1f9f7d7..69e2d6b 100644
> --- a/drivers/acpi/container.c
> +++ b/drivers/acpi/container.c
> @@ -92,6 +92,19 @@ static int is_device_present(acpi_handle handle)
> return ((sta & ACPI_STA_DEVICE_PRESENT) == ACPI_STA_DEVICE_PRESENT);
> }
>
> +static bool is_container_device(const char *hid)
> +{
> + const struct acpi_device_id *container_id;
> +
> + for (container_id = container_device_ids;
> + container_id->id[0]; container_id++) {
> + if (!strcmp((char *)container_id->id, hid))
> + return true;
> + }
> +
> + return false;
> +}
> +
> /*******************************************************************/
> static int acpi_container_add(struct acpi_device *device)
> {
> @@ -232,10 +245,8 @@ container_walk_namespace_cb(acpi_handle handle,
> goto end;
> }
>
> - if (strcmp(hid, "ACPI0004") && strcmp(hid, "PNP0A05") &&
> - strcmp(hid, "PNP0A06")) {
> + if (!is_container_device(hid))
> goto end;
> - }
>
> switch (*action) {
> case INSTALL_NOTIFY_HANDLER:
> --
> 1.7.1
>