Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4833286pxu; Tue, 22 Dec 2020 01:50:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBNtLFnOSX+X2+tt2ZX/DvBqQWv8chjKpi7ZNycUlcn13UWBRDCYN6G89gd81OOzckS4cU X-Received: by 2002:a17:906:3101:: with SMTP id 1mr6228224ejx.115.1608630657000; Tue, 22 Dec 2020 01:50:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608630656; cv=none; d=google.com; s=arc-20160816; b=KBtIPSCwtjDZviisZd9u8RzYb8tn05VUriAcINhxSZNBv9Hi1++u7zqEqs15nhZKE2 TBzimcJEzLDrfsrCm0DeIK1lzuVQCtMbdQTdWyxEIN2ewfx3fBhFLSJ1xW4SfmGoDj+r sP97p7AAVoH4aaM5w4ifrNU5CY5r6bODX5pvppZv59G3uT8yyBdLrSPZAu88/+LOQm2C NA94HEC6B6okHwFo+l9gKlveu5mI1J7FYX1O+1/J2uur5VVC+5OlRCNZFe0e/0URPHpf eAIy7yUzD5Qly5gyr9xmizeSzKcLPkGnFaGeBw6lNMUqf7qIBjkQhC7SG/ZqP7lipYb1 gNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=yU+GiOs+/dNgKuZVvK27cKu2+lDJewxYoud/3XrQRtw=; b=G5RDpbTpyOo5++rdUNxic/tCG76SKNnBWbI1I8enGDpA6D96cXULIVFi4dLSrvnsIW 2bJG8jycldF7P6jSK7OTf3BMwiO7c/pEvxhHl1TZ+0Das9OVZ1vMMJ/w9IKnVq61oMhx PkwwFK0r3Sb1xdm900uFMkmLa4qoHpfWizpa5XeRHY8iOCSWrEcPTTElRGPQYodjZH3L 0X+99HTMQHoJQvEWLmDYLgiCIDm0cLMCYYrC6vrws/wV+AfIdOkzB8tzTVeFSCuH4JRt 5ig7ro1HJ0BzXRt3bM03IS6wy9yWc5DGgDh46kL2dl8BK1SMRIL5cxhyfnXR4E+4ggKb QInA== 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=analog.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si12080341edb.419.2020.12.22.01.50.34; Tue, 22 Dec 2020 01:50:56 -0800 (PST) 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=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725985AbgLVJtF (ORCPT + 99 others); Tue, 22 Dec 2020 04:49:05 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:10758 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725300AbgLVJtF (ORCPT ); Tue, 22 Dec 2020 04:49:05 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BM9f0Sa027727; Tue, 22 Dec 2020 04:48:11 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 35k0e11wb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 04:48:10 -0500 Received: from SCSQMBX11.ad.analog.com (SCSQMBX11.ad.analog.com [10.77.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 0BM9m89c061852 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 22 Dec 2020 04:48:09 -0500 Received: from SCSQCASHYB7.ad.analog.com (10.77.17.133) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Tue, 22 Dec 2020 01:48:07 -0800 Received: from SCSQMBX11.ad.analog.com (10.77.17.10) by SCSQCASHYB7.ad.analog.com (10.77.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.721.2; Tue, 22 Dec 2020 01:48:07 -0800 Received: from zeus.spd.analog.com (10.66.68.11) by SCSQMBX11.ad.analog.com (10.77.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Tue, 22 Dec 2020 01:48:07 -0800 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 0BM9m2pL002106; Tue, 22 Dec 2020 04:48:04 -0500 From: Alexandru Ardelean To: , CC: , , , , , Alexandru Ardelean Subject: [PATCH v5 2/2] iio: Handle enumerated properties with gaps Date: Tue, 22 Dec 2020 11:52:10 +0200 Message-ID: <20201222095210.61897-2-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222095210.61897-1-alexandru.ardelean@analog.com> References: <20201222095210.61897-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Type: text/plain X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 bulkscore=0 mlxlogscore=822 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012220073 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen Some enums might have gaps or reserved values in the middle of their value range. E.g. consider a 2-bit enum where the values 0, 1 and 3 have a meaning, but 2 is a reserved value and can not be used. Add support for such enums to the IIO enum helper functions. A reserved values is marked by setting its entry in the items array to NULL rather than the normal descriptive string value. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean --- drivers/iio/industrialio-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index e9ee9363fed0..5f6211bfb428 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -470,8 +470,11 @@ ssize_t iio_enum_available_read(struct iio_dev *indio_dev, if (!e->num_items) return 0; - for (i = 0; i < e->num_items; ++i) + for (i = 0; i < e->num_items; ++i) { + if (!e->items[i]) + continue; len += scnprintf(buf + len, PAGE_SIZE - len, "%s ", e->items[i]); + } /* replace last space with a newline */ buf[len - 1] = '\n'; @@ -492,7 +495,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev, i = e->get(indio_dev, chan); if (i < 0) return i; - else if (i >= e->num_items) + else if (i >= e->num_items || !e->items[i]) return -EINVAL; return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]); @@ -509,7 +512,7 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev, if (!e->set) return -EINVAL; - ret = __sysfs_match_string(e->items, e->num_items, buf); + ret = __sysfs_match_string_with_gaps(e->items, e->num_items, buf); if (ret < 0) return ret; -- 2.17.1