Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp266414pxj; Thu, 17 Jun 2021 02:10:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo+Puy3uKG0bxO0TolFfxCXJHnQhQDDBAarnGsrq+F43ZpcjvJOfmRP/AdK3mkl9cIfYgg X-Received: by 2002:a17:906:dbee:: with SMTP id yd14mr4274051ejb.49.1623921014775; Thu, 17 Jun 2021 02:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623921014; cv=none; d=google.com; s=arc-20160816; b=W0LQussnNsSq61dE5HCct8T9oIjte3FLGJUVcKSMlyam6wARfJephDbB5otLM8Khfu BMYl39pBmbcU2uF1qfJ57CFiz5yt8MmXFt/thxBfeYfk75fJTXs4u67jzDF4roic1skk wf8wqsYFus+BagZAupBWkfvRve9b7S3sj+2Sc3qMYH/EYYyF0jRglbf4yTXiMS7aYhk1 REWi3yVrBj+aZ1DmP8njzngsyPaIReEO2VfszljP2Rny1PLbUkxFK5O7A3I6kC3TPSby bA+yoVZOAzx4EDOtviOJQ+nXTl0G1IhTv6iOcgPMz+yBUbP+/5a6OuKPv+B+f99MiWlC aMDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:cc:to:subject:from:date; bh=QI/bZAq6M0YILKbfMaA41EV2I30IT9VGUifncxvDZYI=; b=beIvoSZIeHnvS7SOtOOIKKwNkpYeJUW0E3rnVtmesTQaxQP7ZxdVd3mwtoLhZ4+yAg kJUF30ebuXz6VN1r+vwx14ni/jo5sbaMI3x3RwcodDm+a5PwVH9VpxinzvPK8qjA0aH8 mD8xQ3hx1Mqt/yYcJ/ZKi2HPEVqgduLXPtkOzTa5tFVC6V589R1ExHn4/I16+vyt/OmW 8nQ2MNACEk++P3BJ5DQzAZpPo+OxGENRyiIUQ+Mv63V7ekmokM794jCsMkBCPdQOvjGt 82ZcNmGfKnteyaNqeTEWUyjDXafteV4i1bcftmzmVgeQuHHymVGLp+4vr9bVZQ4Q5IBE 0S7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si5895344ejt.474.2021.06.17.02.09.51; Thu, 17 Jun 2021 02:10:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231390AbhFQJKV convert rfc822-to-8bit (ORCPT + 99 others); Thu, 17 Jun 2021 05:10:21 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:46393 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbhFQJKU (ORCPT ); Thu, 17 Jun 2021 05:10:20 -0400 Received: (Authenticated sender: paul@opendingux.net) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 5B3051BF208; Thu, 17 Jun 2021 09:08:09 +0000 (UTC) Date: Thu, 17 Jun 2021 10:08:02 +0100 From: Paul Cercueil Subject: Re: [PATCH v2 2/2] iio: core: Support reading extended name as label To: Alexandru Ardelean Cc: Jonathan Cameron , Lars-Peter Clausen , linux-iio , LKML Message-Id: In-Reply-To: References: <20210616155706.17444-1-paul@crapouillou.net> <20210616155706.17444-3-paul@crapouillou.net> X-Mailer: geary/40.0 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandru, Le jeu., juin 17 2021 at 10:22:35 +0300, Alexandru Ardelean a ?crit : > On Wed, Jun 16, 2021 at 7:00 PM Paul Cercueil > 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__label and verify that it returns 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 >> --- >> 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 >>