Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <vkoul@kernel.org>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: Sanyog Kale <sanyog.r.kale@intel.com>
Cc: alsa-devel@alsa-project.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Tested-By: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://lore.kernel.org/r/2024013029-budget-mulled-5b34@gregkh
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Greg Kroah-Hartman and committed by
Vinod Koul
3ee43f7c b1b11bb0

+22 -6
+22 -6
drivers/soundwire/sysfs_slave.c
··· 184 184 NULL, 185 185 }; 186 186 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 + 187 207 /* 188 208 * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory 189 209 * for dp0-level properties 190 210 */ 191 211 static const struct attribute_group dp0_group = { 192 212 .attrs = dp0_attrs, 213 + .is_visible = SYSFS_GROUP_VISIBLE(dp0), 193 214 .name = "dp0", 194 215 }; 195 216 196 217 static const struct attribute_group *slave_groups[] = { 197 218 &slave_attr_group, 198 219 &sdw_slave_dev_attr_group, 220 + &dp0_group, 199 221 NULL, 200 222 }; 201 223 ··· 228 206 ret = devm_device_add_groups(&slave->dev, slave_groups); 229 207 if (ret < 0) 230 208 return ret; 231 - 232 - if (slave->prop.dp0_prop) { 233 - ret = devm_device_add_group(&slave->dev, &dp0_group); 234 - if (ret < 0) 235 - return ret; 236 - } 237 209 238 210 if (slave->prop.source_ports || slave->prop.sink_ports) { 239 211 ret = sdw_slave_sysfs_dpn_init(slave);