From patchwork Wed May 8 11:19:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10934995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7381B92A for ; Wed, 8 May 2019 11:19:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62967285F0 for ; Wed, 8 May 2019 11:19:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5647D2875C; Wed, 8 May 2019 11:19:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9E76285F0 for ; Wed, 8 May 2019 11:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727407AbfEHLTu (ORCPT ); Wed, 8 May 2019 07:19:50 -0400 Received: from mail-eopbgr770082.outbound.protection.outlook.com ([40.107.77.82]:39494 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726254AbfEHLTu (ORCPT ); Wed, 8 May 2019 07:19:50 -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=VHpMFIYfp33T4yjqGwUYX04XSxeEs1fQxYo0IECcn6U=; b=LO8k/fW1ANcSwRP0j0ubwP564tLQ5YLtyBsJuTF3c6wqdVRWviCt92D7r9cJNB2Y7T5r7MuVWaEdaQ0wE93FYADwTjraNoZ1YHh7ZZmiNaVSgoa3VJuh5dlC8gG4gAHW7XFmf9a//diWL/MsOSLjP78SdpFknnSLEJOp7YiOJi4= Received: from MWHPR03CA0048.namprd03.prod.outlook.com (2603:10b6:301:3b::37) by MWHPR03MB3134.namprd03.prod.outlook.com (2603:10b6:301:3c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.11; Wed, 8 May 2019 11:19:46 +0000 Received: from BL2NAM02FT021.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::209) by MWHPR03CA0048.outlook.office365.com (2603:10b6:301:3b::37) 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:45 +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 BL2NAM02FT021.mail.protection.outlook.com (10.152.77.158) 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:45 +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 x48BJjmk020815 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Wed, 8 May 2019 04:19:45 -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:44 -0400 From: Alexandru Ardelean To: , , CC: , , , , Alexandru Ardelean Subject: [PATCH 1/3][V3] lib: fix __sysfs_match_string() helper when n != -1 Date: Wed, 8 May 2019 14:19:11 +0300 Message-ID: <20190508111913.7276-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 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)(376002)(39860400002)(136003)(396003)(346002)(2980300002)(54534003)(199004)(189003)(476003)(126002)(44832011)(2616005)(486006)(53416004)(478600001)(426003)(336012)(5660300002)(186003)(26005)(1076003)(77096007)(356004)(50466002)(305945005)(7636002)(6666004)(48376002)(2906002)(50226002)(47776003)(246002)(36756003)(8676002)(8936002)(14444005)(107886003)(16586007)(110136005)(316002)(2201001)(7696005)(4326008)(54906003)(106002)(70586007)(51416003)(86362001)(70206006);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR03MB3134;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: b38afcb6-23aa-410b-5035-08d6d3a71355 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4709054)(2017052603328);SRVR:MWHPR03MB3134; X-MS-TrafficTypeDiagnostic: MWHPR03MB3134: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 0031A0FFAF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: nzWa3xrxyHB1zEKTca8pGFwuk9fAlJRcfn+T8uniTYcp73YLJz+d7l4cT88khCBXiRqJ4cqZv20CjAKAVx4mH4Pivql+u4/COf0Wqr2umYp/XWJmlIECPpX38lFrtz+zKidzkkXUpS+IY8Cq2FxisVUg0ToNzluXGjuSWNzR2d6w0JDfk+5+BR2D7XKm2nJUHDjqxWagTzlmp+tniIb0g4oYkrPTgLvTQmnbc4wv1h1Wp95o58D8w0G4SLJucyUnh/k8yMmtPuTVLx007uTPLxVp63rd4r6Qr/dlBVX8wvJQy9j9n8DI+k3Kzo/EsuNqMpMnoxAgKhSX73gBunmNXp7Enprp0I9ZqDmrz/h0/e6w1VOB+zD3UKMZiiDvaEeCZmIfmfWoXp/cCPdr9gYK8WuF0Eo4Kl0sSm0AQsGXcT4= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2019 11:19:45.5920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b38afcb6-23aa-410b-5035-08d6d3a71355 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: MWHPR03MB3134 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The documentation the `__sysfs_match_string()` helper mentions that `n` (the size of the given array) should be: * @n: number of strings in the array or -1 for NULL terminated arrays The behavior of the function is different, in the sense that it exits on the first NULL element in the array. This patch changes the behavior, to exit the loop when a NULL element is found, and the size of the array is provided as -1. All current users of __sysfs_match_string() & sysfs_match_string() provide contiguous arrays of strings, so this behavior change doesn't influence anything (at this point in time). This behavior change allows for an array of strings to have NULL elements within the array, which will be ignored. This is particularly useful when creating mapping of strings and integers (as bitfields or other HW description). Signed-off-by: Alexandru Ardelean Acked-by: Jonathan Cameron --- Changelog v2 -> v3: * fix __sysfs_match_string() vs adding a new __sysfs_match_string_with_gaps() helper lib/string.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/string.c b/lib/string.c index 3ab861c1a857..5bea3f98478a 100644 --- a/lib/string.c +++ b/lib/string.c @@ -674,8 +674,11 @@ int __sysfs_match_string(const char * const *array, size_t n, const char *str) for (index = 0; index < n; index++) { item = array[index]; - if (!item) + if (!item) { + if (n != (size_t)-1) + continue; break; + } if (sysfs_streq(item, str)) return index; } From patchwork Wed May 8 11:19:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10935001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93A6A92A for ; Wed, 8 May 2019 11:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81EFB28508 for ; Wed, 8 May 2019 11:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 753C72875C; Wed, 8 May 2019 11:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AAE128508 for ; Wed, 8 May 2019 11:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727446AbfEHLTw (ORCPT ); Wed, 8 May 2019 07:19:52 -0400 Received: from mail-eopbgr750078.outbound.protection.outlook.com ([40.107.75.78]:14252 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726687AbfEHLTv (ORCPT ); Wed, 8 May 2019 07:19:51 -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=olDzzuypgQcrx2LT2HXtL+wN6aHOlC70Oa+Knk6YDdY=; b=AHwuNWgDmdKDE5Y9jwhSyHPdIoSLkpjXlJevIcs6e4kQrvxjv/54koBLnSseP1KUoApYFCGXmL5P3wo94BkylhJxoCZl0CaPd4sl8HuuEUObQqjjqMBUDa/2N/MOYo1FYVuMdg6Kq9btdixHhPi7UoZ4o9Ubblm0HZkjwn9n9us= Received: from CY4PR03CA0014.namprd03.prod.outlook.com (2603:10b6:903:33::24) by MWHPR03MB3133.namprd03.prod.outlook.com (2603:10b6:301:3c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1856.11; Wed, 8 May 2019 11:19:48 +0000 Received: from BL2NAM02FT013.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::202) by CY4PR03CA0014.outlook.office365.com (2603:10b6:903:33::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1878.21 via Frontend Transport; Wed, 8 May 2019 11:19:48 +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 BL2NAM02FT013.mail.protection.outlook.com (10.152.77.19) 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:47 +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 x48BJl3Y020832 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Wed, 8 May 2019 04:19:47 -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:47 -0400 From: Alexandru Ardelean To: , , CC: , , , , Alexandru Ardelean Subject: [PATCH 2/3][V3] scsi: sd: remove sysfs_match_string() dense array comment Date: Wed, 8 May 2019 14:19:12 +0300 Message-ID: <20190508111913.7276-2-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 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)(39860400002)(376002)(396003)(346002)(136003)(2980300002)(199004)(54534003)(189003)(4744005)(47776003)(4326008)(51416003)(6666004)(356004)(305945005)(77096007)(2616005)(26005)(8936002)(186003)(2201001)(7636002)(44832011)(126002)(476003)(486006)(2906002)(107886003)(8676002)(48376002)(5660300002)(86362001)(50466002)(70206006)(70586007)(426003)(16586007)(50226002)(7696005)(316002)(1076003)(76176011)(246002)(478600001)(36756003)(54906003)(446003)(53416004)(11346002)(106002)(110136005)(336012);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR03MB3133;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: 69215c09-c241-4e00-106a-08d6d3a714bc X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4709054)(2017052603328);SRVR:MWHPR03MB3133; X-MS-TrafficTypeDiagnostic: MWHPR03MB3133: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:619; X-Forefront-PRVS: 0031A0FFAF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: qx3sYVB0+bZLOrjZnhAu3bBksIZLgBvLT/eSIbjknw2/EOJfOLw2qIOStJGaDAYlignJYYqeqjINWKnAcxBeRN7dfYb1BoMpgT2QLheBKaYgZGTjhZ4BRfQnLa7geLDp11k86JTbTbGI2zxpmw9l8E2Z9EGIuN9Y5F9pWRN00o7H/UOyUN8+/UshEUUC91nlfvnioHKnOW+cExpA28PZyrrnZNc6S8WdjA5pK9c4MDHFWIJZWnc/5HmVKII+inl1mMIdn8jj5xZvtrisJFAdZGsz4jTxAQ4643xTCHtFJUM4vqWiSssDW2jlsrbpyqXGPX4EVyHTRyjYTBTC3ryNCChq18tQPLoJez3+2XB6iEVJpF9CqO9NwuL5RBKzKogO5nhglZcfBe52E8OwVxPHBi5i3aPyjruPNlmxhMYd1IY= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2019 11:19:47.9421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69215c09-c241-4e00-106a-08d6d3a714bc 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: MWHPR03MB3133 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The comment is no longer valid, since it supports arrays with gaps now. Signed-off-by: Alexandru Ardelean --- Changelog v2 -> v3: * after fixing __sysfs_match_string() this comment is no longer valid drivers/scsi/sd.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 2b2bc4b49d78..73ce390956c1 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -376,7 +376,6 @@ thin_provisioning_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(thin_provisioning); -/* sysfs_match_string() requires dense arrays */ static const char *lbp_mode[] = { [SD_LBP_FULL] = "full", [SD_LBP_UNMAP] = "unmap", @@ -424,7 +423,6 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(provisioning_mode); -/* sysfs_match_string() requires dense arrays */ static const char *zeroing_mode[] = { [SD_ZERO_WRITE] = "write", [SD_ZERO_WS] = "writesame", From patchwork Wed May 8 11:19:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10935003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2EE2912 for ; Wed, 8 May 2019 11:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93B36285F0 for ; Wed, 8 May 2019 11:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85A93287AB; Wed, 8 May 2019 11:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBBC6285F0 for ; Wed, 8 May 2019 11:19:58 +0000 (UTC) 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 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 X-Virus-Scanned: ClamAV using ClamSMTP 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]);