Skip to contentSkip to conversation

device property: Keep secondary firmware node secondary by type

PATCH Applied Andy Shevchenko 4 participants 9 messages Oct 22, 2020 – Oct 27, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 device property: Keep secondary firmware node secondary by type

Behind primary and secondary we understand the type of the nodes which might define their ordering. However, if primary node gone, we can't maintain the ordering by definition of the linked list. Thus, by ordering secondary node becomes first in the list. But in this case the meaning of it is still secondary (or auxiliary). The type of the node is maintained by the secondary pointer in it:

secondary pointer Meaning
NULL or valid primary node
ERR_PTR(-ENODEV) secondary node

So, if by some reason we do the following sequence of calls

	set_primary_fwnode(dev, NULL);
	set_primary_fwnode(dev, primary);

we should preserve secondary node.

This concept is supported by the description of set_primary_fwnode() along with implementation of set_secondary_fwnode(). Hence, fix the commit c15e1bdda436 to follow this as well.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
Cc Ferry Toth <[email protected]>
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index c852f16c111b..41feab679fa1 100644
@@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	} else {
 		if (fwnode_is_primary(fn)) {
 			dev->fwnode = fn->secondary;
-			fn->secondary = NULL;
+			fn->secondary = ERR_PTR(-ENODEV);
 		} else {
 			dev->fwnode = NULL;
 		}
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/2 device property: Don't clear secondary pointer for shared primary firmware node

It appears that firmware nodes can be shared between devices. In such case when a (child) device is about to be deleted, its firmware node may be shared and ACPI_COMPANION_SET(..., NULL) call for it breaks the secondary link of the shared primary firmware node.

In order to prevent that, check, if the device has a parent and parent's firmware node is shared with its child, and avoid crashing the link.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
---
 drivers/base/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +3 -1
index 41feab679fa1..78114ddac755 100644
@@ -4264,6 +4264,7 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
  */
 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 {
+	struct device *parent = dev->parent;
 	struct fwnode_handle *fn = dev->fwnode;
 
 	if (fwnode) {
@@ -4278,7 +4279,8 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	} else {
 		if (fwnode_is_primary(fn)) {
 			dev->fwnode = fn->secondary;
-			fn->secondary = ERR_PTR(-ENODEV);
+			if (!(parent && fn == parent->fwnode))
+				fn->secondary = ERR_PTR(-ENODEV);
 		} else {
 			dev->fwnode = NULL;
 		}
Signature · 1 line
2.28.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] device property: Don't clear secondary pointer for shared primary firmware node

Quoted 11 lines · Andy Shevchenko

It appears that firmware nodes can be shared between devices. In such case when a (child) device is about to be deleted, its firmware node may be shared and ACPI_COMPANION_SET(..., NULL) call for it breaks the secondary link of the shared primary firmware node.

In order to prevent that, check, if the device has a parent and parent's firmware node is shared with its child, and avoid crashing the link.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")

FWIW:

Quoted 28 lines
---
 drivers/base/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +3 -1
index 41feab679fa1..78114ddac755 100644
@@ -4264,6 +4264,7 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
  */
 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 {
+	struct device *parent = dev->parent;
 	struct fwnode_handle *fn = dev->fwnode;
 
 	if (fwnode) {
@@ -4278,7 +4279,8 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	} else {
 		if (fwnode_is_primary(fn)) {
 			dev->fwnode = fn->secondary;
-			fn->secondary = ERR_PTR(-ENODEV);
+			if (!(parent && fn == parent->fwnode))
+				fn->secondary = ERR_PTR(-ENODEV);
 		} else {
 			dev->fwnode = NULL;
 		}
Signature · 1 line
2.28.0
Signature · 1 line
heikki
Tested-by
#3 lore raw

Re: [PATCH v1 2/2] device property: Don't clear secondary pointer for shared primary firmware node

Hi

Op 23-10-2020 om 14:35 schreef Heikki Krogerus:

Quoted 9 lines · Andy Shevchenko
Quoted 8 lines

It appears that firmware nodes can be shared between devices. In such case when a (child) device is about to be deleted, its firmware node may be shared and ACPI_COMPANION_SET(..., NULL) call for it breaks the secondary link of the shared primary firmware node.

In order to prevent that, check, if the device has a parent and parent's firmware node is shared with its child, and avoid crashing the link.

Quoted 6 lines
Quoted 3 lines
Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")

FWIW:

Quoted 28 lines
Quoted 28 lines
---
  drivers/base/core.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +3 -1
index 41feab679fa1..78114ddac755 100644
@@ -4264,6 +4264,7 @@ static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
   */
  void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
  {
+	struct device *parent = dev->parent;
  	struct fwnode_handle *fn = dev->fwnode;
 
  	if (fwnode) {
@@ -4278,7 +4279,8 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
  	} else {
  		if (fwnode_is_primary(fn)) {
  			dev->fwnode = fn->secondary;
-			fn->secondary = ERR_PTR(-ENODEV);
+			if (!(parent && fn == parent->fwnode))
+				fn->secondary = ERR_PTR(-ENODEV);
  		} else {
  			dev->fwnode = NULL;
  		}
Signature · 1 line
2.28.0
Tested-by
#4 lore raw

Re: [PATCH v1 2/2] device property: Don't clear secondary pointer for shared primary firmware node

In reply to Heikki Krogerus

Hi

Op 23-10-2020 om 14:35 schreef Heikki Krogerus:

Quoted 9 lines · Andy Shevchenko
Quoted 8 lines

It appears that firmware nodes can be shared between devices. In such case when a (child) device is about to be deleted, its firmware node may be shared and ACPI_COMPANION_SET(..., NULL) call for it breaks the secondary link of the shared primary firmware node.

In order to prevent that, check, if the device has a parent and parent's firmware node is shared with its child, and avoid crashing the link.

Quoted 6 lines
Quoted 3 lines
Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")

FWIW:

Quoted 28 lines
Quoted 28 lines

---
drivers/base/core.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +3 -1
index 41feab679fa1..78114ddac755 100644
@@ -4264,6 +4264,7 @@ static inline bool fwnode_is_primary(struct 
 fwnode_handle *fwnode)
 */
 void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 {
+ struct device *parent = dev->parent;
 struct fwnode_handle *fn = dev->fwnode;
 if (fwnode) {
@@ -4278,7 +4279,8 @@ void set_primary_fwnode(struct device *dev, 
 struct fwnode_handle *fwnode)
 } else {
 if (fwnode_is_primary(fn)) {
 dev->fwnode = fn->secondary;
- fn->secondary = ERR_PTR(-ENODEV);
+ if (!(parent && fn == parent->fwnode))
+ fn->secondary = ERR_PTR(-ENODEV);
 } else {
 dev->fwnode = NULL;

}
-- 2.28.0

Reviewed-by on v1 1/2
#5 lore raw
In reply to Andy Shevchenko
Quoted 18 lines · Andy Shevchenko

Behind primary and secondary we understand the type of the nodes which might define their ordering. However, if primary node gone, we can't maintain the ordering by definition of the linked list. Thus, by ordering secondary node becomes first in the list. But in this case the meaning of it is still secondary (or auxiliary). The type of the node is maintained by the secondary pointer in it:

secondary pointer Meaning
NULL or valid primary node
ERR_PTR(-ENODEV) secondary node

So, if by some reason we do the following sequence of calls

	set_primary_fwnode(dev, NULL);
	set_primary_fwnode(dev, primary);

we should preserve secondary node.

Quoted 7 lines

This concept is supported by the description of set_primary_fwnode() along with implementation of set_secondary_fwnode(). Hence, fix the commit c15e1bdda436 to follow this as well.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
Cc Ferry Toth <[email protected]>

FWIW:

Quoted 19 lines
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index c852f16c111b..41feab679fa1 100644
@@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
 	} else {
 		if (fwnode_is_primary(fn)) {
 			dev->fwnode = fn->secondary;
-			fn->secondary = NULL;
+			fn->secondary = ERR_PTR(-ENODEV);
 		} else {
 			dev->fwnode = NULL;
 		}
Signature · 1 line
2.28.0
Signature · 1 line
heikki
#6 lore raw

Hi

Op 23-10-2020 om 14:34 schreef Heikki Krogerus:

Quoted 49 lines · Andy Shevchenko
Quoted 18 lines

Behind primary and secondary we understand the type of the nodes which might define their ordering. However, if primary node gone, we can't maintain the ordering by definition of the linked list. Thus, by ordering secondary node becomes first in the list. But in this case the meaning of it is still secondary (or auxiliary). The type of the node is maintained by the secondary pointer in it:

secondary pointer Meaning
NULL or valid primary node
ERR_PTR(-ENODEV) secondary node

So, if by some reason we do the following sequence of calls

	set_primary_fwnode(dev, NULL);
	set_primary_fwnode(dev, primary);

we should preserve secondary node.

Quoted 7 lines

This concept is supported by the description of set_primary_fwnode() along with implementation of set_secondary_fwnode(). Hence, fix the commit c15e1bdda436 to follow this as well.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
Cc Ferry Toth<[email protected]>

FWIW:

Quoted 19 lines
---
  drivers/base/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index c852f16c111b..41feab679fa1 100644
@@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
  	} else {
  		if (fwnode_is_primary(fn)) {
  			dev->fwnode = fn->secondary;
-			fn->secondary = NULL;
+			fn->secondary = ERR_PTR(-ENODEV);
  		} else {
  			dev->fwnode = NULL;
  		}
Signature · 1 line
2.28.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Tested-by Ferry Toth
#8 lore raw
Quoted 33 lines · Ferry Toth

Hi

Op 23-10-2020 om 14:34 schreef Heikki Krogerus:

Quoted 30 lines · Andy Shevchenko
Quoted 18 lines

Behind primary and secondary we understand the type of the nodes which might define their ordering. However, if primary node gone, we can't maintain the ordering by definition of the linked list. Thus, by ordering secondary node becomes first in the list. But in this case the meaning of it is still secondary (or auxiliary). The type of the node is maintained by the secondary pointer in it:

secondary pointer Meaning
NULL or valid primary node
ERR_PTR(-ENODEV) secondary node

So, if by some reason we do the following sequence of calls

	set_primary_fwnode(dev, NULL);
	set_primary_fwnode(dev, primary);

we should preserve secondary node.

Quoted 7 lines

This concept is supported by the description of set_primary_fwnode() along with implementation of set_secondary_fwnode(). Hence, fix the commit c15e1bdda436 to follow this as well.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
Cc Ferry Toth <[email protected]>

FWIW:

The quoting above is broken, I dare to put it below without any quoting.

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
---
  drivers/base/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index c852f16c111b..41feab679fa1 100644
@@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
  	} else {
  		if (fwnode_is_primary(fn)) {
  			dev->fwnode = fn->secondary;
-			fn->secondary = NULL;
+			fn->secondary = ERR_PTR(-ENODEV);
  		} else {
  			dev->fwnode = NULL;
  		}
Signature · 1 line
2.28.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Applied
#9 lore raw
In reply to Andy Shevchenko
Quoted 35 lines · Andy Shevchenko

Behind primary and secondary we understand the type of the nodes which might define their ordering. However, if primary node gone, we can't maintain the ordering by definition of the linked list. Thus, by ordering secondary node becomes first in the list. But in this case the meaning of it is still secondary (or auxiliary). The type of the node is maintained by the secondary pointer in it:

        secondary pointer               Meaning
        NULL or valid                   primary node
        ERR_PTR(-ENODEV)                secondary node

So, if by some reason we do the following sequence of calls

        set_primary_fwnode(dev, NULL);
        set_primary_fwnode(dev, primary);

we should preserve secondary node.

This concept is supported by the description of set_primary_fwnode() along with implementation of set_secondary_fwnode(). Hence, fix the commit c15e1bdda436 to follow this as well.

Fixes c15e1bdda436 ("device property: Fix the secondary firmware node handling in set_primary_fwnode()")
Cc Ferry Toth <[email protected]>
---
 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +0 -0
index c852f16c111b..41feab679fa1 100644

drivers/base/core.c void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

Quoted 9 lines
drivers/base/core.c +1 -2
@@ -4278,7 +4278,7 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
        } else {
                if (fwnode_is_primary(fn)) {
                        dev->fwnode = fn->secondary;
-                       fn->secondary = NULL;
+                       fn->secondary = ERR_PTR(-ENODEV);
                } else {
                        dev->fwnode = NULL;
                }
--

Applied as 5.10-rc material along with the [2/2], thanks!