Skip to content

Commit 3ee43f7

Browse files
gregkhvinodkoul
authored andcommitted
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]> Reviewed-by: Dan Williams <[email protected]> Tested-By: Vijendar Mukunda <[email protected]> Link: https://lore.kernel.org/r/2024013029-budget-mulled-5b34@gregkh Signed-off-by: Vinod Koul <[email protected]>
1 parent b1b11bb commit 3ee43f7

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

drivers/soundwire/sysfs_slave.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,40 @@ static struct attribute *dp0_attrs[] = {
184184
NULL,
185185
};
186186

187+
static umode_t dp0_attr_visible(struct kobject *kobj, struct attribute *attr,
188+
int n)
189+
{
190+
struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
191+
192+
if (slave->prop.dp0_prop)
193+
return attr->mode;
194+
return 0;
195+
}
196+
197+
static bool dp0_group_visible(struct kobject *kobj)
198+
{
199+
struct sdw_slave *slave = dev_to_sdw_dev(kobj_to_dev(kobj));
200+
201+
if (slave->prop.dp0_prop)
202+
return true;
203+
return false;
204+
}
205+
DEFINE_SYSFS_GROUP_VISIBLE(dp0);
206+
187207
/*
188208
* we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
189209
* for dp0-level properties
190210
*/
191211
static const struct attribute_group dp0_group = {
192212
.attrs = dp0_attrs,
213+
.is_visible = SYSFS_GROUP_VISIBLE(dp0),
193214
.name = "dp0",
194215
};
195216

196217
static const struct attribute_group *slave_groups[] = {
197218
&slave_attr_group,
198219
&sdw_slave_dev_attr_group,
220+
&dp0_group,
199221
NULL,
200222
};
201223

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

210-
if (slave->prop.dp0_prop) {
211-
ret = devm_device_add_group(&slave->dev, &dp0_group);
212-
if (ret < 0)
213-
return ret;
214-
}
215-
216232
if (slave->prop.source_ports || slave->prop.sink_ports) {
217233
ret = sdw_slave_sysfs_dpn_init(slave);
218234
if (ret < 0)

0 commit comments

Comments
 (0)