Re: [RFC PATCH] software node: Skip duplicated software_node sysfs

From: Qian Cai
Date: Mon Nov 08 2021 - 11:07:59 EST




On 11/5/21 3:39 PM, Andy Shevchenko wrote:
>> Andy, thanks for the pointers so far. I was able to trace
>> set_primary_fwnode() and set_secondary_fwnode().
>
> Can you share the trace you have got?


I used a simple debugging patch below:

diff --git a/drivers/base/core.c b/drivers/base/core.c

index fd034d742447..d8ae96289acf 100644

--- a/drivers/base/core.c

+++ b/drivers/base/core.c

@@ -4742,6 +4742,11 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

struct device *parent = dev->parent;

struct fwnode_handle *fn = dev->fwnode;



+ printk("KK set_primary_fwnode dev name = %s, fwnode = %px\n", dev_name(dev), fwnode);

+ if (parent)

+ printk("KK parent = %s\n", dev_name(dev->parent));

+ if (fwnode && fwnode->dev)

+ printk("KK fwnode->dev = %s\n", dev_name(fwnode->dev));

if (fwnode) {

if (fwnode_is_primary(fn))

fn = fn->secondary;

@@ -4761,6 +4766,8 @@ void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

dev->fwnode = NULL;

}

}

+ if (fwnode)

+ printk("KK secondary = %px\n", dev->fwnode->secondary);

}

EXPORT_SYMBOL_GPL(set_primary_fwnode);



@@ -4775,13 +4782,20 @@ EXPORT_SYMBOL_GPL(set_primary_fwnode);

*/

void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)

{

+ printk("KK set_secondary_fwnode dev name = %s, fwnode = %px\n", dev_name(dev), fwnode);

+ if (dev->parent)

+ printk("KK parent = %s\n", dev_name(dev->parent));

+ if (fwnode && fwnode->dev)

+ printk("KK fwnode->dev = %s\n", dev_name(fwnode->dev));

if (fwnode)

fwnode->secondary = ERR_PTR(-ENODEV);



- if (fwnode_is_primary(dev->fwnode))

+ if (fwnode_is_primary(dev->fwnode)) {

dev->fwnode->secondary = fwnode;

- else

+ printk("KK primary = %px\n", dev->fwnode);

+ } else {

dev->fwnode = fwnode;

+ }

}

EXPORT_SYMBOL_GPL(set_secondary_fwnode);


Then, here are the relevant outputs indicating that
"808622B7:01" and "xhci-hcd.3.auto" have the same
primary but different secondaries.

[ 11.233280] KK set_secondary_fwnode dev name = 808622B7:01, fwnode = ffff000838618840

[ 11.241846] KK parent = platform

[ 11.245790] KK primary = ffff0008064b9010

[ 11.259838] KK set_primary_fwnode dev name = (null), fwnode = ffff0008064b9010

[ 11.267795] KK parent = 808622B7:01

[ 11.272000] KK fwnode->dev = 808622B7:01

[ 11.276636] KK secondary = ffff000838618840

[ 11.680489] KK set_secondary_fwnode dev name = xhci-hcd.3.auto, fwnode = ffff000838325040

[ 11.689406] KK parent = 808622B7:01

[ 11.693916] KK primary = ffff0008064b9010
[ 11.698763] sysfs: cannot create duplicate filename '/devices/platform/808622B7:01/xhci-hcd.3.auto/software_node'