Issue
Following this tutorial, I assumed that I can simply assign my attribute group to the default attribute group like so:
static DEVICE_ATTR_RO(status);
static struct attribute *my_dev_attrs[] = {
&dev_attr_status.attr,
NULL
};
ATTRIBUTE_GROUPS(my_dev);
static int probe(struct spi_device *spi) {
...
spi->dev.groups = my_dev_groups;
...
}
But no file appears at /sys/bus/spi/drivers/my_dev/spi2.0
.
However, when I define the attribute like so:
int ret
ret = sysfs_create_group(&spi->dev.kobj, &my_dev_group);
if (ret < 0)
return ret;
I can see and correctly access the file at /sys/bus/spi/drivers/my_dev/spi2.0
. Is there any further setup required for the first option?
Solution
The .groups
field of the struct device
is not supposed to be used or assigned directly. The idea behind is to provide the static attribute groups and assign them via .dev_groups
member of the respective struct driver
. See, for example, this code.
With that done, the driver core will take care of creating and removing them in a non-racy manner (that's why that field was appeared to begin with).
Answered By - 0andriy Answer Checked By - Terry (WPSolving Volunteer)