Saturday, October 29, 2022

[SOLVED] How to fix error: implicit declaration of function ‘setup_timer’

Issue

Trying to compile Linux core module for usb-audio card Line6 UX2. Got code from repo and trying to make. Repo have no ./configure

Make produce error:

line6linux-code-r1108/driver/trunk/driver.c:169:2: error: implicit declaration of function ‘setup_timer’; did you mean ‘del_timer’? [-Werror=implicit-function-declaration]
  setup_timer(timer, function, data);
  ^~~~~~~~~~~
  del_timer

C function setup_timer() declare in the linux linux-headers package. Currently is linux-headers-4.18.0-16 Of course it's installed in the default place /usr/src/

Code which produces error (driver.c):

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/usb.h>

#include <sound/core.h>
#include <sound/initval.h>

#include "capture.h"
#include "driver.h"
#include "midi.h"
#include "playback.h"

... some code here

/*
    Setup and start timer.
*/
void line6_start_timer(struct timer_list *timer, unsigned long msecs,
               void (*function)(unsigned long), unsigned long data)
{
    setup_timer(timer, function, data); // <-- string 169
    mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
}
EXPORT_SYMBOL_GPL(line6_start_timer);

So apparently compiler can't find Linux headers. How can I fix it?

Also based on the INSTALL file, it follows that the driver was written for the kernel version linux-headers-2.6.x and now it's 4.18.0-16.

And more from INSTALL: For other distributions, please consult the documentation to find out which package you have to install.

Everything is lost?

OS Ubuntu 18.10 Linux 4.18.0-16-generic #17-Ubuntu SMP Fri Feb 8 00:06:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


Solution

In newer version of Linux kernel, setup_timer function is known as timer_setup.

Note, that type of the callback function has been changed in the resent versions. Now that callback accepts pointer to timer_list structure itself.

See more in this LWN article: https://lwn.net/Articles/735887/.



Answered By - Tsyvarev
Answer Checked By - Clifford M. (WPSolving Volunteer)