Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2761501ybz; Sun, 3 May 2020 08:41:31 -0700 (PDT) X-Google-Smtp-Source: APiQypLY+J2kjm3z4TTHfTKheKrey1aXgrKPVGxGIxxbN1KcnjC1EnH/Q9xOvwiHsTWcR2TgCmok X-Received: by 2002:a17:906:7a51:: with SMTP id i17mr11105573ejo.8.1588520490966; Sun, 03 May 2020 08:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588520490; cv=none; d=google.com; s=arc-20160816; b=fc+nxDZ98b6C8CcItFF4/8pVY0ptGHzFt6ehXyCOm/pfwlSrG2xUiSPXeerueo6DFH WRClw9mwreQoX8KS04TseoskCj/VcrU5Et/LCGNKzwH3xUgAUrex8eBwk0Ef5fL8cF6z e9wzI1alp9u+yb8d0/cu+/yMrrwiJWpHvFabMRrOznz0x7uWBKvIC4EKFltG2i/MRDew Ftgyke5JozKTK1MC00CCfI9vYzYOVlnl/DELcthvARtywyVopZoWEPPhChvaK3rLicwU NPu4TcZKVzn/f6WQM+LwrYqscioTH+fwP+HW9Wq54Owxs3ow43vTUTIm20XmqQIt19c9 WKrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=2GW1KR/YrkIxVWd4++stqvi1sfkbxwGmoh0AZq/lduA=; b=qn3WETB2e3W9sGIS+QHeq7hQt5tdHrTdl1FcX1oc+6vthOf1z9PzucPamOct/Cxp3J vxt6mdHJbQyOeqSnsRwPpB8nYE6dKnflSwQ0tyn1weeg5g2fXnrHwZFcO2pVmY5YCFNq Fvg4JFXOrGo1rKeIfItAXur0NkyPb2tAZXMx9QK5owW+FmYQJz1eGmTJMjtkD7bpW4uV O2YdTINvLmGCrNwqLpAW8Iw/vhthtfsNFdbc2xTF2vSFUcjTMuJfAUUyrFrxxplDvlrb TNdVjM7fkvnB5Qjp2NfgXlOhZ1zNC3nC/MJQ2cs6gKW70nlM1WGjMOKwt4zfaP4+snFh nfDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="gX2gk/9c"; 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 n26si4954184ejy.188.2020.05.03.08.41.06; Sun, 03 May 2020 08:41:30 -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; dkim=pass header.i=@kernel.org header.s=default header.b="gX2gk/9c"; 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 S1728748AbgECPjg (ORCPT + 99 others); Sun, 3 May 2020 11:39:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:56034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728665AbgECPjf (ORCPT ); Sun, 3 May 2020 11:39:35 -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 2295020757; Sun, 3 May 2020 15:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588520375; bh=7ugReJw62PCRt6fde0BnQlWhcam2vXexqDlVSZCxoGs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gX2gk/9coEHpqa1waHifo9drHDgjb567olmPj2bOQV554QZegDjUTgHIMo3T4g/4x yXRj2ZfDFBQFrleBl2tzmgebwJd/W/PIyyGatMA8tasQu0NPJstqn1MZ11mjw7r+7Q PWTcy8iW91FxxyAUj8fEwbmEYBMGv86uYenohJ6U= Date: Sun, 3 May 2020 16:39:26 +0100 From: Jonathan Cameron To: Alexandru Ardelean Cc: , , , Subject: Re: [PATCH v6 3/6] iio: core: register chardev only if needed Message-ID: <20200503163926.6f840406@archlinux> In-Reply-To: <20200427131100.50845-4-alexandru.ardelean@analog.com> References: <20200427131100.50845-1-alexandru.ardelean@analog.com> <20200427131100.50845-4-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 Mon, 27 Apr 2020 16:10:57 +0300 Alexandru Ardelean wrote: > The final 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 only need a chardev if we need to support buffers and/or events. > > With this change, a chardev will be created only if an IIO buffer is > attached OR an event_interface is configured. > > Otherwise, no chardev will be created, and the IIO device will get > registered with the 'device_add()' call. > > Quite a lot of IIO devices don't really need a chardev, so this is a minor > improvement to the IIO core, as the IIO device will take up (slightly) > fewer resources. > > Signed-off-by: Alexandru Ardelean > --- > drivers/iio/industrialio-core.c | 25 ++++++++++++++++++++++--- > 1 file changed, 22 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c > index 32c489139cd2..51e279c60793 100644 > --- a/drivers/iio/industrialio-core.c > +++ b/drivers/iio/industrialio-core.c > @@ -1682,6 +1682,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 = { > + .owner = THIS_MODULE, > + .llseek = noop_llseek, > + .unlocked_ioctl = iio_event_ioctl_wrapper, Unfortunately this doesn't exist until the next patch... > + .compat_ioctl = compat_ptr_ioctl, > + .open = iio_chrdev_open, > + .release = iio_chrdev_release, > +}; > + > int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) > { > int ret; > @@ -1732,11 +1741,18 @@ 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 if (indio_dev->event_interface) > + cdev_init(&indio_dev->chrdev, &iio_event_fileops); > > indio_dev->chrdev.owner = this_mod; > > - ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev); > + if (indio_dev->buffer || indio_dev->event_interface) > + ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev); > + else > + ret = device_add(&indio_dev->dev); > + > if (ret < 0) > goto error_unreg_eventset; > > @@ -1760,7 +1776,10 @@ EXPORT_SYMBOL(__iio_device_register); > **/ > void iio_device_unregister(struct iio_dev *indio_dev) > { > - cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); > + if (indio_dev->buffer || indio_dev->event_interface) > + cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); > + else > + device_del(&indio_dev->dev); > > mutex_lock(&indio_dev->info_exist_lock); >