2013-08-06 00:21:26

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 0/5] ACPI: acpi_bind_one()/acpi_unbind_one() cleanups

Hi All,

The following 5 patches clean up a little mess in acpi_bind_one() and
acpi_unbind_one(). They are on top of current linux-next plus the patch
at https://patchwork.kernel.org/patch/2839101/ .

[1/5] Move duplicated code from acpi_bind_one()/acpi_unbind_one() to a separate
function.
[2/5] Create symlinks in acpi_bind_one() under physical_node_lock.
[3/5] Clean up inconsistent use of whitespace in acpi_bind_one()/acpi_unbind_one().
[4/5] Use list_for_each_entry() to walk the list in acpi_unbind_one().
[5/5] Clean up the error code path in acpi_unbind_one().

Thanks,
Rafael


2013-08-06 00:21:22

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 4/5] ACPI: Use list_for_each_entry() in acpi_unbind_one()

From: Rafael J. Wysocki <[email protected]>

Since acpi_unbind_one() walks physical_node_list under the ACPI
device object's physical_node_lock mutex and the walk may be
terminated as soon as the matching entry has been found, it is
not necessary to use list_for_each_safe() for that walk, so use
list_for_each_entry() instead and make the code slightly more
straightforward.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/glue.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -214,7 +214,6 @@ int acpi_unbind_one(struct device *dev)
struct acpi_device_physical_node *entry;
struct acpi_device *acpi_dev;
acpi_status status;
- struct list_head *node, *next;

if (!ACPI_HANDLE(dev))
return 0;
@@ -224,25 +223,24 @@ int acpi_unbind_one(struct device *dev)
goto err;

mutex_lock(&acpi_dev->physical_node_lock);
- list_for_each_safe(node, next, &acpi_dev->physical_node_list) {
- char physical_node_name[PHYSICAL_NODE_NAME_SIZE];

- entry = list_entry(node, struct acpi_device_physical_node,
- node);
- if (entry->dev != dev)
- continue;
-
- list_del(node);
- acpi_dev->physical_node_count--;
-
- acpi_bind_physnode_name(physical_node_name, entry->node_id);
- sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name);
- sysfs_remove_link(&dev->kobj, "firmware_node");
- ACPI_HANDLE_SET(dev, NULL);
- /* acpi_bind_one increase refcnt by one */
- put_device(dev);
- kfree(entry);
- }
+ list_for_each_entry(entry, &acpi_dev->physical_node_list, node)
+ if (entry->dev == dev) {
+ char physnode_name[PHYSICAL_NODE_NAME_SIZE];
+
+ list_del(&entry->node);
+ acpi_dev->physical_node_count--;
+
+ acpi_bind_physnode_name(physnode_name, entry->node_id);
+ sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
+ sysfs_remove_link(&dev->kobj, "firmware_node");
+ ACPI_HANDLE_SET(dev, NULL);
+ /* acpi_bind_one() increase refcnt by one. */
+ put_device(dev);
+ kfree(entry);
+ break;
+ }
+
mutex_unlock(&acpi_dev->physical_node_lock);

return 0;

2013-08-06 00:21:27

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 1/5] ACPI: Reduce acpi_bind_one()/acpi_unbind_one() code duplication

From: Rafael J. Wysocki <[email protected]>

Move some duplicated code from acpi_bind_one() and acpi_unbind_one()
into a separate function and make that function use snprintf()
instead of sprintf() for extra safety.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/glue.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -108,6 +108,15 @@ acpi_handle acpi_get_child(acpi_handle p
}
EXPORT_SYMBOL(acpi_get_child);

+static void acpi_bind_physnode_name(char *buf, unsigned int node_id)
+{
+ if (node_id > 0)
+ snprintf(buf, PHYSICAL_NODE_NAME_SIZE,
+ PHYSICAL_NODE_STRING "%u", node_id);
+ else
+ strcpy(buf, PHYSICAL_NODE_STRING);
+}
+
int acpi_bind_one(struct device *dev, acpi_handle handle)
{
struct acpi_device *acpi_dev;
@@ -173,11 +182,7 @@ int acpi_bind_one(struct device *dev, ac
if (!ACPI_HANDLE(dev))
ACPI_HANDLE_SET(dev, acpi_dev->handle);

- if (!physical_node->node_id)
- strcpy(physical_node_name, PHYSICAL_NODE_STRING);
- else
- sprintf(physical_node_name,
- "physical_node%d", physical_node->node_id);
+ acpi_bind_physnode_name(physical_node_name, node_id);
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
physical_node_name);
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
@@ -231,12 +236,7 @@ int acpi_unbind_one(struct device *dev)

acpi_dev->physical_node_count--;

- if (!entry->node_id)
- strcpy(physical_node_name, PHYSICAL_NODE_STRING);
- else
- sprintf(physical_node_name,
- "physical_node%d", entry->node_id);
-
+ acpi_bind_physnode_name(physical_node_name, entry->node_id);
sysfs_remove_link(&acpi_dev->dev.kobj, physical_node_name);
sysfs_remove_link(&dev->kobj, "firmware_node");
ACPI_HANDLE_SET(dev, NULL);

2013-08-06 00:21:59

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 2/5] ACPI: Create symlinks in acpi_bind_one() under physical_node_lock

From: Rafael J. Wysocki <[email protected]>

Put the creation of symlinks in acpi_bind_one() under the
physical_node_lock mutex of the given ACPI device objects, because
that is part of the binding operation logically (those links are
already removed under that mutex too).

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/glue.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -177,8 +177,6 @@ int acpi_bind_one(struct device *dev, ac
list_add(&physical_node->node, physnode_list);
acpi_dev->physical_node_count++;

- mutex_unlock(&acpi_dev->physical_node_lock);
-
if (!ACPI_HANDLE(dev))
ACPI_HANDLE_SET(dev, acpi_dev->handle);

@@ -188,6 +186,8 @@ int acpi_bind_one(struct device *dev, ac
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
"firmware_node");

+ mutex_unlock(&acpi_dev->physical_node_lock);
+
if (acpi_dev->wakeup.flags.valid)
device_set_wakeup_capable(dev, true);

2013-08-06 00:21:21

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 5/5] ACPI: Clean up error code path in acpi_unbind_one()

From: Rafael J. Wysocki <[email protected]>

The error code path in acpi_unbind_one() is unnecessarily complicated
(in particular, the err label is not really necessary) and the error
message printed by it is inaccurate (there's nothing called
'acpi_handle' in that function), so clean up those things.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/glue.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -219,8 +219,10 @@ int acpi_unbind_one(struct device *dev)
return 0;

status = acpi_bus_get_device(ACPI_HANDLE(dev), &acpi_dev);
- if (ACPI_FAILURE(status))
- goto err;
+ if (ACPI_FAILURE(status)) {
+ dev_err(dev, "Oops, ACPI handle corrupt in %s()\n", __func__);
+ return -EINVAL;
+ }

mutex_lock(&acpi_dev->physical_node_lock);

@@ -242,12 +244,7 @@ int acpi_unbind_one(struct device *dev)
}

mutex_unlock(&acpi_dev->physical_node_lock);
-
return 0;
-
-err:
- dev_err(dev, "Oops, 'acpi_handle' corrupt\n");
- return -EINVAL;
}
EXPORT_SYMBOL_GPL(acpi_unbind_one);

2013-08-06 00:22:38

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH 3/5] ACPI: acpi_bind_one()/acpi_unbind_one() whitespace cleanups

From: Rafael J. Wysocki <[email protected]>

Clean up some inconsistent use of whitespace in acpi_bind_one() and
acpi_unbind_one().

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/acpi/glue.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -182,9 +182,9 @@ int acpi_bind_one(struct device *dev, ac

acpi_bind_physnode_name(physical_node_name, node_id);
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
- physical_node_name);
+ physical_node_name);
retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
- "firmware_node");
+ "firmware_node");

mutex_unlock(&acpi_dev->physical_node_lock);

@@ -228,12 +228,11 @@ int acpi_unbind_one(struct device *dev)
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];

entry = list_entry(node, struct acpi_device_physical_node,
- node);
+ node);
if (entry->dev != dev)
continue;

list_del(node);
-
acpi_dev->physical_node_count--;

acpi_bind_physnode_name(physical_node_name, entry->node_id);

2013-08-06 21:16:45

by Toshi Kani

[permalink] [raw]
Subject: Re: [PATCH 0/5] ACPI: acpi_bind_one()/acpi_unbind_one() cleanups

On Tue, 2013-08-06 at 02:22 +0200, Rafael J. Wysocki wrote:
> Hi All,
>
> The following 5 patches clean up a little mess in acpi_bind_one() and
> acpi_unbind_one(). They are on top of current linux-next plus the patch
> at https://patchwork.kernel.org/patch/2839101/ .
>
> [1/5] Move duplicated code from acpi_bind_one()/acpi_unbind_one() to a separate
> function.

I think the name of acpi_bind_physnode_name() is a bit confusing as if
it would make some persistent binding. So, I'd suggest to rename it to
acpi_set_physnode_name().

> [2/5] Create symlinks in acpi_bind_one() under physical_node_lock.
> [3/5] Clean up inconsistent use of whitespace in acpi_bind_one()/acpi_unbind_one().
> [4/5] Use list_for_each_entry() to walk the list in acpi_unbind_one().
> [5/5] Clean up the error code path in acpi_unbind_one().

All changes look good. For the series:

Acked-by: Toshi Kani <[email protected]>

Thanks,
-Toshi

2013-08-06 22:19:37

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 0/5] ACPI: acpi_bind_one()/acpi_unbind_one() cleanups

On Tuesday, August 06, 2013 03:15:36 PM Toshi Kani wrote:
> On Tue, 2013-08-06 at 02:22 +0200, Rafael J. Wysocki wrote:
> > Hi All,
> >
> > The following 5 patches clean up a little mess in acpi_bind_one() and
> > acpi_unbind_one(). They are on top of current linux-next plus the patch
> > at https://patchwork.kernel.org/patch/2839101/ .
> >
> > [1/5] Move duplicated code from acpi_bind_one()/acpi_unbind_one() to a separate
> > function.
>
> I think the name of acpi_bind_physnode_name() is a bit confusing as if
> it would make some persistent binding. So, I'd suggest to rename it to
> acpi_set_physnode_name().

In fact, the plan was to make it mean "physical node name for acpi_bind", but
the execution was somewhat sloppy. ;-)

I think I'll call it acpi_physnode_link_name(), that should be clear enough.

> > [2/5] Create symlinks in acpi_bind_one() under physical_node_lock.
> > [3/5] Clean up inconsistent use of whitespace in acpi_bind_one()/acpi_unbind_one().
> > [4/5] Use list_for_each_entry() to walk the list in acpi_unbind_one().
> > [5/5] Clean up the error code path in acpi_unbind_one().
>
> All changes look good. For the series:
>
> Acked-by: Toshi Kani <[email protected]>

Thanks!

Rafael

2013-08-06 22:52:32

by Toshi Kani

[permalink] [raw]
Subject: Re: [PATCH 0/5] ACPI: acpi_bind_one()/acpi_unbind_one() cleanups

On Wed, 2013-08-07 at 00:29 +0200, Rafael J. Wysocki wrote:
> On Tuesday, August 06, 2013 03:15:36 PM Toshi Kani wrote:
> > On Tue, 2013-08-06 at 02:22 +0200, Rafael J. Wysocki wrote:
> > > Hi All,
> > >
> > > The following 5 patches clean up a little mess in acpi_bind_one() and
> > > acpi_unbind_one(). They are on top of current linux-next plus the patch
> > > at https://patchwork.kernel.org/patch/2839101/ .
> > >
> > > [1/5] Move duplicated code from acpi_bind_one()/acpi_unbind_one() to a separate
> > > function.
> >
> > I think the name of acpi_bind_physnode_name() is a bit confusing as if
> > it would make some persistent binding. So, I'd suggest to rename it to
> > acpi_set_physnode_name().
>
> In fact, the plan was to make it mean "physical node name for acpi_bind", but
> the execution was somewhat sloppy. ;-)
>
> I think I'll call it acpi_physnode_link_name(), that should be clear enough.

Sounds good to me.

Thanks,
-Toshi

2013-08-07 05:09:56

by Yasuaki Ishimatsu

[permalink] [raw]
Subject: Re: [PATCH 0/5] ACPI: acpi_bind_one()/acpi_unbind_one() cleanups

(2013/08/06 9:22), Rafael J. Wysocki wrote:
> Hi All,
>
> The following 5 patches clean up a little mess in acpi_bind_one() and
> acpi_unbind_one(). They are on top of current linux-next plus the patch
> at https://patchwork.kernel.org/patch/2839101/ .
>

> [1/5] Move duplicated code from acpi_bind_one()/acpi_unbind_one() to a separate
> function.
> [2/5] Create symlinks in acpi_bind_one() under physical_node_lock.
> [3/5] Clean up inconsistent use of whitespace in acpi_bind_one()/acpi_unbind_one().
> [4/5] Use list_for_each_entry() to walk the list in acpi_unbind_one().
> [5/5] Clean up the error code path in acpi_unbind_one().

Acked-by: Yasuaki Ishimatsu <[email protected]>

Thanks,
Yasuaki Ishimatsu


>
> Thanks,
> Rafael
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>