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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,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 7CBC7C433E0 for ; Thu, 18 Jun 2020 01:38:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BCF1221E9 for ; Thu, 18 Jun 2020 01:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592444284; bh=cNRss9k61jcT5jvgxhOjB1htArPOvfCf4vU4KyasxiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZzVyzJjgjqlOAGGW9caRPlmUyv+XnJ49h2Ym8zozC/7ysixx5r6XzTiX+5xxFuaID RzIQHctgnxfTWH1K7rpKhO3hh8tHER3su09oRkK8LeVW1q0jbK+K2G5Vyug9HF8bTK xPeYljPMQoBrSoSiz3yip6a9sl45FZ0A4hIOGHSw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729508AbgFRBah (ORCPT ); Wed, 17 Jun 2020 21:30:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:40722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732570AbgFRBah (ORCPT ); Wed, 17 Jun 2020 21:30:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 990D1221EC; Thu, 18 Jun 2020 01:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592443836; bh=cNRss9k61jcT5jvgxhOjB1htArPOvfCf4vU4KyasxiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1rVAN0os+U07gNa/RD1yiH1np/lAjDBSvIVREce3KxMP0tQUbWFtE9tSHxNzrrxEG Z53Nq41nr5qP3itoqfCJh+o7Pw8W/1Qf9mGiv58VV+p4tNgs0+srPv5YGF4lT0lskc qJDR7S2lINj0wCnsC6g7XuArDeKD6x7Ze2NcYRQc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lars-Peter Clausen , Alexandru Ardelean , Jonathan Cameron , Sasha Levin , linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 23/60] iio: buffer: Don't allow buffers without any channels enabled to be activated Date: Wed, 17 Jun 2020 21:29:27 -0400 Message-Id: <20200618013004.610532-23-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618013004.610532-1-sashal@kernel.org> References: <20200618013004.610532-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Lars-Peter Clausen [ Upstream commit b7329249ea5b08b2a1c2c3f24a2f4c495c4f14b8 ] 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. Note from Jonathan: Probably not suitable for automatic application to stable. This has been there from the very start. It tidies up an odd corner case but won't effect any 'real' users. Fixes: 84b36ce5f79c0 ("staging:iio: Add support for multiple buffers") Signed-off-by: Lars-Peter Clausen Signed-off-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- 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 864a61b05665..fea41b328ab9 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -641,6 +641,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)); /* -- 2.25.1