Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3554201pxf; Mon, 29 Mar 2021 05:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl2s7MWRP5Xjl5Gr8jVpEZvr2xA7PK/FoGgeGcJ3d2wGZS+F8EPqQklGBPZhw535MVKLNG X-Received: by 2002:a17:907:2716:: with SMTP id w22mr28183322ejk.328.1617021296574; Mon, 29 Mar 2021 05:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617021296; cv=none; d=google.com; s=arc-20160816; b=YVJJAbCRSD5mpkRefozQQiGgsu/MgdUCGnrbn3ktSBTE6UYeZv1BJeZ9Q0QXuDHXc4 B3UFx+UOARNYgLqiUwiulJE/5dqbrU38i+dNqSPlnFOdgu+g1Q7Dacc69pGpScyIeBnO GRQVfT6EXmRJuuCgFW2tVHpQVdvg1a2evr22PnqQir5/4D0RXZJtCNWaVjm+stt9+IsD s/xeROrcTR/nGMP9wxITYT7N+z5QiZm1oVc8Ze3vzqt4C1a2z8kx6ifV03VPRdt/y3tT GpLUYIAjvAXGo3BOBikpZMdLws4b9MIzUTdVnKzVDUAJEonHtmEuUVsCTGqTPO0VXH+t IZaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=CLpANdTqtyky/zM1E6AnsqOfUNohUuGLqswLSaCzpnM=; b=wgJX0ABUnTFgo6QL0s02d0cvprkhWPq+Uv0mslgZIhIbqivXK05k85ECgdOqSZ4aVa mbapov0nbcOqXUt6A8wUovUeIMecAeqOl4492jEKG5qLhbdw+TguqnvTXejo+IuALulA E0H6dhwZBekAGiTwgVfpavHht+ImsGTvKnTTP5jUTdUI8pQ4J1AcZVEtJdnFLDptQER7 4cD4R7VxC1dTlCrlUlhP8tXeUBCgL1QRhTtdIV1Ev8l4Q8fA7qOY2NH4WqVS5bMbxLKA nzH8hlwyQ+ZS8/5/VKwbWuTHc33Pb5/pggmZiQxWMatYmHbtKrVqvXdilNV3yAtDJZlk zV6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si6616919edn.294.2021.03.29.05.34.34; Mon, 29 Mar 2021 05:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbhC2Md0 (ORCPT + 99 others); Mon, 29 Mar 2021 08:33:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:44208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbhC2MdV (ORCPT ); Mon, 29 Mar 2021 08:33:21 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3899B61930; Mon, 29 Mar 2021 12:33:18 +0000 (UTC) Date: Mon, 29 Mar 2021 13:33:24 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Lars-Peter Clausen Subject: Re: [PATCH] iio: buffer: return 0 for buffer getfd ioctl handler Message-ID: <20210329133324.67eef6d8@jic23-huawei> In-Reply-To: <20210322084135.17536-1-aardelean@deviqon.com> References: <20210322084135.17536-1-aardelean@deviqon.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 22 Mar 2021 10:41:35 +0200 Alexandru Ardelean wrote: > As Lars pointed out, we could either return the FD vs memcpy-ing it to the > userspace data object. > > However, this comment exposed a bug. We should return 0 or negative from > these ioctl() handlers. Because an ioctl() handler can also return > IIO_IOCTL_UNHANDLED (which is positive 1), which means that the ioctl() > handler doesn't support this ioctl number. Positive 1 could also be a valid > FD number in some corner cases. > > The reason we did this is to be able to differentiate between an error > code and an unsupported ioctl number; for unsupported ioctl numbers, the > main loop should keep going. > > Maybe we should change this to a higher negative number, to avoid such > cases when/if we add more ioctl() handlers. That sounds like a sensible follow up plan to me - perhaps we could use EOPNOTSUPP for this directly but add special handling for that in the core so it doesn't worry about it as long as someone supports the ioctl. > > Cc: Lars-Peter Clausen > Fixes: f73f7f4da5818 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device") > Signed-off-by: Alexandru Ardelean Applied to the togreg branch of iio.git and pushed out as testing. Thanks, Jonathan > --- > drivers/iio/industrialio-buffer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c > index ee5aab9d4a23..d7a15c9bb0cd 100644 > --- a/drivers/iio/industrialio-buffer.c > +++ b/drivers/iio/industrialio-buffer.c > @@ -1442,7 +1442,7 @@ static long iio_device_buffer_getfd(struct iio_dev *indio_dev, unsigned long arg > goto error_free_ib; > } > > - return fd; > + return 0; > > error_free_ib: > kfree(ib);