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,USER_AGENT_GIT autolearn=ham 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 DC30BC433DF for ; Thu, 18 Jun 2020 02:21:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5FE7207E8 for ; Thu, 18 Jun 2020 02:21:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592446887; bh=D8MAFFTVPpLP8dncp5JzGg3VHGSOJhBl+2J7eEbuAYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zfFQytxK5ZpWqKR20bhCS8/6i/UMj/243BqLWaFzNf4ZmoIL5pRs0Z44CuyzECtzv gpUd3JJIVfTO0fQZLbkHwAuHesFFLF0cJ43n50ILOsBB3BGPpnUCHyWLEK5oCIMkGS bFDmT30ey1xpX6odlVRXlQ5ww1oePJCMQ4f2BlCA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387576AbgFRCV0 (ORCPT ); Wed, 17 Jun 2020 22:21:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:50192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727016AbgFRBSj (ORCPT ); Wed, 17 Jun 2020 21:18:39 -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 946B421D82; Thu, 18 Jun 2020 01:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592443119; bh=D8MAFFTVPpLP8dncp5JzGg3VHGSOJhBl+2J7eEbuAYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vPd6xMvV3R6VWJHeb657+ju70GQ0Tj9+WS8bOor6itK0hRUTOGC5v4pA9wRmzumnr IvOdrgRB6zu3TsZIpf5UOEh/jYIECI+J4xF2BGUomhxxYvpO23I7gP91Zv8N9E5sTN EthxUMVjMGVGURdBBXh1PXHtMNnRI9CiOB4oJrlU= 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 5.4 094/266] iio: buffer: Don't allow buffers without any channels enabled to be activated Date: Wed, 17 Jun 2020 21:13:39 -0400 Message-Id: <20200618011631.604574-94-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618011631.604574-1-sashal@kernel.org> References: <20200618011631.604574-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 112225c0e486..caacc9d00636 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -687,6 +687,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