diff mbox series

Compilation error in rtl8821ce driver and possible fix

Message ID 4491429.ZAENLmHWg6@afrodite.mst.cosmic-odyssey.net (mailing list archive)
State Not Applicable
Delegated to: Kalle Valo
Headers show
Series Compilation error in rtl8821ce driver and possible fix | expand

Commit Message

Francesco Napoleoni Feb. 2, 2019, 1:02 a.m. UTC
Hi

A few days ago I downloaded rtl8821ce wireless network driver from endlessm/
linux repository (master branch), and I managed to build module for kernel 
4.19.16 on my Linux laptop, a HP 15-DB0035NL with an AMD Ryzen 5 2500U CPU.

When upgrading to kernel 4.20.5 I could not build the module anymore, the 
compilation stopped with an error about the use of get_monotonic_boottime() 
function, which apparently was deprecated and has been removed.

I’m no expert in kernel development, however I discovered that such function 
has been superseded by ktime_get_boottime_ts64(), and so I tried to use it in 
place of get_monotonic_boottime(). The resulting code compiled correctly, and 
the module seems to load and work without problem.

The code I changed is in the rtl8821ce/os_dep/linux/ioctl_cfg80211.c (lines 
338-339), you can find a patchfile attached here.

Sorry for any mistake I may have done in this report, this is the first time I 
do such a thing.

greetings
Francesco Napoleoni

Comments

Larry Finger Feb. 2, 2019, 5:06 p.m. UTC | #1
On 2/1/19 7:02 PM, Francesco Napoleoni wrote:
> Hi
> 
> A few days ago I downloaded rtl8821ce wireless network driver from endlessm/
> linux repository (master branch), and I managed to build module for kernel
> 4.19.16 on my Linux laptop, a HP 15-DB0035NL with an AMD Ryzen 5 2500U CPU.
> 
> When upgrading to kernel 4.20.5 I could not build the module anymore, the
> compilation stopped with an error about the use of get_monotonic_boottime()
> function, which apparently was deprecated and has been removed.
> 
> I’m no expert in kernel development, however I discovered that such function
> has been superseded by ktime_get_boottime_ts64(), and so I tried to use it in
> place of get_monotonic_boottime(). The resulting code compiled correctly, and
> the module seems to load and work without problem.
> 
> The code I changed is in the rtl8821ce/os_dep/linux/ioctl_cfg80211.c (lines
> 338-339), you can find a patchfile attached here.
> 
> Sorry for any mistake I may have done in this report, this is the first time I
> do such a thing.

When you use an out-of-kernel driver, then you are responsible for making the 
changes that result from kernel API changes. For the in-kernel drivers, the 
person changing the API is responsible for all the fixes. For that reason, I'm 
not sure that the linux-wireless mailing list was appropriate for your "fix", 
but I am replying to it just in case someone else needs to fix one of Realtek's 
drivers.

By the way, your fix will break the driver for anyone trying to go back to 
kernel 4.19, or for anyone running a 32-bit system. My fix for this problem with 
Realtek drivers is to make rtw_get_systime_us() to look like this:

static u64 rtw_get_systime_us(void)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0))
         u64 ts;
         ts = ktime_get_boottime();
         return do_div(ts, 1000);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
         struct timespec ts;
         get_monotonic_boottime(&ts);
         return ((u64)ts.tv_sec * 1000000) + ts.tv_nsec / 1000;
#else
         struct timeval tv;
         do_gettimeofday(&tv);
         return ((u64)tv.tv_sec * 1000000) + tv.tv_usec;
#endif
}

The above version will build on all kernel versions. The use of do_div() is to 
prevent a missing divide routine in 32-bit systems.

Larry
diff mbox series

Patch

--- ioctl_cfg80211.c.old	2019-02-02 01:15:41.407123709 +0100
+++ ioctl_cfg80211.c	2019-02-02 01:16:18.459536625 +0100
@@ -335,8 +335,8 @@ 
 static u64 rtw_get_systime_us(void)
 {
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
-	struct timespec ts;
-	get_monotonic_boottime(&ts);
+	struct timespec64 ts;
+	ktime_get_boottime_ts64(&ts);
 	return ((u64)ts.tv_sec * 1000000) + ts.tv_nsec / 1000;
 #else
 	struct timeval tv;