From: David Lechner <david@lechnology.com>
To: linux-iio@vger.kernel.org
Cc: David Lechner <david@lechnology.com>,
William Breathitt Gray <vilhelm.gray@gmail.com>,
linux-kernel@vger.kernel.org,
Greg KH <gregkh@linuxfoundation.org>
Subject: [PATCH] counter: drop chrdev_lock
Date: Sun, 17 Oct 2021 13:55:21 -0500 [thread overview]
Message-ID: <20211017185521.3468640-1-david@lechnology.com> (raw)
This removes the chrdev_lock from the counter subsystem. This was
intended to prevent opening the chrdev more than once. However, this
doesn't work in practice since userspace can duplicate file descriptors
and pass file descriptors to other processes. Since this protection
can't be relied on, it is best to just remove it.
Suggested-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: David Lechner <david@lechnology.com>
---
drivers/counter/counter-chrdev.c | 6 ------
drivers/counter/counter-sysfs.c | 13 +++----------
include/linux/counter.h | 7 -------
3 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
index 967c94ae95bb..b747dc81cfc6 100644
--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -384,10 +384,6 @@ static int counter_chrdev_open(struct inode *inode, struct file *filp)
typeof(*counter),
chrdev);
- /* Ensure chrdev is not opened more than 1 at a time */
- if (!atomic_add_unless(&counter->chrdev_lock, 1, 1))
- return -EBUSY;
-
get_device(&counter->dev);
filp->private_data = counter;
@@ -419,7 +415,6 @@ static int counter_chrdev_release(struct inode *inode, struct file *filp)
mutex_unlock(&counter->ops_exist_lock);
put_device(&counter->dev);
- atomic_dec(&counter->chrdev_lock);
return ret;
}
@@ -445,7 +440,6 @@ int counter_chrdev_add(struct counter_device *const counter)
mutex_init(&counter->events_lock);
/* Initialize character device */
- atomic_set(&counter->chrdev_lock, 0);
cdev_init(&counter->chrdev, &counter_fops);
/* Allocate Counter events queue */
diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
index 1ccd771da25f..7bf8882ff54d 100644
--- a/drivers/counter/counter-sysfs.c
+++ b/drivers/counter/counter-sysfs.c
@@ -796,25 +796,18 @@ static int counter_events_queue_size_write(struct counter_device *counter,
u64 val)
{
DECLARE_KFIFO_PTR(events, struct counter_event);
- int err = 0;
-
- /* Ensure chrdev is not opened more than 1 at a time */
- if (!atomic_add_unless(&counter->chrdev_lock, 1, 1))
- return -EBUSY;
+ int err;
/* Allocate new events queue */
err = kfifo_alloc(&events, val, GFP_KERNEL);
if (err)
- goto exit_early;
+ return err;
/* Swap in new events queue */
kfifo_free(&counter->events);
counter->events.kfifo = events.kfifo;
-exit_early:
- atomic_dec(&counter->chrdev_lock);
-
- return err;
+ return 0;
}
static struct counter_comp counter_num_signals_comp =
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 22b14a552b1d..0fd99e255a50 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -297,7 +297,6 @@ struct counter_ops {
* @events: queue of detected Counter events
* @events_wait: wait queue to allow blocking reads of Counter events
* @events_lock: lock to protect Counter events queue read operations
- * @chrdev_lock: lock to limit chrdev to a single open at a time
* @ops_exist_lock: lock to prevent use during removal
*/
struct counter_device {
@@ -325,12 +324,6 @@ struct counter_device {
DECLARE_KFIFO_PTR(events, struct counter_event);
wait_queue_head_t events_wait;
struct mutex events_lock;
- /*
- * chrdev_lock is locked by counter_chrdev_open() and unlocked by
- * counter_chrdev_release(), so a mutex is not possible here because
- * chrdev_lock will invariably be held when returning to user space
- */
- atomic_t chrdev_lock;
struct mutex ops_exist_lock;
};
--
2.25.1
next reply other threads:[~2021-10-17 18:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-17 18:55 David Lechner [this message]
2021-10-18 6:08 ` Greg KH
2021-10-18 8:58 ` William Breathitt Gray
2021-10-18 9:13 ` Greg KH
2021-10-18 9:51 ` William Breathitt Gray
2021-10-18 16:14 ` David Lechner
2021-10-18 23:56 ` William Breathitt Gray
2021-10-18 9:14 ` William Breathitt Gray
2021-10-18 16:03 ` David Lechner
2021-10-19 6:53 ` William Breathitt Gray
2021-10-19 7:07 ` Greg KH
2021-10-19 7:18 ` William Breathitt Gray
2021-10-19 7:29 ` Greg KH
2021-10-19 7:46 ` William Breathitt Gray
2021-10-19 9:36 ` Greg KH
2021-10-19 14:44 ` David Lechner
2021-10-19 20:59 ` William Breathitt Gray
2021-10-20 5:42 ` William Breathitt Gray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211017185521.3468640-1-david@lechnology.com \
--to=david@lechnology.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vilhelm.gray@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®