2024-01-30 18:46:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 0/7] Soundwire: clean up sysfs group creation

Note, this is a redone version of a very old series I wrote back in
2022:
https://lore.kernel.org/r/[email protected]
but everyone has forgotten about it now, and I've reworked it, so I'm
considering it a "new" version, and not v2.

Here's a series that adds the functionality to the driver core to hide
entire attribute groups, in a much saner way than we have attempted in
the past (i.e. dynamically figuring it out.) Many thanks to Dan for
this patch. I'll also be taking this into my driver-core branch and
creating a stable tag for anyone else to pull from to get it into their
trees, as I think it will want to be in many for this development cycle.

After the driver core change, there's cleanups to the soundwire core for
how the attribute groups are created, to remove the "manual" creation of
them, and allow the driver core to create them correctly, as needed,
when needed, which makes things much smaller for the soundwire code to
manage.

Comments appreciated!

thanks,

greg k-h

Dan Williams (1):
sysfs: Introduce a mechanism to hide static attribute_groups

Greg Kroah-Hartman (5):
soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list
of groups
soundwire: sysfs: cleanup the logic for creating the dp0 sysfs
attributes
soundwire: sysfs: have the driver core handle the creation of the
device groups
soundwire: sysfs: remove sdw_slave_sysfs_init()
soundwire: sysfs: remove unneeded ATTRIBUTE_GROUPS() comments

drivers/soundwire/bus_type.c | 5 ++-
drivers/soundwire/sysfs_local.h | 4 +-
drivers/soundwire/sysfs_slave.c | 64 ++++++++++++++---------------
drivers/soundwire/sysfs_slave_dpn.c | 3 ++
fs/sysfs/group.c | 45 ++++++++++++++++----
include/linux/sysfs.h | 63 ++++++++++++++++++++++------
6 files changed, 126 insertions(+), 58 deletions(-)

--
2.43.0



2024-01-30 18:47:05

by Greg KH

[permalink] [raw]
Subject: [PATCH 2/6] soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list of groups

The sysfs logic already creates a list of groups for the device, so add
the sdw_slave_dev_attr_group group to that list instead of having to do
a two-step process of adding a group list and then an individual group.

This is a step on the way to moving all of the sysfs attribute handling
into the default driver core attribute group logic so that the soundwire
core does not have to do any of it manually.

Cc: Vinod Koul <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Sanyog Kale <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/soundwire/sysfs_slave.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index 3210359cd944..83e3f6cc3250 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -105,7 +105,10 @@ static struct attribute *slave_attrs[] = {
&dev_attr_modalias.attr,
NULL,
};
-ATTRIBUTE_GROUPS(slave);
+
+static const struct attribute_group slave_attr_group = {
+ .attrs = slave_attrs,
+};

static struct attribute *slave_dev_attrs[] = {
&dev_attr_mipi_revision.attr,
@@ -190,6 +193,12 @@ static const struct attribute_group dp0_group = {
.name = "dp0",
};

+static const struct attribute_group *slave_groups[] = {
+ &slave_attr_group,
+ &sdw_slave_dev_attr_group,
+ NULL,
+};
+
int sdw_slave_sysfs_init(struct sdw_slave *slave)
{
int ret;
@@ -198,10 +207,6 @@ int sdw_slave_sysfs_init(struct sdw_slave *slave)
if (ret < 0)
return ret;

- ret = devm_device_add_group(&slave->dev, &sdw_slave_dev_attr_group);
- if (ret < 0)
- return ret;
-
if (slave->prop.dp0_prop) {
ret = devm_device_add_group(&slave->dev, &dp0_group);
if (ret < 0)
--
2.43.0


2024-01-30 18:47:12

by Greg KH

[permalink] [raw]
Subject: [PATCH 3/6] soundwire: sysfs: cleanup the logic for creating the dp0 sysfs attributes

There's no need to special-case the dp0 sysfs attributes, the
is_visible() callback in the attribute group can handle that for us, so
add that and add it to the attribute group list making the logic simpler
overall.

This is a step on the way to moving all of the sysfs attribute handling
into the default driver core attribute group logic so that the soundwire
core does not have to do any of it manually.

Cc: Vinod Koul <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Sanyog Kale <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/soundwire/sysfs_slave.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index 83e3f6cc3250..8876c7807048 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -184,18 +184,40 @@ static struct attribute *dp0_attrs[] = {
NULL,
};

+static umode_t dp0_attr_visible(struct kobject *kobj, struct attribute *attr,
+ int n)
+{
+ struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
+
+ if (slave->prop.dp0_prop)
+ return attr->mode;
+ return 0;
+}
+
+static bool dp0_group_visible(struct kobject *kobj)
+{
+ struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
+
+ if (slave->prop.dp0_prop)
+ return true;
+ return false;
+}
+DEFINE_SYSFS_GROUP_VISIBLE(dp0);
+
/*
* we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
* for dp0-level properties
*/
static const struct attribute_group dp0_group = {
.attrs = dp0_attrs,
+ .is_visible = SYSFS_GROUP_VISIBLE(dp0),
.name = "dp0",
};

static const struct attribute_group *slave_groups[] = {
&slave_attr_group,
&sdw_slave_dev_attr_group,
+ &dp0_group,
NULL,
};

@@ -207,12 +229,6 @@ int sdw_slave_sysfs_init(struct sdw_slave *slave)
if (ret < 0)
return ret;

- if (slave->prop.dp0_prop) {
- ret = devm_device_add_group(&slave->dev, &dp0_group);
- if (ret < 0)
- return ret;
- }
-
if (slave->prop.source_ports || slave->prop.sink_ports) {
ret = sdw_slave_sysfs_dpn_init(slave);
if (ret < 0)
--
2.43.0


2024-01-30 18:47:18

by Greg KH

[permalink] [raw]
Subject: [PATCH 4/6] soundwire: sysfs: have the driver core handle the creation of the device groups

The driver core supports the ability to handle the creation and removal
of device-specific sysfs files in a race-free manner. Take advantage of
that by converting this driver to use this by moving the sysfs
attributes into a group and assigning the dev_groups pointer to it.

Cc: Vinod Koul <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Sanyog Kale <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/soundwire/bus_type.c | 1 +
drivers/soundwire/sysfs_local.h | 3 +++
drivers/soundwire/sysfs_slave.c | 6 +-----
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
index 9fa93bb923d7..5abe5593395a 100644
--- a/drivers/soundwire/bus_type.c
+++ b/drivers/soundwire/bus_type.c
@@ -221,6 +221,7 @@ int __sdw_register_driver(struct sdw_driver *drv, struct module *owner)
drv->driver.probe = sdw_drv_probe;
drv->driver.remove = sdw_drv_remove;
drv->driver.shutdown = sdw_drv_shutdown;
+ drv->driver.dev_groups = sdw_attr_groups;

return driver_register(&drv->driver);
}
diff --git a/drivers/soundwire/sysfs_local.h b/drivers/soundwire/sysfs_local.h
index 7268bc24c538..3ab8658a7782 100644
--- a/drivers/soundwire/sysfs_local.h
+++ b/drivers/soundwire/sysfs_local.h
@@ -11,6 +11,9 @@
/* basic attributes to report status of Slave (attachment, dev_num) */
extern const struct attribute_group *sdw_slave_status_attr_groups[];

+/* attributes for all soundwire devices */
+extern const struct attribute_group *sdw_attr_groups[];
+
/* additional device-managed properties reported after driver probe */
int sdw_slave_sysfs_init(struct sdw_slave *slave);
int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave);
diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index 8876c7807048..3afc0dc06c98 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -214,7 +214,7 @@ static const struct attribute_group dp0_group = {
.name = "dp0",
};

-static const struct attribute_group *slave_groups[] = {
+const struct attribute_group *sdw_attr_groups[] = {
&slave_attr_group,
&sdw_slave_dev_attr_group,
&dp0_group,
@@ -225,10 +225,6 @@ int sdw_slave_sysfs_init(struct sdw_slave *slave)
{
int ret;

- ret = devm_device_add_groups(&slave->dev, slave_groups);
- if (ret < 0)
- return ret;
-
if (slave->prop.source_ports || slave->prop.sink_ports) {
ret = sdw_slave_sysfs_dpn_init(slave);
if (ret < 0)
--
2.43.0


2024-01-30 18:48:09

by Greg KH

[permalink] [raw]
Subject: [PATCH 6/6] soundwire: sysfs: remove unneeded ATTRIBUTE_GROUPS() comments

Now that we manually created our own attribute group list, the outdated
ATTRIBUTE_GROUPS() comments can be removed as they are not needed at
all.

Cc: Vinod Koul <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Sanyog Kale <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/soundwire/sysfs_slave.c | 8 --------
1 file changed, 8 deletions(-)

diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index 0eefc205f697..f4259710dd0f 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -129,10 +129,6 @@ static struct attribute *slave_dev_attrs[] = {
NULL,
};

-/*
- * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
- * for device-level properties
- */
static const struct attribute_group sdw_slave_dev_attr_group = {
.attrs = slave_dev_attrs,
.name = "dev-properties",
@@ -204,10 +200,6 @@ static bool dp0_group_visible(struct kobject *kobj)
}
DEFINE_SYSFS_GROUP_VISIBLE(dp0);

-/*
- * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
- * for dp0-level properties
- */
static const struct attribute_group dp0_group = {
.attrs = dp0_attrs,
.is_visible = SYSFS_GROUP_VISIBLE(dp0),
--
2.43.0


2024-01-30 18:48:09

by Greg KH

[permalink] [raw]
Subject: [PATCH 5/6] soundwire: sysfs: remove sdw_slave_sysfs_init()

Now that sdw_slave_sysfs_init() only calls sdw_slave_sysfs_dpn_init(),
just do that instead and remove sdw_slave_sysfs_init() to get it out of
the way to save a bit of logic and code size.

Cc: Vinod Koul <[email protected]>
Cc: Bard Liao <[email protected]>
Cc: Pierre-Louis Bossart <[email protected]>
Cc: Sanyog Kale <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/soundwire/bus_type.c | 4 ++--
drivers/soundwire/sysfs_local.h | 1 -
drivers/soundwire/sysfs_slave.c | 13 -------------
drivers/soundwire/sysfs_slave_dpn.c | 3 +++
4 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
index 5abe5593395a..6085eb8c8d85 100644
--- a/drivers/soundwire/bus_type.c
+++ b/drivers/soundwire/bus_type.c
@@ -126,8 +126,8 @@ static int sdw_drv_probe(struct device *dev)
if (slave->prop.use_domain_irq)
sdw_irq_create_mapping(slave);

- /* init the sysfs as we have properties now */
- ret = sdw_slave_sysfs_init(slave);
+ /* init the dynamic sysfs attributes we need */
+ ret = sdw_slave_sysfs_dpn_init(slave);
if (ret < 0)
dev_warn(dev, "Slave sysfs init failed:%d\n", ret);

diff --git a/drivers/soundwire/sysfs_local.h b/drivers/soundwire/sysfs_local.h
index 3ab8658a7782..fa048e112629 100644
--- a/drivers/soundwire/sysfs_local.h
+++ b/drivers/soundwire/sysfs_local.h
@@ -15,7 +15,6 @@ extern const struct attribute_group *sdw_slave_status_attr_groups[];
extern const struct attribute_group *sdw_attr_groups[];

/* additional device-managed properties reported after driver probe */
-int sdw_slave_sysfs_init(struct sdw_slave *slave);
int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave);

#endif /* __SDW_SYSFS_LOCAL_H */
diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index 3afc0dc06c98..0eefc205f697 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -221,19 +221,6 @@ const struct attribute_group *sdw_attr_groups[] = {
NULL,
};

-int sdw_slave_sysfs_init(struct sdw_slave *slave)
-{
- int ret;
-
- if (slave->prop.source_ports || slave->prop.sink_ports) {
- ret = sdw_slave_sysfs_dpn_init(slave);
- if (ret < 0)
- return ret;
- }
-
- return 0;
-}
-
/*
* the status is shown in capital letters for UNATTACHED and RESERVED
* on purpose, to highligh users to the fact that these status values
diff --git a/drivers/soundwire/sysfs_slave_dpn.c b/drivers/soundwire/sysfs_slave_dpn.c
index c4b6543c09fd..a3fb380ee519 100644
--- a/drivers/soundwire/sysfs_slave_dpn.c
+++ b/drivers/soundwire/sysfs_slave_dpn.c
@@ -283,6 +283,9 @@ int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave)
int ret;
int i;

+ if (!slave->prop.source_ports && !slave->prop.sink_ports)
+ return 0;
+
mask = slave->prop.source_ports;
for_each_set_bit(i, &mask, 32) {
ret = add_all_attributes(&slave->dev, i, 1);
--
2.43.0


2024-01-31 05:20:23

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 2/6] soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list of groups

Greg Kroah-Hartman wrote:
> The sysfs logic already creates a list of groups for the device, so add
> the sdw_slave_dev_attr_group group to that list instead of having to do
> a two-step process of adding a group list and then an individual group.
>
> This is a step on the way to moving all of the sysfs attribute handling
> into the default driver core attribute group logic so that the soundwire
> core does not have to do any of it manually.
>
> Cc: Vinod Koul <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Sanyog Kale <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/soundwire/sysfs_slave.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
> index 3210359cd944..83e3f6cc3250 100644
> --- a/drivers/soundwire/sysfs_slave.c
> +++ b/drivers/soundwire/sysfs_slave.c
> @@ -105,7 +105,10 @@ static struct attribute *slave_attrs[] = {
> &dev_attr_modalias.attr,
> NULL,
> };
> -ATTRIBUTE_GROUPS(slave);
> +
> +static const struct attribute_group slave_attr_group = {
> + .attrs = slave_attrs,
> +};
>
> static struct attribute *slave_dev_attrs[] = {
> &dev_attr_mipi_revision.attr,
> @@ -190,6 +193,12 @@ static const struct attribute_group dp0_group = {
> .name = "dp0",
> };
>
> +static const struct attribute_group *slave_groups[] = {
> + &slave_attr_group,
> + &sdw_slave_dev_attr_group,
> + NULL,
> +};
> +
> int sdw_slave_sysfs_init(struct sdw_slave *slave)
> {
> int ret;
> @@ -198,10 +207,6 @@ int sdw_slave_sysfs_init(struct sdw_slave *slave)
> if (ret < 0)
> return ret;
>
> - ret = devm_device_add_group(&slave->dev, &sdw_slave_dev_attr_group);
> - if (ret < 0)
> - return ret;
> -

Yeah, open-coding the groups, much better than dynamically adding one.

> if (slave->prop.dp0_prop) {
> ret = devm_device_add_group(&slave->dev, &dp0_group);
> if (ret < 0)

Makes sense. I won't say "looks good" as this file has "slave" all over
the place, but I checked and it entered the kernel just before the
CodingStyle changed.

Reviewed-by: Dan Williams <[email protected]>

2024-01-31 05:32:24

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 3/6] soundwire: sysfs: cleanup the logic for creating the dp0 sysfs attributes

Greg Kroah-Hartman wrote:
> There's no need to special-case the dp0 sysfs attributes, the
> is_visible() callback in the attribute group can handle that for us, so
> add that and add it to the attribute group list making the logic simpler
> overall.
>
> This is a step on the way to moving all of the sysfs attribute handling
> into the default driver core attribute group logic so that the soundwire
> core does not have to do any of it manually.
>
> Cc: Vinod Koul <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Sanyog Kale <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/soundwire/sysfs_slave.c | 28 ++++++++++++++++++++++------
> 1 file changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
> index 83e3f6cc3250..8876c7807048 100644
> --- a/drivers/soundwire/sysfs_slave.c
> +++ b/drivers/soundwire/sysfs_slave.c
> @@ -184,18 +184,40 @@ static struct attribute *dp0_attrs[] = {
> NULL,
> };
>
> +static umode_t dp0_attr_visible(struct kobject *kobj, struct attribute *attr,
> + int n)
> +{
> + struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
> +
> + if (slave->prop.dp0_prop)
> + return attr->mode;
> + return 0;
> +}
> +
> +static bool dp0_group_visible(struct kobject *kobj)
> +{
> + struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
> +
> + if (slave->prop.dp0_prop)
> + return true;
> + return false;
> +}
> +DEFINE_SYSFS_GROUP_VISIBLE(dp0);

What do you think of the following for cases like these where
attr_visible is trivially derivable from group_visible?

diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index a42642b277dd..203d2e7e9a1e 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -117,6 +117,15 @@ struct attribute_group {
return name##_attr_visible(kobj, attr, n); \
}

+#define DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name) \
+ static inline umode_t sysfs_group_visible_##name( \
+ struct kobject *kobj, struct attribute *a, int n) \
+ { \
+ if (n == 0 && !name##_group_visible(kobj)) \
+ return SYSFS_GROUP_INVISIBLE; \
+ return a->mode; \
+ }
+
/*
* Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary
* attributes

..i.e. don't require $prefix_attr_visible() to be defined?

With or without that:

Reviewed-by: Dan Williams <[email protected]>

2024-01-31 05:38:23

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 4/6] soundwire: sysfs: have the driver core handle the creation of the device groups

Greg Kroah-Hartman wrote:
> The driver core supports the ability to handle the creation and removal
> of device-specific sysfs files in a race-free manner. Take advantage of
> that by converting this driver to use this by moving the sysfs
> attributes into a group and assigning the dev_groups pointer to it.
>
> Cc: Vinod Koul <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Sanyog Kale <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/soundwire/bus_type.c | 1 +
> drivers/soundwire/sysfs_local.h | 3 +++
> drivers/soundwire/sysfs_slave.c | 6 +-----
> 3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
> index 9fa93bb923d7..5abe5593395a 100644
> --- a/drivers/soundwire/bus_type.c
> +++ b/drivers/soundwire/bus_type.c
> @@ -221,6 +221,7 @@ int __sdw_register_driver(struct sdw_driver *drv, struct module *owner)
> drv->driver.probe = sdw_drv_probe;
> drv->driver.remove = sdw_drv_remove;
> drv->driver.shutdown = sdw_drv_shutdown;
> + drv->driver.dev_groups = sdw_attr_groups;
>
> return driver_register(&drv->driver);
> }
> diff --git a/drivers/soundwire/sysfs_local.h b/drivers/soundwire/sysfs_local.h
> index 7268bc24c538..3ab8658a7782 100644
> --- a/drivers/soundwire/sysfs_local.h
> +++ b/drivers/soundwire/sysfs_local.h
> @@ -11,6 +11,9 @@
> /* basic attributes to report status of Slave (attachment, dev_num) */
> extern const struct attribute_group *sdw_slave_status_attr_groups[];
>
> +/* attributes for all soundwire devices */
> +extern const struct attribute_group *sdw_attr_groups[];
> +
> /* additional device-managed properties reported after driver probe */
> int sdw_slave_sysfs_init(struct sdw_slave *slave);
> int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave);
> diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
> index 8876c7807048..3afc0dc06c98 100644
> --- a/drivers/soundwire/sysfs_slave.c
> +++ b/drivers/soundwire/sysfs_slave.c
> @@ -214,7 +214,7 @@ static const struct attribute_group dp0_group = {
> .name = "dp0",
> };
>
> -static const struct attribute_group *slave_groups[] = {
> +const struct attribute_group *sdw_attr_groups[] = {
> &slave_attr_group,
> &sdw_slave_dev_attr_group,
> &dp0_group,
> @@ -225,10 +225,6 @@ int sdw_slave_sysfs_init(struct sdw_slave *slave)
> {
> int ret;
>
> - ret = devm_device_add_groups(&slave->dev, slave_groups);
> - if (ret < 0)
> - return ret;
> -

The subtle scary thing about this usage in general is that this makes
the sysfs attributes live before it is known that the driver probe
succeeded. So beyond the cleanup of using devm to do something that the
driver-core already handles it removes a hard to reason about race
compared to the well known lifetime of driver->dev_groups.

Reviewed-by: Dan Williams <[email protected]>

2024-01-31 05:40:34

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 5/6] soundwire: sysfs: remove sdw_slave_sysfs_init()

Greg Kroah-Hartman wrote:
> Now that sdw_slave_sysfs_init() only calls sdw_slave_sysfs_dpn_init(),
> just do that instead and remove sdw_slave_sysfs_init() to get it out of
> the way to save a bit of logic and code size.
>
> Cc: Vinod Koul <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Sanyog Kale <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Looks correct.

Reviewed-by: Dan Williams <[email protected]>

2024-01-31 05:43:05

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 6/6] soundwire: sysfs: remove unneeded ATTRIBUTE_GROUPS() comments

Greg Kroah-Hartman wrote:
> Now that we manually created our own attribute group list, the outdated
> ATTRIBUTE_GROUPS() comments can be removed as they are not needed at
> all.
>
> Cc: Vinod Koul <[email protected]>
> Cc: Bard Liao <[email protected]>
> Cc: Pierre-Louis Bossart <[email protected]>
> Cc: Sanyog Kale <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> drivers/soundwire/sysfs_slave.c | 8 --------
> 1 file changed, 8 deletions(-)
>
> diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
> index 0eefc205f697..f4259710dd0f 100644
> --- a/drivers/soundwire/sysfs_slave.c
> +++ b/drivers/soundwire/sysfs_slave.c
> @@ -129,10 +129,6 @@ static struct attribute *slave_dev_attrs[] = {
> NULL,
> };
>
> -/*
> - * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
> - * for device-level properties
> - */
> static const struct attribute_group sdw_slave_dev_attr_group = {
> .attrs = slave_dev_attrs,
> .name = "dev-properties",
> @@ -204,10 +200,6 @@ static bool dp0_group_visible(struct kobject *kobj)
> }
> DEFINE_SYSFS_GROUP_VISIBLE(dp0);
>
> -/*
> - * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
> - * for dp0-level properties
> - */
> static const struct attribute_group dp0_group = {
> .attrs = dp0_attrs,
> .is_visible = SYSFS_GROUP_VISIBLE(dp0),

Not a great look when there are comments around avoiding common idioms.

Reviewed-by: Dan Williams <[email protected]>

2024-01-31 13:35:38

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/7] Soundwire: clean up sysfs group creation

On 30-01-24, 10:46, Greg Kroah-Hartman wrote:
> Note, this is a redone version of a very old series I wrote back in
> 2022:
> https://lore.kernel.org/r/[email protected]
> but everyone has forgotten about it now, and I've reworked it, so I'm
> considering it a "new" version, and not v2.
>
> Here's a series that adds the functionality to the driver core to hide
> entire attribute groups, in a much saner way than we have attempted in
> the past (i.e. dynamically figuring it out.) Many thanks to Dan for
> this patch. I'll also be taking this into my driver-core branch and
> creating a stable tag for anyone else to pull from to get it into their
> trees, as I think it will want to be in many for this development cycle.
>
> After the driver core change, there's cleanups to the soundwire core for
> how the attribute groups are created, to remove the "manual" creation of
> them, and allow the driver core to create them correctly, as needed,
> when needed, which makes things much smaller for the soundwire code to
> manage.

The series lgtm, having the core handle these would be good. I will wait
couple of days for people to test this and give a t-b and apply.
I hope it is okay if patch1 goes thru sdw tree?

BR
--
~Vinod

2024-02-01 08:00:20

by Pierre-Louis Bossart

[permalink] [raw]
Subject: Re: [PATCH 2/6] soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list of groups


> Makes sense. I won't say "looks good" as this file has "slave" all over
> the place, but I checked and it entered the kernel just before the
> CodingStyle changed.

SoundWire 1.2.1 introduced the terms "Manager" and "Peripheral", I had a
patchset to rename everything maybe two years ago already but it's been
difficult to add without getting in the way of development and
backports. Maybe a gradual replacement makes more sense, not sure how to
go about this.


2024-02-01 15:19:19

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 2/6] soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list of groups

On Wed, Jan 31, 2024 at 08:12:10AM +0100, Pierre-Louis Bossart wrote:
>
> > Makes sense. I won't say "looks good" as this file has "slave" all over
> > the place, but I checked and it entered the kernel just before the
> > CodingStyle changed.
>
> SoundWire 1.2.1 introduced the terms "Manager" and "Peripheral", I had a
> patchset to rename everything maybe two years ago already but it's been
> difficult to add without getting in the way of development and backports.

Don't worry about backports for stable, we can handle that. Development
for fixes or changes should NEVER worry about stable kernels, worst
case, we can just take all of the same changes into them, no problem.

> Maybe a gradual replacement makes more sense, not sure how to go about this.

Just rename it all.

thanks,

greg k-h

2024-03-27 08:13:28

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 0/7] Soundwire: clean up sysfs group creation

On Wed, Jan 31, 2024 at 06:34:15PM +0530, Vinod Koul wrote:
> On 30-01-24, 10:46, Greg Kroah-Hartman wrote:
> > Note, this is a redone version of a very old series I wrote back in
> > 2022:
> > https://lore.kernel.org/r/[email protected]
> > but everyone has forgotten about it now, and I've reworked it, so I'm
> > considering it a "new" version, and not v2.
> >
> > Here's a series that adds the functionality to the driver core to hide
> > entire attribute groups, in a much saner way than we have attempted in
> > the past (i.e. dynamically figuring it out.) Many thanks to Dan for
> > this patch. I'll also be taking this into my driver-core branch and
> > creating a stable tag for anyone else to pull from to get it into their
> > trees, as I think it will want to be in many for this development cycle.
> >
> > After the driver core change, there's cleanups to the soundwire core for
> > how the attribute groups are created, to remove the "manual" creation of
> > them, and allow the driver core to create them correctly, as needed,
> > when needed, which makes things much smaller for the soundwire code to
> > manage.
>
> The series lgtm, having the core handle these would be good. I will wait
> couple of days for people to test this and give a t-b and apply.
> I hope it is okay if patch1 goes thru sdw tree?

patch 1 is now in Linus's tree, so the remaining ones can go through the
your tree now if you want. Or I can resend them if needed, just let me
know.

thanks,

greg k-h

2024-03-27 14:30:45

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/7] Soundwire: clean up sysfs group creation

On 27-03-24, 09:13, Greg Kroah-Hartman wrote:
> On Wed, Jan 31, 2024 at 06:34:15PM +0530, Vinod Koul wrote:
> > On 30-01-24, 10:46, Greg Kroah-Hartman wrote:
> > > Note, this is a redone version of a very old series I wrote back in
> > > 2022:
> > > https://lore.kernel.org/r/[email protected]
> > > but everyone has forgotten about it now, and I've reworked it, so I'm
> > > considering it a "new" version, and not v2.
> > >
> > > Here's a series that adds the functionality to the driver core to hide
> > > entire attribute groups, in a much saner way than we have attempted in
> > > the past (i.e. dynamically figuring it out.) Many thanks to Dan for
> > > this patch. I'll also be taking this into my driver-core branch and
> > > creating a stable tag for anyone else to pull from to get it into their
> > > trees, as I think it will want to be in many for this development cycle.
> > >
> > > After the driver core change, there's cleanups to the soundwire core for
> > > how the attribute groups are created, to remove the "manual" creation of
> > > them, and allow the driver core to create them correctly, as needed,
> > > when needed, which makes things much smaller for the soundwire code to
> > > manage.
> >
> > The series lgtm, having the core handle these would be good. I will wait
> > couple of days for people to test this and give a t-b and apply.
> > I hope it is okay if patch1 goes thru sdw tree?
>
> patch 1 is now in Linus's tree, so the remaining ones can go through the
> your tree now if you want. Or I can resend them if needed, just let me
> know.

Great, I was about to ask about this. If there is no conflicts I can
pick this series (looking at folks for giving me a t-b)

--
~Vinod

2024-03-28 12:24:23

by Vijendar Mukunda

[permalink] [raw]
Subject: Re: [PATCH 0/7] Soundwire: clean up sysfs group creation

On 27/03/24 18:21, Vinod Koul wrote:
> On 27-03-24, 09:13, Greg Kroah-Hartman wrote:
>> On Wed, Jan 31, 2024 at 06:34:15PM +0530, Vinod Koul wrote:
>>> On 30-01-24, 10:46, Greg Kroah-Hartman wrote:
>>>> Note, this is a redone version of a very old series I wrote back in
>>>> 2022:
>>>> https://lore.kernel.org/r/[email protected]
>>>> but everyone has forgotten about it now, and I've reworked it, so I'm
>>>> considering it a "new" version, and not v2.
>>>>
>>>> Here's a series that adds the functionality to the driver core to hide
>>>> entire attribute groups, in a much saner way than we have attempted in
>>>> the past (i.e. dynamically figuring it out.) Many thanks to Dan for
>>>> this patch. I'll also be taking this into my driver-core branch and
>>>> creating a stable tag for anyone else to pull from to get it into their
>>>> trees, as I think it will want to be in many for this development cycle.
>>>>
>>>> After the driver core change, there's cleanups to the soundwire core for
>>>> how the attribute groups are created, to remove the "manual" creation of
>>>> them, and allow the driver core to create them correctly, as needed,
>>>> when needed, which makes things much smaller for the soundwire code to
>>>> manage.
>>> The series lgtm, having the core handle these would be good. I will wait
>>> couple of days for people to test this and give a t-b and apply.
>>> I hope it is okay if patch1 goes thru sdw tree?
>> patch 1 is now in Linus's tree, so the remaining ones can go through the
>> your tree now if you want. Or I can resend them if needed, just let me
>> know.
> Great, I was about to ask about this. If there is no conflicts I can
> pick this series (looking at folks for giving me a t-b)
Applied this patch series on top of soundwire git tree and validated SoundWire
stack on AMD platform using command line alsa utils. All use cases are working
fine. Tested-By: Vijendar Mukunda <[email protected]>

>


2024-03-28 18:15:54

by Vinod Koul

[permalink] [raw]
Subject: Re: (subset) [PATCH 0/7] Soundwire: clean up sysfs group creation


On Tue, 30 Jan 2024 10:46:26 -0800, Greg Kroah-Hartman wrote:
> Note, this is a redone version of a very old series I wrote back in
> 2022:
> https://lore.kernel.org/r/[email protected]
> but everyone has forgotten about it now, and I've reworked it, so I'm
> considering it a "new" version, and not v2.
>
> Here's a series that adds the functionality to the driver core to hide
> entire attribute groups, in a much saner way than we have attempted in
> the past (i.e. dynamically figuring it out.) Many thanks to Dan for
> this patch. I'll also be taking this into my driver-core branch and
> creating a stable tag for anyone else to pull from to get it into their
> trees, as I think it will want to be in many for this development cycle.
>
> [...]

Applied, thanks!

[2/6] soundwire: sysfs: move sdw_slave_dev_attr_group into the existing list of groups
commit: b1b11bb07898b7e0313438734c310100219e676f
[3/6] soundwire: sysfs: cleanup the logic for creating the dp0 sysfs attributes
commit: 3ee43f7cc9841cdf3f2bec2de4b1e729fd17e303
[4/6] soundwire: sysfs: have the driver core handle the creation of the device groups
commit: fc7e56017b51482f1b9da2e778eedb4bd1deb6b3
[5/6] soundwire: sysfs: remove sdw_slave_sysfs_init()
commit: f88c1afe338edbcbfd23743742c45581075fb86c
[6/6] soundwire: sysfs: remove unneeded ATTRIBUTE_GROUPS() comments
commit: 91c4dd2e5c9066577960c7eef7dd8e699220c85e

Best regards,
--
~Vinod