iio: core: Support reading extended name as label
authorPaul Cercueil <paul@crapouillou.net>
Fri, 18 Jun 2021 12:30:05 +0000 (13:30 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 19 Jul 2021 08:51:59 +0000 (09:51 +0100)
commit13efdc3dc9030972c81285e2dbdeac1f9cef880d
tree05ed12a583c3b8516771f72cb0c2662835508431
parent0e0761f86f10253425edac56df9950c172b923ea
iio: core: Support reading extended name as label

The point of this new change is to make the IIO tree actually parsable.

Before, given this attribute as a filename:
in_voltage0_aux_sample_rate

Userspace had no way to know if the attribute name was
"aux_sample_rate" with no extended name, or "sample_rate" with "aux" as
the extended name, or just "rate" with "aux_sample" as the extended
name.

This was somewhat possible to deduce when there was more than one
attribute present for a given channel, e.g:
in_voltage0_aux_sample_rate
in_voltage0_aux_frequency

There, it was possible to deduce that "aux" was the extended name. But
even with more than one attribute, this wasn't very robust, as two
attributes starting with the same prefix (e.g. "sample_rate" and
"sample_size") would result in the first part of the prefix being
interpreted as being part of the extended name.

To address the issue, knowing that channels will never have both a label
and an extended name, set the channel's label to the extended name.
In this case, the label's attribute will also have the extended name in
its filename, but we can live with that - userspace can open
in_voltage0_<prefix>_label and verify that it returns <prefix> to obtain
the extended name.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20210618123005.49867-3-paul@crapouillou.net
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-core.c