Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp446329ybb; Wed, 25 Mar 2020 03:02:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv+mFxiJoR99gpKS1IvYNlcf3vRgbZXl2JKrS9fVxNCs04LaQFVy6NmGrc6JgHXJo0n+hTa X-Received: by 2002:aca:f582:: with SMTP id t124mr1902486oih.17.1585130564812; Wed, 25 Mar 2020 03:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585130564; cv=none; d=google.com; s=arc-20160816; b=HZ9Y0vwysU0LkamGHO1hNMGnfGRDAL+NdUD+9xY0LrUvHlCMdr0zpOGbjiRl1wOJIH zvKwiWt/O2iPtfgVn5TAX1gS6G3Bv8/7Ykchs0DSWSSWxMkWF25DwiUegXUPdShr4tS9 NTr+eDwYXTS4+M24xwFXhfU8nYIXX8PNJZo074bFXm9SJltmKEsu6upY0HnKt/7b/uh2 303ysg/Zk4zJUIeBraGSXkp6uo2+ISSjOtEbD/fZmri73KWy2CA3diWgIi2rPO0dHqs0 Rc+QGTLMSjNKi749905zzXnzIDCKHw38WQpTYPmAiqcrrSEL5N5RCCX6ryMX8fqvxLtH Hxfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XVQCjRQusWid6NkPRSEDM3CpHM2gaVYtc++EdOoVJcw=; b=dTMHAH/Zc5fXYBxvE/XpWxVa16xCAOpbvGCCHAV1sAcBOrZtcozGhhF+e6Q2I/fhzF 52WPw2rYuX/g5EeIEhOoESBDW0n8zg8YXlimd8DByDvQhkhbTZYlXv9sH7l/a3hMKx6i tmYmbi22/mKDQgicdSti//H+By2ecIs2owgjCrM9luVUK1OmRLTvOQpQ3pDXx3QGq6+j P8jG1A9D2OF6B5MsUiwvPeBToBG5ctwHLK6/iOFPfj48fOFtZNgk6Ww6u+p1V3iCTNNC 22TRCFO7WXvgKLK2NCeafa3z9pC5zGvBmT2uYttSNBSK1DfZEbrPYYBJhKfrMTtsChS6 R8/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y206si5404845oig.253.2020.03.25.03.02.27; Wed, 25 Mar 2020 03:02:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727545AbgCYKBx (ORCPT + 99 others); Wed, 25 Mar 2020 06:01:53 -0400 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:37752 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727494AbgCYKBw (ORCPT ); Wed, 25 Mar 2020 06:01:52 -0400 Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02P9tOP2028336; Wed, 25 Mar 2020 06:01:42 -0400 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 2ywcs6556j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Mar 2020 06:01:42 -0400 Received: from ASHBMBX8.ad.analog.com (ashbmbx8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 02PA1fAg008627 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Wed, 25 Mar 2020 06:01:41 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 25 Mar 2020 06:01:40 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Wed, 25 Mar 2020 06:01:40 -0400 Received: from zeus.spd.analog.com (10.64.82.11) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Wed, 25 Mar 2020 06:01:40 -0400 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 02PA1anO023841; Wed, 25 Mar 2020 06:01:36 -0400 From: Alexandru Ardelean To: , CC: , , , , Alexandru Ardelean Subject: [PATCH v2] iio: buffer: Don't allow buffers without any channels enabled to be activated Date: Wed, 25 Mar 2020 12:01:12 +0200 Message-ID: <20200325100112.85107-1-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320104031.31701-1-alexandru.ardelean@analog.com> References: <20200320104031.31701-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ADIRoutedOnPrem: True X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.645 definitions=2020-03-25_04:2020-03-23,2020-03-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 adultscore=0 phishscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1011 suspectscore=0 spamscore=0 mlxlogscore=961 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003250085 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen Before activating a buffer make sure that at least one channel is enabled. Activating a buffer with 0 channels enabled doesn't make too much sense and disallowing this case makes sure that individual driver don't have to add special case code to handle it. Currently, without this patch enabling a buffer is possible and no error is produced. With this patch -EINVAL is returned. An example of execution with this patch and some instrumented print-code: root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000 1: iio_verify_update 753 2:__iio_update_buffers 1115 ret -22 3: iio_buffer_store_enable 1241 ret -22 -bash: echo: write error: Invalid argument 1, 2 & 3 are exit-error paths. 0 the first print in iio_verify_update() rergardless of error path. Without this patch (and same instrumented print-code): root@analog:~# cd /sys/bus/iio/devices/iio\:device3/buffer root@analog:/sys/bus/iio/devices/iio:device3/buffer# echo 1 > enable 0: iio_verify_update 748 indio_dev->masklength 2 *insert_buffer->scan_mask 00000000 root@analog:/sys/bus/iio/devices/iio:device3/buffer# Buffer is enabled with no error. Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean --- Changelog v1 -> v2: * moved check in iio_verify_update() * added dev_dbg() message; should help some folks understand the message * documented steps to reproduce * added Fixes tag; hopefully the tag is the good one; if needed, it can be   dropped; this has been around for ~8 years; no idea if it's worth   backporting drivers/iio/industrialio-buffer.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 5ff34ce8b6a2..e6fa1a4e135d 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -686,6 +686,13 @@ static int iio_verify_update(struct iio_dev *indio_dev, bool scan_timestamp; unsigned int modes; + if (insert_buffer && + bitmap_empty(insert_buffer->scan_mask, indio_dev->masklength)) { + dev_dbg(&indio_dev->dev, + "At least one scan element must be enabled first\n"); + return -EINVAL; + } + memset(config, 0, sizeof(*config)); config->watermark = ~0; -- 2.17.1