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=-8.6 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_SANE_2 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 9846DC2BBFD for ; Mon, 13 Apr 2020 15:47:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FEEE20739 for ; Mon, 13 Apr 2020 15:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586792855; bh=1kbI+L/FOBvyQlWHtEOqRSUxbelREV3uN+qV916OMhU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=p+FmKMJQ7D2+aeq4oRfjGM5VQrn0azvaVPYBMv5D/tDpIsKV0Hz+lFvpA0WVhwjGv tFGfNtcR6wck/1liI+sXL/BqfHJa1a8JAOrY+a0VOz8xmIa2E85XMq2b4dILIJinbF ct42V2qveuH/8QSqXhA0meD7acXYAvdrEMY3Lh5o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730771AbgDMPre (ORCPT ); Mon, 13 Apr 2020 11:47:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:53884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728597AbgDMPrb (ORCPT ); Mon, 13 Apr 2020 11:47:31 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 BAB9120735; Mon, 13 Apr 2020 15:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586792850; bh=1kbI+L/FOBvyQlWHtEOqRSUxbelREV3uN+qV916OMhU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EerhglLhkdcjrdNPG/aRGrsuRAIcQzU36TvUnEMoA/BZZ0R78JdNUtCyeEe5BHFDc yCIml7K8Nb+vjzIA8Rn+u2D0g97+FT4V7lOMS1rVvs3o8QGtyO08/3aZuT6gra4HK7 3XDwpUWTX1rfvmnrm+3gZ/tQuMoZrP3p2x2W62JA= Date: Mon, 13 Apr 2020 16:47:26 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , Subject: Re: [PATCH v3 1/5] iio: core: register buffer fileops only if buffer present Message-ID: <20200413164726.5e5e2efd@archlinux> In-Reply-To: <20200410141729.82834-2-alexandru.ardelean@analog.com> References: <20200410141729.82834-1-alexandru.ardelean@analog.com> <20200410141729.82834-2-alexandru.ardelean@analog.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 10 Apr 2020 17:17:25 +0300 Alexandru Ardelean wrote: > The intent is to localize all buffer ops into the industrialio-buffer.c > file, to be able to add support for multiple buffers per IIO device. > > We still need to allocate a chardev in __iio_device_register() to be able > to pass event ioctl commands. So, if the IIO device has no buffer, we > create the legacy chardev for the event ioctl() command. > > Signed-off-by: Alexandru Ardelean Whilst we are here, can we avoid allocating the chardev at all if we have neither buffer support, nor events? So don't add the chrdev to the device. That covers quite a wide range of slow devices and is a nice incidental improvement (to be honest I'd forgotten we actually created a chardev in those circumstance :( Jonathan > --- > drivers/iio/industrialio-core.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index 157d95a24faa..c8c074602709 100644 > --- a/drivers/iio/industrialio-core.c > +++ b/drivers/iio/industrialio-core.c > @@ -1707,6 +1707,15 @@ static int iio_check_unique_scan_index(struct iio_dev *indio_dev) > > static const struct iio_buffer_setup_ops noop_ring_setup_ops; > > +static const struct file_operations iio_event_fileops = { > + .release = iio_chrdev_release, > + .open = iio_chrdev_open, > + .owner = THIS_MODULE, > + .llseek = noop_llseek, > + .unlocked_ioctl = iio_ioctl, > + .compat_ioctl = compat_ptr_ioctl, > +}; > + > int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) > { > int ret; > @@ -1757,7 +1766,10 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) > indio_dev->setup_ops == NULL) > indio_dev->setup_ops = &noop_ring_setup_ops; > > - cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); > + if (indio_dev->buffer) > + cdev_init(&indio_dev->chrdev, &iio_buffer_fileops); > + else > + cdev_init(&indio_dev->chrdev, &iio_event_fileops); > > indio_dev->chrdev.owner = this_mod; >