mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] counter: Allow 32-bit tasks to use the character device
@ 2026-09-29  1:21 Danish Khateeb
  0 siblings, 0 replies; only message in thread
From: Danish Khateeb @ 2026-09-29  1:21 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Danish Khateeb, stable

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-29  1:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29  1:21 [PATCH] counter: Allow 32-bit tasks to use the character device Danish Khateeb

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®