linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Cercueil <paul@crapouillou.net>
To: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio <linux-iio@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: core: Support reading extended name as label
Date: Thu, 17 Jun 2021 10:08:02 +0100	[thread overview]
Message-ID: <ED9UUQ.EDOA8S56T8BP@crapouillou.net> (raw)
In-Reply-To: <CA+U=DsrP6+Zjnca8Sqd0jAi9a4aDqAV4suJZc95ayqm7K0+mCw@mail.gmail.com>

Hi Alexandru,

Le jeu., juin 17 2021 at 10:22:35 +0300, Alexandru Ardelean 
<ardeleanalex@gmail.com> a écrit :
> On Wed, Jun 16, 2021 at 7:00 PM Paul Cercueil <paul@crapouillou.net> 
> wrote:
>> 
>>  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.
>> 
> 
> The best way would have been for all drivers [using extend_name] to
> implement their own read_label hook.

Let's agree to disagree :)

> But this can work fine as well [as the other method would add some 
> duplication].
> 
>>  Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>  ---
>>   drivers/iio/industrialio-core.c | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>> 
>>  diff --git a/drivers/iio/industrialio-core.c 
>> b/drivers/iio/industrialio-core.c
>>  index 81f40dab778a..9b37e96538c2 100644
>>  --- a/drivers/iio/industrialio-core.c
>>  +++ b/drivers/iio/industrialio-core.c
>>  @@ -717,8 +717,12 @@ static ssize_t iio_read_channel_label(struct 
>> device *dev,
>>          struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>>          struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>> 
>>  -       if (!indio_dev->info->read_label)
>>  -               return -EINVAL;
>>  +       if (!indio_dev->info->read_label) {
>>  +               if (this_attr->c->extend_name)
>>  +                       return sprintf(buf, "%s\n", 
>> this_attr->c->extend_name);
>>  +               else
> 
> nitpick: else statement has no effect
> 
> well, this block could be reworked a bit as:
> 
> ----------------------------------------------------
> if (indio_dev->info->read_label)
>    return indio_dev->info->read_label(indio_dev, this_attr->c, buf);
> 
> if (this_attr->c->extend_name)
>     return sprintf(buf, "%s\n", this_attr->c->extend_name);
> 
> return -EINVAL;
> ----------------------------------------------------

I generally prefer to make the diff as small as possible so that the 
changes are more obvious. But this does look better.

-Paul

> 
>>  +                       return -EINVAL;
>>  +       }
>> 
>>          return indio_dev->info->read_label(indio_dev, this_attr->c, 
>> buf);
>>   }
>>  @@ -1160,7 +1164,7 @@ static int 
>> iio_device_add_channel_label(struct iio_dev *indio_dev,
>>          struct iio_dev_opaque *iio_dev_opaque = 
>> to_iio_dev_opaque(indio_dev);
>>          int ret;
>> 
>>  -       if (!indio_dev->info->read_label)
>>  +       if (!indio_dev->info->read_label && !chan->extend_name)
>>                  return 0;
>> 
>>          ret = __iio_add_chan_devattr("label",
>>  --
>>  2.30.2
>> 



      reply	other threads:[~2021-06-17  9:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 15:57 [PATCH v2 0/2] Add "extended_name" to label Paul Cercueil
2021-06-16 15:57 ` [PATCH v2 1/2] iio: core: Forbid use of both labels and extended names Paul Cercueil
2021-06-17  7:07   ` Alexandru Ardelean
2021-06-16 15:57 ` [PATCH v2 2/2] iio: core: Support reading extended name as label Paul Cercueil
2021-06-17  7:22   ` Alexandru Ardelean
2021-06-17  9:08     ` Paul Cercueil [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ED9UUQ.EDOA8S56T8BP@crapouillou.net \
    --to=paul@crapouillou.net \
    --cc=ardeleanalex@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH v2 2/2] iio: core: Support reading extended name as label' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).