Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp486776pxj; Thu, 10 Jun 2021 05:48:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJ9GQzDx+5/2F/wr6jAzLtwYlNj8FKYbSHSNu/Ws/lvQ75aa2scQ6/DnXgeszTfuTBK/5Z X-Received: by 2002:a50:9b06:: with SMTP id o6mr4616622edi.284.1623329332180; Thu, 10 Jun 2021 05:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623329332; cv=none; d=google.com; s=arc-20160816; b=Am3kNh12S+Icq9Rw9neQRfTJZ83bfguM3QBhf1vdBHYIF4lOwNcA1fCYE3QWC/rad/ flemj2uuR6xCvCTp2IhHbDfAx4f8Mi+1qg1fQmSlR9M1Tf+Me8alS1BJt4ShQ/9L5JUM XyrO72W7i2rqVWfzfXZxeUUgtzUwU6JXkVSeZKbTX3DAM4SSAFuqLje2bvfKkAvD3FIg qss8QnYa64x/CvfnZ8tRqRe44GdUPjWFf//3SbK3vBdtZPY1hg2+gyr2Jl2g7Gv5PlI5 eb2KVqUM+iKyOu3uar5buLTg+f0VTVbW4Arhzv9t26Gf8d6yKrp+DoDQP7zaf2nPQXXZ Dmig== 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:date:subject:cc:to:from; bh=Xa17M9o2YdCxp2/1zIGN3abOsKhnSWyPQ8uno3qwnew=; b=nEfIAgFYvoS9RvdBx8cOPXfIrTVzvioJvY2hkkFHx0s3t57ANSnNV7403+Zw+uzLZ3 jSS27hRLIwxFSIA48h5LTuamtEMJgvuloQ02RZirEw0OvjFDVmT3teQhpZMZV/AraumH 8ezpBWr7KbqEGRp0dAyOhWsQrFBfm1wg1E741lMLm2pgRnoNQRd6ytI+e/og/RvxB+f2 gmNuSdCvqW+QXUInXZe01f3iZlphX9xdRUOHNQ1xW31HDdww2TRZclggsX7qaKT5HCkL gLma/C3287BEHbHN/2qj5TWCVfi50MlS5lewAOnZFNMTSU90aDnp3mVmepswZxbllYYn IZrA== 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 cq10si2036640edb.358.2021.06.10.05.48.29; Thu, 10 Jun 2021 05:48:52 -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 S230393AbhFJMsU (ORCPT + 99 others); Thu, 10 Jun 2021 08:48:20 -0400 Received: from aposti.net ([89.234.176.197]:54540 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbhFJMsS (ORCPT ); Thu, 10 Jun 2021 08:48:18 -0400 From: Paul Cercueil To: Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH 2/2] iio: core: Add "extended_name" attribute to all channels Date: Thu, 10 Jun 2021 13:45:56 +0100 Message-Id: <20210610124556.34507-3-paul@crapouillou.net> In-Reply-To: <20210610124556.34507-1-paul@crapouillou.net> References: <20210610124556.34507-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The point of this new attribute 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 this issue, add an "extended_name" attribute to all channels that actually do have an extended name. For this attribute, the extended name is not present in the filename; so in this example, the file name would be "in_voltage0_extended_name", and reading it would return "aux". Signed-off-by: Paul Cercueil --- drivers/iio/industrialio-core.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index ec34d930920c..4cdf9f092d73 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -723,6 +723,16 @@ static ssize_t iio_read_channel_label(struct device *dev, return indio_dev->info->read_label(indio_dev, this_attr->c, buf); } +static ssize_t iio_read_channel_extended_name(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + const struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + const struct iio_chan_spec *chan = this_attr->c; + + return sprintf(buf, "%s\n", chan->extend_name); +} + static ssize_t iio_read_channel_info(struct device *dev, struct device_attribute *attr, char *buf) @@ -1185,6 +1195,32 @@ static int iio_device_add_channel_label(struct iio_dev *indio_dev, return 1; } +static int +iio_device_add_channel_extended_name(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan) +{ + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); + int ret; + + if (!chan->extend_name) + return 0; + + ret = __iio_add_chan_devattr("extended_name", + chan, + &iio_read_channel_extended_name, + NULL, + 0, + IIO_SEPARATE, + &indio_dev->dev, + NULL, + &iio_dev_opaque->channel_attr_list, + false); + if (ret < 0) + return ret; + + return 1; +} + static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, enum iio_shared_by shared_by, @@ -1327,6 +1363,11 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev, return ret; attrcount += ret; + ret = iio_device_add_channel_extended_name(indio_dev, chan); + if (ret < 0) + return ret; + attrcount += ret; + if (chan->ext_info) { unsigned int i = 0; for (ext_info = chan->ext_info; ext_info->name; ext_info++) { -- 2.30.2