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 --- 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