Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3900843pxb; Mon, 1 Feb 2021 07:31:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPKJgNKkPL4LwkaXw5jNqBWWNMdOE0w5l27LHuUG6+RpJ9dPOHQOXdsy8YiSo8FEOVNJIa X-Received: by 2002:aa7:d148:: with SMTP id r8mr19313313edo.127.1612193493515; Mon, 01 Feb 2021 07:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612193493; cv=none; d=google.com; s=arc-20160816; b=vESOHUK2fop0D/I+N6csXByNbiYQgANlWqxUlOYjxL/Uj+hMvoeXP2sqA8fb+ZrMvp kIBk3GCc5epEaB9vUbQZaNnTErjqXfCVOxqg6cEjNCEvv64nO9uFKSGRTVMNZksIqhAQ TxD9QheY/Tphy0Jw0tD2kC8M/sjE7F8WnOPMYNf1LrFDiy2gDZ9JIKYb582zwygq7bRi 05ZX0CCSnWDu047pHP+UokgLKc7v5rUGRVely5VX55RL41SxExmsGuVs1vLBtENFk3Qj kdk5LdiIBMgLTmwzbRlzj/R7Y9rC9EBTmJztHiJknk95CB7+v34h1GQp/NeNAzrEIfFK HULg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=V6REmVlI3OEzUWd6pXmGvc6CVL+qKA+m496E71YQ2Yg=; b=rf0tJzhG5cuPiQAvAl5GF28jcpazyVEzOTQvujlk8hJgOzH7FEARuvOu7szLN+koVX 0bIivW/8g/4m3+JArDxQG/HjnNg9hQzD0rDrIEpFiRdstjBdAqC8RbJJTsfD4Ndg3vHA 5+EfNQLOFds/ruuMPdrL20dMIvrJupi3oY9C9gvDzQCFwNfPki/Q4X2hb7MmGg1CX5HA XEjz8X4ytq99lovW0oFWGTW+9ouevidMva9ZxizaNy//c2J30Ys9mhtspisdorARuQ45 4SNxjGdo43l6EzcaCOevmZqacryKaFEdsmYCsxuSzDgKj+W7qPkie3EoiW+c9DTnGXIz 5pqg== 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=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si11291258edd.505.2021.02.01.07.31.06; Mon, 01 Feb 2021 07:31:33 -0800 (PST) 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=fail (p=NONE sp=NONE dis=NONE) header.from=analog.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231293AbhBAP3t (ORCPT + 99 others); Mon, 1 Feb 2021 10:29:49 -0500 Received: from mx0a-00128a01.pphosted.com ([148.163.135.77]:28814 "EHLO mx0a-00128a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbhBAOt1 (ORCPT ); Mon, 1 Feb 2021 09:49:27 -0500 Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 111El9AT014367; Mon, 1 Feb 2021 09:48:32 -0500 Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com with ESMTP id 36dbucuqa3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Feb 2021 09:48:32 -0500 Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 111EmUAb030260 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 1 Feb 2021 09:48:31 -0500 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.721.2; Mon, 1 Feb 2021 09:48:30 -0500 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.721.2; Mon, 1 Feb 2021 09:48:29 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.1.1779.2 via Frontend Transport; Mon, 1 Feb 2021 09:48:29 -0500 Received: from localhost.localdomain ([10.48.65.12]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 111EmNu8027350; Mon, 1 Feb 2021 09:48:27 -0500 From: Alexandru Ardelean To: , CC: , , , , , , , Alexandru Ardelean Subject: [PATCH v3 02/11] iio: core: register chardev only if needed Date: Mon, 1 Feb 2021 16:50:56 +0200 Message-ID: <20210201145105.20459-3-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210201145105.20459-1-alexandru.ardelean@analog.com> References: <20210201145105.20459-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 Content-Type: text/plain X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-01_06:2021-01-29,2021-02-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 spamscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102010079 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. In order to not create a chardev, we mostly just need to not initialize the indio_dev->dev.devt field. If that is un-initialized, cdev_device_add() behaves like device_add(). Signed-off-by: Alexandru Ardelean --- drivers/iio/industrialio-core.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 7db761afa578..0a6fd299a978 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1761,6 +1761,15 @@ static const struct file_operations iio_buffer_fileops = { .release = iio_chrdev_release, }; +static const struct file_operations iio_event_fileops = { + .owner = THIS_MODULE, + .llseek = noop_llseek, + .unlocked_ioctl = iio_ioctl, + .compat_ioctl = compat_ptr_ioctl, + .open = iio_chrdev_open, + .release = iio_chrdev_release, +}; + static int iio_check_unique_scan_index(struct iio_dev *indio_dev) { int i, j; @@ -1788,6 +1797,7 @@ static const struct iio_buffer_setup_ops noop_ring_setup_ops; int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) { + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); int ret; if (!indio_dev->info) @@ -1805,9 +1815,6 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) if (ret < 0) return ret; - /* configure elements for the chrdev */ - indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id); - iio_device_register_debugfs(indio_dev); ret = iio_buffer_alloc_sysfs_and_mask(indio_dev); @@ -1836,9 +1843,15 @@ 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 (iio_dev_opaque->event_interface) + cdev_init(&indio_dev->chrdev, &iio_event_fileops); - indio_dev->chrdev.owner = this_mod; + if (indio_dev->buffer || iio_dev_opaque->event_interface) { + indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id); + indio_dev->chrdev.owner = this_mod; + } ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev); if (ret < 0) -- 2.17.1