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 5C95EC433E1 for ; Thu, 18 Jun 2020 01:27:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37BCF20B1F for ; Thu, 18 Jun 2020 01:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592443624; bh=OTuaHqvEqmAQRLH9EV+L9+Tbjn9g6XBVYj3cfaOysE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KoTwzd0vbl79RJbWjTAtgJ5Ir4UFUDAVxWECIt139O3wyvjR4eXse7/HmRZvSgegc o5EhQiwZKP9LJMnMmJmeDfUn5kpLx4ZZRG/rwt3cdt5/NTEsahvMyehRLsEs4GaOow YNBocc8MweqKcohcgcbf/qUDMSLaziWhhneZ38BU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730317AbgFRB1D (ORCPT ); Wed, 17 Jun 2020 21:27:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:57460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731018AbgFRBXi (ORCPT ); Wed, 17 Jun 2020 21:23:38 -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 B853521974; Thu, 18 Jun 2020 01:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592443417; bh=OTuaHqvEqmAQRLH9EV+L9+Tbjn9g6XBVYj3cfaOysE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otMOaBJOSLZ/qztgZ5ye1KbsXRXFm46tY8P8agVwRzY6xRzq7drdTpFmIr8BtlMzO tEIvGsFVdyfZSGioeDIv6r8GuDEwcoAwRtQdlow+PQW2Q5w0NqRmzcTRkDz1IUEdVo iWKqXxBvxqRUvuGoajsu0SeuTCRMYBqmv+Z+Qb1Y= 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.19 059/172] iio: buffer: Don't allow buffers without any channels enabled to be activated Date: Wed, 17 Jun 2020 21:20:25 -0400 Message-Id: <20200618012218.607130-59-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618012218.607130-1-sashal@kernel.org> References: <20200618012218.607130-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 a0d089afa1a2..b1e9ac5ecdac 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -691,6 +691,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.25.1