Skip to content

Build failure on Linux kernel 7.0: from_timer() and del_timer_sync() removed from timer API #41

@yanorei32

Description

@yanorei32

After upgrading the system to Linux kernel 7.0, the module fails to build due to removed timer APIs.
The following errors occur during compilation:

make CHECK="/usr/bin/sparse" -C /lib/modules/7.0.2-arch1-1/build M=/usr/src/ms912x-0.1 modules
make[1]: Entering directory '/usr/lib/modules/7.0.2-arch1-1/build'
make[2]: Entering directory '/usr/src/ms912x-0.1'
  CC [M]  ms912x_registers.o
  CC [M]  ms912x_connector.o
  CC [M]  ms912x_transfer.o
ms912x_transfer.c: In function ‘ms912x_request_timeout’:
ms912x_transfer.c:12:46: error: implicit declaration of function ‘from_timer’; did you mean ‘mod_timer’? [-Wimplicit-function-declaration]
   12 |         struct ms912x_usb_request *request = from_timer(request, t, timer);
      |                                              ^~~~~~~~~~
      |                                              mod_timer
ms912x_transfer.c:12:69: error: ‘timer’ undeclared (first use in this function); did you mean ‘ktimerd’?
   12 |         struct ms912x_usb_request *request = from_timer(request, t, timer);
      |                                                                     ^~~~~
      |                                                                     ktimerd
ms912x_transfer.c:12:69: note: each undeclared identifier is reported only once for each function it appears in
ms912x_transfer.c: In function ‘ms912x_request_work’:
ms912x_transfer.c:31:9: error: implicit declaration of function ‘del_timer_sync’ [-Wimplicit-function-declaration]
   31 |         del_timer_sync(&request->timer);
      |         ^~~~~~~~~~~~~~
make[4]: *** [/usr/lib/modules/7.0.2-arch1-1/build/scripts/Makefile.build:289: ms912x_transfer.o] Error 1
make[3]: *** [/usr/lib/modules/7.0.2-arch1-1/build/Makefile:2105: .] Error 2
make[2]: *** [/usr/lib/modules/7.0.2-arch1-1/build/Makefile:248: __sub-make] Error 2
make[2]: Leaving directory '/usr/src/ms912x-0.1'
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Leaving directory '/usr/lib/modules/7.0.2-arch1-1/build'
make: *** [Makefile:15: modules] Error 2

These functions were deprecated in late 6.x kernels and fully removed in 7.0.
The driver still uses:

  • from_timer()
  • del_timer_sync()

Both must be replaced with the modern timer API.

Cause

Linux 7.0 removed several legacy timer helpers.
The correct replacements are:

  • from_timer() → container_of()
  • del_timer_sync() → timer_shutdown_sync()

Proposed fix (diff)

--- a/ms912x_transfer.c
+++ b/ms912x_transfer.c
@@ -1,5 +1,6 @@
 #include <linux/dma-buf.h>
 #include <linux/vmalloc.h>
+#include <linux/timer.h>
 
 #include <drm/drm_drv.h>
 #include <drm/drm_gem_framebuffer_helper.h>
@@ -7,9 +8,11 @@
 #include "ms912x.h"
 
 static void ms912x_request_timeout(struct timer_list *t)
 {
-   struct ms912x_usb_request *request = from_timer(request, t, timer);
+   struct ms912x_usb_request *request =
+       container_of(t, struct ms912x_usb_request, timer);
+
    usb_sg_cancel(&request->sgr);
 }
 
@@ -32,7 +35,7 @@ static void ms912x_request_work(struct work_struct *work)
    usb_sg_init(sgr, usbdev, usb_sndbulkpipe(usbdev, 0x04), 0,
            transfer_sgt->sgl, transfer_sgt->nents,
            request->transfer_len, GFP_KERNEL);
    mod_timer(&request->timer, jiffies + msecs_to_jiffies(5000));
    usb_sg_wait(sgr);
-   del_timer_sync(&request->timer);
+   timer_shutdown_sync(&request->timer);
    complete(&request->done);
 }

Environment

Kernel: Linux 7.0.2-arch1-1 x86_64

Expected behavior

Module should build successfully on Linux 7.0+.

Actual behavior

Build fails due to removed timer API functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions