From: Danish Khateeb <danishkhateeb03@gmail.com>
To: William Breathitt Gray <wbg@kernel.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Danish Khateeb <danishkhateeb03@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] counter: Allow 32-bit tasks to use the character device
Date: Mon, 28 Sep 2026 20:21:38 -0500 [thread overview]
Message-ID: <20260929012138.71156-1-danishkhateeb03@gmail.com> (raw)
counter_fops has no .compat_ioctl, so COUNTER_ADD_WATCH_IOCTL,
COUNTER_ENABLE_EVENTS_IOCTL and COUNTER_DISABLE_EVENTS_IOCTL fail with
-ENOTTY for 32-bit tasks on a 64-bit kernel, e.g. armhf userspace on
arm64. Without a watch, such a task gets no events from /dev/counterN.
struct counter_watch has the same layout for 32-bit and 64-bit tasks,
and the other two ioctls take no argument, so compat_ptr_ioctl() is
enough. struct counter_event, which read() returns, has the same layout
too.
Fixes: b6c50affda59 ("counter: Add character device interface")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---
Notes:
Tested on x86_64 in QEMU (counter-fixes plus this patch, KASAN and
lockdep) with interrupt-cnt on a gpio-sim line, toggling the line five
times per run:
- before: tools/counter/counter_watch_events built with -m32 fails with
"Error adding watches[0]: Inappropriate ioctl for device", and so do
the enable and disable ioctls; the 64-bit build gets all five events
- after: the -m32 build gets the same five events and the same errors
for an invalid watch and a bad pointer as the 64-bit build
No splats. W=1 builds are clean for arm64 (COMPAT=y, LLVM=1) and for
i386 (no COMPAT).
drivers/counter/counter-chrdev.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
index 61451ba74ca1..f5bf8e40096b 100644
--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -457,6 +457,7 @@ static const struct file_operations counter_fops = {
.read = counter_chrdev_read,
.poll = counter_chrdev_poll,
.unlocked_ioctl = counter_chrdev_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
.open = counter_chrdev_open,
.release = counter_chrdev_release,
};
base-commit: fd73f4a6659897191fa0d40695fe370925dd3780
--
2.55.0
reply other threads:[~2026-09-29 1:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260929012138.71156-1-danishkhateeb03@gmail.com \
--to=danishkhateeb03@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=wbg@kernel.org \
/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®