Skip to contentSkip to conversation

base: core: Remove WARN_ON from link dependencies check

PATCH Superseded Benjamin Gaignard 4 participants 6 messages Jul 12, 2018 – Jul 16, 2018 Driver core

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 base: core: Remove WARN_ON from link dependencies check

In some cases the link between between customer and supplier already exist. Do not warn about already existing dependencies because device_link_add() take care of this case.

---
 drivers/base/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/core.c +2 -2
index df3e1a44707a..fcdc17f0f349 100644
@@ -105,7 +105,7 @@ static int device_is_dependent(struct device *dev, void *target)
 	struct device_link *link;
 	int ret;
 
-	if (WARN_ON(dev == target))
+	if (dev == target)
 		return 1;
 
 	ret = device_for_each_child(dev, target, device_is_dependent);
@@ -113,7 +113,7 @@ static int device_is_dependent(struct device *dev, void *target)
 		return ret;
 
 	list_for_each_entry(link, &dev->links.consumers, s_node) {
-		if (WARN_ON(link->consumer == target))
+		if (link->consumer == target)
 			return 1;
 
 		ret = device_is_dependent(link->consumer, target);
Signature · 1 line
2.15.0
maintainer
#1 lore raw
Quoted 3 lines · Benjamin Gaignard

In some cases the link between between customer and supplier already exist. Do not warn about already existing dependencies because device_link_add() take care of this case.

Why would a link already exist that is asked to be created again? What code path causes this?

Quoted 21 lines
---
 drivers/base/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/core.c +1 -1
index df3e1a44707a..fcdc17f0f349 100644
@@ -105,7 +105,7 @@ static int device_is_dependent(struct device *dev, void *target)
 	struct device_link *link;
 	int ret;
 
-	if (WARN_ON(dev == target))
+	if (dev == target)
 		return 1;
 
 	ret = device_for_each_child(dev, target, device_is_dependent);

drivers/base/core.c static int device_is_dependent(struct device *dev, void *target) · line 117

Quoted 6 lines
drivers/base/core.c +1 -1
@@ -113,7 +113,7 @@ static int device_is_dependent(struct device *dev, void *target)
 		return ret;
 
 	list_for_each_entry(link, &dev->links.consumers, s_node) {
-		if (WARN_ON(link->consumer == target))
+		if (link->consumer == target)
 			return 1;

Both of these WARN_ON are for valid code? That feels really odd to me, I need more explanation here please.

thanks,

greg k-h

#2 lore raw

2018-07-12 10:55 GMT+02:00 Greg KH <[email protected]>:

Quoted 7 lines · Benjamin Gaignard
Quoted 3 lines

In some cases the link between between customer and supplier already exist. Do not warn about already existing dependencies because device_link_add() take care of this case.

Why would a link already exist that is asked to be created again? What code path causes this?

It could happen that the link exist because a device use it parent as supplier. That case has been describe by Marek in this thread (I forgot to add it in the commit message, sorry):
https://lkml.org/lkml/2018/7/9/356

Quoted 24 lines
Quoted 24 lines
---
 drivers/base/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/core.c +1 -1
index df3e1a44707a..fcdc17f0f349 100644
@@ -105,7 +105,7 @@ static int device_is_dependent(struct device *dev, void *target)
      struct device_link *link;
      int ret;
 
-     if (WARN_ON(dev == target))
+     if (dev == target)
              return 1;
 
      ret = device_for_each_child(dev, target, device_is_dependent);
@@ -113,7 +113,7 @@ static int device_is_dependent(struct device *dev, void *target)
              return ret;
 
Quoted 7 lines

drivers/base/core.c static int device_is_dependent(struct device *dev, void *target) · line 117

Quoted 4 lines
drivers/base/core.c +1 -1
      list_for_each_entry(link, &dev->links.consumers, s_node) {
-             if (WARN_ON(link->consumer == target))
+             if (link->consumer == target)
                      return 1;

Both of these WARN_ON are for valid code? That feels really odd to me, I need more explanation here please.

The documentation of the function is clear about return values:
"Check if @target depends on @dev or any device dependent on it (its child or ts consumer etc). Return 1 if that is the case or 0 otherwise."
so, for me, not need to warn user about something that is expected.

Benjamin

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
Quoted 9 lines · Benjamin Gaignard

2018-07-12 10:55 GMT+02:00 Greg KH <[email protected]>:

Quoted 2 lines

Why would a link already exist that is asked to be created again? What code path causes this?

It could happen that the link exist because a device use it parent as supplier. That case has been describe by Marek in this thread (I forgot to add it in the commit message, sorry):
https://lkml.org/lkml/2018/7/9/356

If we don't remove the warning then we'd need to have some way for generic code to check if a link that it wants to create exists already since if more than one thing adds links there's always a chance that two of them will come up with the same idea for a link. We could export device_is_dependent() and have them check that, or add a new flag that skips the check for example. This is however probably going to affect a reasonable percentage of potential users.

#4 lore raw
In reply to Benjamin Gaignard
Quoted 6 lines · CEST Benjamin Gaignard

2018-07-12 10:55 GMT+02:00 Greg KH <[email protected]>:

Quoted 5 lines · Benjamin Gaignard
Quoted 3 lines

In some cases the link between between customer and supplier already exist. Do not warn about already existing dependencies because device_link_add() take care of this case.

Quoted 7 lines
Quoted 2 lines

Why would a link already exist that is asked to be created again? What code path causes this?

It could happen that the link exist because a device use it parent as supplier. That case has been describe by Marek in this thread (I forgot to add it in the commit message, sorry):
https://lkml.org/lkml/2018/7/9/356

So please add this information to the patch changelog and resend.

Thanks,
Rafael