diff options
author | Miquel Raynal <miquel.raynal@bootlin.com> | 2023-06-14 08:30:16 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-06-15 13:37:53 +0200 |
commit | a91845b9a872039618d74104c0721376ce092638 (patch) | |
tree | d4452a56aa3ce123c5ad595cc62bf31482d3b25c /drivers/iio | |
parent | 4981e0139feeadb1cdffd43a203543afe20769fa (diff) | |
download | linux-stable-a91845b9a872039618d74104c0721376ce092638.tar.gz linux-stable-a91845b9a872039618d74104c0721376ce092638.tar.bz2 linux-stable-a91845b9a872039618d74104c0721376ce092638.zip |
sysfs: Skip empty folders creation
Most sysfs attributes are statically defined, the goal with this design
being to be able to move all the filesystem description into read-only
memory. Anyway, it may be relevant in some cases to populate attributes
at run time. This leads to situation where an attribute may or may not be
present depending on conditions which are not known at compile
time, up to the point where no attribute at all gets added in a folder
which then becomes "sometimes" empty. Problem is, providing an attribute
group with a name and without .[bin_]attrs members will be loudly
refused by the core, leading in most cases to a device registration
failure.
The simple way to support such situation right now is to dynamically
allocate an empty attribute array, which is:
* a (small) waste of space
* a waste of time
* disturbing, to say the least, as an empty sysfs folder will be created
anyway.
Another (even worse) possibility would be to dynamically overwrite a
member of the attribute_group list, hopefully the last, which is also
supposed to remain in the read-only section.
In order to avoid these hackish situations, while still giving a little
bit of flexibility, we might just check the validity of the .[bin_]attrs
list and, if empty, just skip the attribute group creation instead of
failing. This way, developers will not be tempted to workaround the
core with useless allocations or strange writes on supposedly read-only
structures.
The content of the WARN() message is kept but turned into a debug
message in order to help developers understanding why their sysfs
folders might now silently fail to be created.
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Message-ID: <20230614063018.2419043-3-miquel.raynal@bootlin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/iio')
0 files changed, 0 insertions, 0 deletions