Skip to contentSkip to conversation

ACPI: Do not fail acpi_bind_one() if device is already bound correctly

PATCH In review Rafael J. Wysocki 3 participants 10 messages Aug 1, 2013 – Aug 5, 2013 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: Do not fail acpi_bind_one() if device is already bound correctly

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/acpi/glue.c +11 -4
Index: linux-pm/drivers/acpi/glue.c
===================================================================
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
 	list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
 		if (pn->dev == dev) {
 			dev_warn(dev, "Already associated with ACPI node\n");
-			goto err_free;
+			if (ACPI_HANDLE(dev) == handle)
+				retval = 0;
+
+			goto out_free;
 		}
 
 	/* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
 		ACPI_MAX_PHYSICAL_NODE);
 	if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
 		retval = -ENOSPC;
-		goto err_free;
+		goto out_free;
 	}
 
 	set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
 	put_device(dev);
 	return retval;
 
- err_free:
+ out_free:
 	mutex_unlock(&acpi_dev->physical_node_lock);
 	kfree(physical_node);
-	goto err;
+	if (retval)
+		goto err;
+
+	put_device(dev);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
 
#1 lore raw

2013/8/2 Rafael J. Wysocki <[email protected]>:

Quoted 43 lines

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================

drivers/acpi/glue.c +6 -3
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
        list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
                if (pn->dev == dev) {
                        dev_warn(dev, "Already associated with ACPI node\n");
-                       goto err_free;
+                       if (ACPI_HANDLE(dev) == handle)
+                               retval = 0;
+
+                       goto out_free;
                }
 
        /* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
                ACPI_MAX_PHYSICAL_NODE);
        if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
                retval = -ENOSPC;
-               goto err_free;
+               goto out_free;
        }
 
        set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
        put_device(dev);
        return retval;
 
- err_free:
+ out_free:

drivers/acpi/glue.c int acpi_bind_one(struct device *dev, ac · line 200

Quoted 10 lines
drivers/acpi/glue.c +5 -1
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       goto err;
+       if (retval)
+               goto err;
+
+       put_device(dev);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);

Hi Rafael:
How about the following change?

drivers/acpi/glue.c +4 -9
index f70cc45..35f375e 100644
@@ -183,19 +183,15 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
 
        return 0;
 
- err:
-       ACPI_HANDLE_SET(dev, NULL);
-       put_device(dev);
-       return retval;
-
  out_free:
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       if (retval)
-               goto err;
 
+ err:
+       if (retval)
+               ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
-       return 0;
+       return retval;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
---------------

When I reviewed this patch, found the dev's acpi handle always is set to NULL if there is error. This seems make no sense for the case that the handle has been set to dev before binding.

For this case, the acpi handle has been found before binding. Actually, the device driver could control any resources under ACPI node even if the binding failed. So adding one flag to differentiate it.

drivers/acpi/glue.c +3 -1
index 35f375e..c868e51 100644
@@ -113,6 +113,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        acpi_status status;
        struct acpi_device_physical_node *physical_node, *pn;
        char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
+       bool has_handle = false;
        int retval = -EINVAL;
 
        if (ACPI_HANDLE(dev)) {
@@ -121,6 +122,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
                        return -EINVAL;
                } else {
                        handle = ACPI_HANDLE(dev);
+                       has_handle = true;
                }
        }
        if (!handle)
@@ -188,7 +190,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        kfree(physical_node);
 
  err:
-       if (retval)
+       if (retval && !has_handle)
                ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
        return retval;
Quoted 6 lines
drivers/acpi/glue.c +0 -1
--

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

Signature · 2 lines
Best regards
Tianyu Lan
#2 lore raw
Quoted 42 lines · Lan Tianyu

2013/8/2 Rafael J. Wysocki <[email protected]>:

Quoted 41 lines

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================

drivers/acpi/glue.c +5 -2
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
        list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
                if (pn->dev == dev) {
                        dev_warn(dev, "Already associated with ACPI node\n");
-                       goto err_free;
+                       if (ACPI_HANDLE(dev) == handle)
+                               retval = 0;
+
+                       goto out_free;
                }
 
        /* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
                ACPI_MAX_PHYSICAL_NODE);
        if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
                retval = -ENOSPC;
-               goto err_free;
+               goto out_free;
        }
 
        set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
        put_device(dev);
        return retval;
 
Quoted 15 lines

drivers/acpi/glue.c int acpi_bind_one(struct device *dev, acpi_handle handle) · line 196

Quoted 12 lines
drivers/acpi/glue.c +6 -2
- err_free:
+ out_free:
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       goto err;
+       if (retval)
+               goto err;
+
+       put_device(dev);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);

Hi Rafael:
How about the following change?

It is incorrect, because the "problem" it attempts to "fix" is actually intentional behavior. [And you could ask if it was intentional in the first place instead of assuming that it was a mistake. It wasn't.]

Do you have any problems with my $subject patch?

Rafael

Quoted 81 lines
drivers/acpi/glue.c +4 -9
index f70cc45..35f375e 100644
@@ -183,19 +183,15 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
 
        return 0;
 
- err:
-       ACPI_HANDLE_SET(dev, NULL);
-       put_device(dev);
-       return retval;
-
  out_free:
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       if (retval)
-               goto err;
 
+ err:
+       if (retval)
+               ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
-       return 0;
+       return retval;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
---------------

When I reviewed this patch, found the dev's acpi handle always is set to NULL if there is error. This seems make no sense for the case that the handle has been set to dev before binding.

For this case, the acpi handle has been found before binding. Actually, the device driver could control any resources under ACPI node even if the binding failed. So adding one flag to differentiate it.

drivers/acpi/glue.c +3 -1
index 35f375e..c868e51 100644
@@ -113,6 +113,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        acpi_status status;
        struct acpi_device_physical_node *physical_node, *pn;
        char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
+       bool has_handle = false;
        int retval = -EINVAL;
 
        if (ACPI_HANDLE(dev)) {
@@ -121,6 +122,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
                        return -EINVAL;
                } else {
                        handle = ACPI_HANDLE(dev);
+                       has_handle = true;
                }
        }
        if (!handle)
@@ -188,7 +190,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        kfree(physical_node);
 
  err:
-       if (retval)
+       if (retval && !has_handle)
                ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
        return retval;
Quoted 9 lines
drivers/acpi/glue.c +0 -1
--

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

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Reviewed-by
#3 lore raw

2013/8/2 Rafael J. Wysocki <[email protected]>:

Quoted 59 lines · Lan Tianyu
Quoted 42 lines

2013/8/2 Rafael J. Wysocki <[email protected]>:

Quoted 41 lines

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================

drivers/acpi/glue.c +5 -2
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
        list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
                if (pn->dev == dev) {
                        dev_warn(dev, "Already associated with ACPI node\n");
-                       goto err_free;
+                       if (ACPI_HANDLE(dev) == handle)
+                               retval = 0;
+
+                       goto out_free;
                }
 
        /* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
                ACPI_MAX_PHYSICAL_NODE);
        if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
                retval = -ENOSPC;
-               goto err_free;
+               goto out_free;
        }
 
        set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
        put_device(dev);
        return retval;
 
Quoted 15 lines

drivers/acpi/glue.c int acpi_bind_one(struct device *dev, acpi_handle handle) · line 196

Quoted 12 lines
drivers/acpi/glue.c +6 -2
- err_free:
+ out_free:
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       goto err;
+       if (retval)
+               goto err;
+
+       put_device(dev);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);

Hi Rafael:
How about the following change?

Quoted 4 lines

It is incorrect, because the "problem" it attempts to "fix" is actually intentional behavior. [And you could ask if it was intentional in the first place instead of assuming that it was a mistake. It wasn't.]

Ok.

Quoted 1 line

Do you have any problems with my $subject patch?

No, I have no problem now.

Quoted 88 lines

Rafael

Quoted 73 lines
drivers/acpi/glue.c +4 -9
index f70cc45..35f375e 100644
@@ -183,19 +183,15 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
 
        return 0;
 
- err:
-       ACPI_HANDLE_SET(dev, NULL);
-       put_device(dev);
-       return retval;
-
  out_free:
        mutex_unlock(&acpi_dev->physical_node_lock);
        kfree(physical_node);
-       if (retval)
-               goto err;
 
+ err:
+       if (retval)
+               ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
-       return 0;
+       return retval;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
---------------

When I reviewed this patch, found the dev's acpi handle always is set to NULL if there is error. This seems make no sense for the case that the handle has been set to dev before binding.

For this case, the acpi handle has been found before binding. Actually, the device driver could control any resources under ACPI node even if the binding failed. So adding one flag to differentiate it.

drivers/acpi/glue.c +3 -1
index 35f375e..c868e51 100644
@@ -113,6 +113,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        acpi_status status;
        struct acpi_device_physical_node *physical_node, *pn;
        char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2];
+       bool has_handle = false;
        int retval = -EINVAL;
 
        if (ACPI_HANDLE(dev)) {
@@ -121,6 +122,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
                        return -EINVAL;
                } else {
                        handle = ACPI_HANDLE(dev);
+                       has_handle = true;
                }
        }
        if (!handle)
@@ -188,7 +190,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle)
        kfree(physical_node);
 
  err:
-       if (retval)
+       if (retval && !has_handle)
                ACPI_HANDLE_SET(dev, NULL);
        put_device(dev);
        return retval;
Quoted 5 lines
Quoted 8 lines
Quoted 4 lines

--
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

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

Signature · 2 lines
Best regards
Tianyu Lan
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

Thanks,
-Toshi

Quoted 52 lines
---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================

drivers/acpi/glue.c +11 -5
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
 	list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
 		if (pn->dev == dev) {
 			dev_warn(dev, "Already associated with ACPI node\n");
-			goto err_free;
+			if (ACPI_HANDLE(dev) == handle)
+				retval = 0;
+
+			goto out_free;
 		}
 
 	/* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
 		ACPI_MAX_PHYSICAL_NODE);
 	if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
 		retval = -ENOSPC;
-		goto err_free;
+		goto out_free;
 	}
 
 	set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
 	put_device(dev);
 	return retval;
 
- err_free:
+ out_free:
 	mutex_unlock(&acpi_dev->physical_node_lock);
 	kfree(physical_node);
-	goto err;
+	if (retval)
+		goto err;
+
+	put_device(dev);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
 
 
--

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

#5 lore raw
Quoted 8 lines · Toshi Kani
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

Quoted 4 lines

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

In theory it should be possible to call acpi_bind_one() twice in a row for the same dev and the same handle without failure, that simply is logical. The patch may not fix any problems visible now, but returning an error code in such a case is simply incorrect.

Thanks,
Rafael

Quoted 58 lines
Quoted 49 lines
---
 drivers/acpi/glue.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================

drivers/acpi/glue.c +11 -5
@@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac
 	list_for_each_entry(pn, &acpi_dev->physical_node_list, node)
 		if (pn->dev == dev) {
 			dev_warn(dev, "Already associated with ACPI node\n");
-			goto err_free;
+			if (ACPI_HANDLE(dev) == handle)
+				retval = 0;
+
+			goto out_free;
 		}
 
 	/* allocate physical node id according to physical_node_id_bitmap */
@@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac
 		ACPI_MAX_PHYSICAL_NODE);
 	if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) {
 		retval = -ENOSPC;
-		goto err_free;
+		goto out_free;
 	}
 
 	set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap);
@@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac
 	put_device(dev);
 	return retval;
 
- err_free:
+ out_free:
 	mutex_unlock(&acpi_dev->physical_node_lock);
 	kfree(physical_node);
-	goto err;
+	if (retval)
+		goto err;
+
+	put_device(dev);
+	return 0;
 }
 EXPORT_SYMBOL_GPL(acpi_bind_one);
 
 
--
Quoted 3 lines

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

--
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

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#6 lore raw
Quoted 14 lines · Rafael J. Wysocki
Quoted 8 lines · Toshi Kani
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

Quoted 4 lines

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

Quoted 4 lines

In theory it should be possible to call acpi_bind_one() twice in a row for the same dev and the same handle without failure, that simply is logical. The patch may not fix any problems visible now, but returning an error code in such a case is simply incorrect.

We changed acpi_bus_device_attach() to not call the handler or driver again if it is already bound. So, I was under impression that we prevent from attaching a same device twice. But I may be missing something...

Thanks,
-Toshi

#7 lore raw
Quoted 20 lines · Toshi Kani
Quoted 14 lines · Rafael J. Wysocki
Quoted 8 lines · Toshi Kani
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

Quoted 4 lines

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

Quoted 4 lines

In theory it should be possible to call acpi_bind_one() twice in a row for the same dev and the same handle without failure, that simply is logical. The patch may not fix any problems visible now, but returning an error code in such a case is simply incorrect.

Quoted 4 lines

We changed acpi_bus_device_attach() to not call the handler or driver again if it is already bound. So, I was under impression that we prevent from attaching a same device twice. But I may be missing something...

acpi_bind_one() may be called in code paths that don't start from acpi_bus_device_attach(), like acpi_platform_notify(), where the result depends on how .find_device() is implemented by the the given bus type, for example.

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Acked-by
#8 lore raw
Quoted 26 lines · Rafael J. Wysocki
Quoted 20 lines · Toshi Kani
Quoted 14 lines · Rafael J. Wysocki
Quoted 8 lines · Toshi Kani
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

Quoted 4 lines

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

Quoted 4 lines

In theory it should be possible to call acpi_bind_one() twice in a row for the same dev and the same handle without failure, that simply is logical. The patch may not fix any problems visible now, but returning an error code in such a case is simply incorrect.

Quoted 4 lines

We changed acpi_bus_device_attach() to not call the handler or driver again if it is already bound. So, I was under impression that we prevent from attaching a same device twice. But I may be missing something...

Quoted 4 lines

acpi_bind_one() may be called in code paths that don't start from acpi_bus_device_attach(), like acpi_platform_notify(), where the result depends on how .find_device() is implemented by the the given bus type, for example.

acpi_bind_one() always returns with 0 when it sets a handle to the device. So, acpi_platform_notify() should not call .find_device() in this case. acpi_bus_check_add() is also protected from adding a same device twice. But I see your point that the callers of acpi_bind_one() could be changed / implementation dependent. So, I agree that it would be prudent to have this change.

Thanks,
-Toshi

#9 lore raw
Quoted 32 lines · Toshi Kani
Quoted 26 lines · Rafael J. Wysocki
Quoted 20 lines · Toshi Kani
Quoted 14 lines · Rafael J. Wysocki
Quoted 8 lines · Toshi Kani
Quoted 6 lines · Rafael J. Wysocki

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

Modify acpi_bind_one() so that it doesn't fail if the device represented by its first argument has already been bound to the given ACPI handle (second argument), because that is not a good enough reason for returning an error code.

Quoted 4 lines

While it seems reasonable to allow such case, I do not think we will hit this case under the normal scenarios. So, I do not think we need to make this change now unless it actually solves Yasuaki's issue (which I am guessing not).

Quoted 4 lines

In theory it should be possible to call acpi_bind_one() twice in a row for the same dev and the same handle without failure, that simply is logical. The patch may not fix any problems visible now, but returning an error code in such a case is simply incorrect.

Quoted 4 lines

We changed acpi_bus_device_attach() to not call the handler or driver again if it is already bound. So, I was under impression that we prevent from attaching a same device twice. But I may be missing something...

Quoted 4 lines

acpi_bind_one() may be called in code paths that don't start from acpi_bus_device_attach(), like acpi_platform_notify(), where the result depends on how .find_device() is implemented by the the given bus type, for example.

Quoted 8 lines

acpi_bind_one() always returns with 0 when it sets a handle to the device. So, acpi_platform_notify() should not call .find_device() in this case. acpi_bus_check_add() is also protected from adding a same device twice. But I see your point that the callers of acpi_bind_one() could be changed / implementation dependent. So, I agree that it would be prudent to have this change.

Thanks!

I wonder what you think about this patch:

https://patchwork.kernel.org/patch/2838675/

Rafael