From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A944C04A6B for ; Wed, 8 May 2019 11:19:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2D2121655 for ; Wed, 8 May 2019 11:19:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=analog.onmicrosoft.com header.i=@analog.onmicrosoft.com header.b="lBhk7qhG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727472AbfEHLTy (ORCPT ); Wed, 8 May 2019 07:19:54 -0400 Received: from mail-eopbgr720060.outbound.protection.outlook.com ([40.107.72.60]:53352 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726254AbfEHLTx (ORCPT ); Wed, 8 May 2019 07:19:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t8Gpn5zKRV9ExKalhlYK3NE8SPPieqAU5p6PlMZIP/I=; b=lBhk7qhGM/ybnMCTJ0HQTthYMooVdbbGydbJNKxF82NBdwD1Ax3VUHcJNQXH8jPvqMxXOhCqCS5j0bq5AdltPfhAs42lAi01Ilimdp/KBBAl90gjR8vZBh15zqzKKI4Jdb55+FooIBIk63mJJcrDB5E3KuoeebriPq54X3tGDdU= Received: from DM6PR03CA0033.namprd03.prod.outlook.com (2603:10b6:5:40::46) by SN2PR03MB2270.namprd03.prod.outlook.com (2603:10b6:804:d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.10; Wed, 8 May 2019 11:19:50 +0000 Received: from BL2NAM02FT057.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::205) by DM6PR03CA0033.outlook.office365.com (2603:10b6:5:40::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1856.11 via Frontend Transport; Wed, 8 May 2019 11:19:50 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BL2NAM02FT057.mail.protection.outlook.com (10.152.77.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1856.11 via Frontend Transport; Wed, 8 May 2019 11:19:49 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id x48BJndi020836 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Wed, 8 May 2019 04:19:49 -0700 Received: from saturn.analog.com (10.50.1.244) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Wed, 8 May 2019 07:19:49 -0400 From: Alexandru Ardelean To: , , CC: , , , , Alexandru Ardelean Subject: [PATCH 3/3][V3] iio: Handle enumerated properties with gaps Date: Wed, 8 May 2019 14:19:13 +0300 Message-ID: <20190508111913.7276-3-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190508111913.7276-1-alexandru.ardelean@analog.com> References: <20190508111913.7276-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Type: text/plain X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(39860400002)(376002)(346002)(136003)(2980300002)(54534003)(199004)(189003)(86362001)(70586007)(50466002)(446003)(11346002)(478600001)(36756003)(126002)(50226002)(486006)(476003)(2616005)(186003)(26005)(77096007)(44832011)(426003)(246002)(8676002)(8936002)(5660300002)(336012)(1076003)(316002)(2201001)(7696005)(6666004)(356004)(76176011)(51416003)(70206006)(53416004)(106002)(7636002)(305945005)(107886003)(16586007)(4326008)(54906003)(2906002)(47776003)(48376002)(110136005);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2270;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;A:1;MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83806e9e-e88b-4c84-71aa-08d6d3a715cd X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4709054)(2017052603328);SRVR:SN2PR03MB2270; X-MS-TrafficTypeDiagnostic: SN2PR03MB2270: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2331; X-Forefront-PRVS: 0031A0FFAF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: cXn6UES+7eIPV7nYnZHu8fGJBqx/H2nXan2QDqoU28pNm2x7KqwQVaqEAZ+ATnvJVlqkyExWWe7n51UBIy0RYzKxBAwTcyw1M9IlU5YMwv4rxhlr1UV6AvA+Pd9B4aPYoauvqqb2bX+RKPwMMp45H5lidPuDVJZoaQG2zo/1a+3jVFjcYrjJeItyenFvitL1IhIdJOtZH1f8MlYaH+a3ePhqLiiFOikIkBnMfl0WqCHZbJVZ58UcWtHKEPfXW/U3PmWCZ0EzcnZR6LDgT1GXi0wxO32lieYPgyPLqDs/9levnVIcWtPPlirWgdN2v828/Rxw2RYRk150S1U99LAFz4iRPmKXRj0GOZqG821oBYgOcAu6+QiPnqpfJH4tCduF+3ctVIp2SoUR9ka+SeMs1Y2IuQdyOiHp4mxIWIB+0xA= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2019 11:19:49.7327 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83806e9e-e88b-4c84-71aa-08d6d3a715cd X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2270 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@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. Also, `__sysfs_match_string()` now supports NULL gaps, so that doesn't require any changes. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean --- Changelog v2 -> v3: * after fixing __sysfs_match_string(), this change only requires that NULL be handled in the iio_enum_{available_}read functions __sysfs_match_string() handles the NULL gaps drivers/iio/industrialio-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 9c4d92115504..8b4ff3c8f547 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -446,8 +446,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'; @@ -468,7 +471,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]); -- 2.17.1