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=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 125ABC433E0 for ; Thu, 18 Jun 2020 02:45:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFA8621534 for ; Thu, 18 Jun 2020 02:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592448340; bh=yIpaCBY7KC3JSoJD77yuBJ8C7JGm5l4UWnOFl9zU1Rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=M9Qq2ckvb/uFOg5t4myqEXO6stWuAH6z/q+eNZwSKMndF9uQLTOQptSIEfKNOj4Vc Hct12nV65K637A9gd4zeZ/qch1YcURAR1YItg8Qj1B+GsFPo1xYMCNuNP5iqSg/Ewp gb2s3FYRo+NjruVSr292R+F0edBtTFcCi6Z4hIoA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730595AbgFRCpj (ORCPT ); Wed, 17 Jun 2020 22:45:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgFRBK4 (ORCPT ); Wed, 17 Jun 2020 21:10:56 -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 B22B720CC7; Thu, 18 Jun 2020 01:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442655; bh=yIpaCBY7KC3JSoJD77yuBJ8C7JGm5l4UWnOFl9zU1Rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=znju3W+H0nu9v7waOHP/DKIYOaxdlVT1C5h5lGAq2hoTJPBppMTOpx2i2xk7uaC5E N+aYFBSPKwaP6fi1wXCnps6uVOAGUKZ04TG5CYUFOne8V5Pu9gXVYyGq9NlgeZ0DgG o9yeA3vZimXPTTz0PSN14sPHYHtVxgwbmIza2na0= 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.7 127/388] iio: buffer: Don't allow buffers without any channels enabled to be activated Date: Wed, 17 Jun 2020 21:03:44 -0400 Message-Id: <20200618010805.600873-127-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-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 4ada5592aa2b..7c0004b5a4bb 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