Skip to content

Commit c74dc01

Browse files
Add multiple flags for newly defined methods and utilities
Adding a flag for the definition of hid_warn_ratelimited introduced in kernel v6.17 Adding a flag for the usage of __free which was introduced in kernel version v6.5. Adding flags for the new guard and secure_guard methods implemented in kernel v6.5 Adding flag for DEFINE_SIMPLE_DEV_PM_OPS definition implemented in kernel v5.17
1 parent e44367b commit c74dc01

5 files changed

Lines changed: 166 additions & 4 deletions

File tree

.github/workflows/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-24.04
1313
strategy:
1414
matrix:
15-
kernel: ["7.0", "6.12", "6.10", "6.3", "5.15", "5.10", "5.4", "5.0", "4.19"]
15+
kernel: ["7.0", "6.17", "6.12", "6.10", "6.5", "6.3", "5.17", "5.15", "5.10", "5.4", "5.0", "4.19"]
1616
include:
1717
- kernel: "4.19"
1818
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
@@ -24,15 +24,23 @@ jobs:
2424
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
2525
- kernel: "5.15"
2626
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
27+
- kernel: "5.17"
28+
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
2729
- kernel: "6.3"
2830
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
2931
build_makeflags: KBUILD_MODPOST_WARN=1
32+
- kernel: "6.5"
33+
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
34+
build_makeflags: KBUILD_MODPOST_WARN=1
3035
- kernel: "6.10"
3136
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
3237
build_makeflags: KBUILD_MODPOST_WARN=1
3338
- kernel: "6.12"
3439
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
3540
build_makeflags: KBUILD_MODPOST_WARN=1
41+
- kernel: "6.17"
42+
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
43+
build_makeflags: KBUILD_MODPOST_WARN=1
3644
- kernel: "7.0"
3745
compile_cflags: -Wno-error=format-truncation -Wno-error=pointer-sign
3846
build_makeflags: KBUILD_MODPOST_WARN=1

4.18/wacom_i2c.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ static int wacom_i2c_probe(struct i2c_client *client)
338338
return 0;
339339
}
340340

341+
#ifdef WACOM_DEFINE_SIMPLE_DEV_PM_OPS
341342
static int wacom_i2c_suspend(struct device *dev)
343+
#else
344+
static int __maybe_unused wacom_i2c_suspend(struct device *dev)
345+
#endif
342346
{
343347
struct i2c_client *client = to_i2c_client(dev);
344348

@@ -347,7 +351,11 @@ static int wacom_i2c_suspend(struct device *dev)
347351
return 0;
348352
}
349353

354+
#ifdef WACOM_DEFINE_SIMPLE_DEV_PM_OPS
350355
static int wacom_i2c_resume(struct device *dev)
356+
#else
357+
static int __maybe_unused wacom_i2c_resume(struct device *dev)
358+
#endif
351359
{
352360
struct i2c_client *client = to_i2c_client(dev);
353361

@@ -356,7 +364,11 @@ static int wacom_i2c_resume(struct device *dev)
356364
return 0;
357365
}
358366

367+
#ifdef WACOM_DEFINE_SIMPLE_DEV_PM_OPS
359368
static DEFINE_SIMPLE_DEV_PM_OPS(wacom_i2c_pm, wacom_i2c_suspend, wacom_i2c_resume);
369+
#else
370+
static SIMPLE_DEV_PM_OPS(wacom_i2c_pm, wacom_i2c_suspend, wacom_i2c_resume);
371+
#endif
360372

361373
static const struct i2c_device_id wacom_i2c_id[] = {
362374
{ "WAC_I2C_EMR" },
@@ -375,7 +387,11 @@ MODULE_DEVICE_TABLE(of, wacom_i2c_of_match_table);
375387
static struct i2c_driver wacom_i2c_driver = {
376388
.driver = {
377389
.name = "wacom_i2c",
390+
#ifdef WACOM_DEFINE_SIMPLE_DEV_PM_OPS
378391
.pm = pm_sleep_ptr(&wacom_i2c_pm),
392+
#else
393+
.pm = &wacom_i2c_pm,
394+
#endif
379395

380396
#ifdef CONFIG_OF
381397
.of_match_table = of_match_ptr(wacom_i2c_of_match_table),

4.18/wacom_sys.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,33 @@ static void wacom_wac_queue_insert(struct hid_device *hdev,
6868
kfifo_skip(fifo);
6969
}
7070

71+
#ifdef WACOM_HID_WARN_RATELIMITED
7172
if (!kfifo_in(fifo, raw_data, size))
7273
hid_warn_ratelimited(hdev, "%s: report is too large (%d)\n",
7374
__func__, size);
75+
#else
76+
kfifo_in(fifo, raw_data, size);
77+
#endif
7478
}
7579

7680
static void wacom_wac_queue_flush(struct hid_device *hdev,
7781
struct kfifo_rec_ptr_2 *fifo)
7882
{
7983
while (!kfifo_is_empty(fifo)) {
8084
int size = kfifo_peek_len(fifo);
85+
#ifdef WACOM_CLEANUP_FREE
8186
u8 *buf __free(kfree) = kzalloc(size, GFP_ATOMIC);
87+
#else
88+
u8 *buf;
89+
#endif
8290
unsigned int count;
8391
int err;
8492

93+
#ifdef WACOM_CLEANUP_FREE
94+
#else
95+
buf = kzalloc(size, GFP_ATOMIC);
96+
#endif
97+
8598
if (!buf) {
8699
kfifo_skip(fifo);
87100
continue;
@@ -92,8 +105,12 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
92105
// Hard to say what is the "right" action in this
93106
// circumstance. Skipping the entry and continuing
94107
// to flush seems reasonable enough, however.
95-
hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
96-
__func__);\
108+
hid_warn(hdev, "%s: removed fifo entry with unexpected size\n",
109+
__func__);
110+
#ifdef WACOM_CLEANUP_FREE
111+
#else
112+
kfree(buf);
113+
#endif
97114
continue;
98115
}
99116
#ifdef WACOM_HID_REPORT_RAW_EVENT_BUFSIZE
@@ -105,6 +122,10 @@ static void wacom_wac_queue_flush(struct hid_device *hdev,
105122
hid_warn(hdev, "%s: unable to flush event due to error %d\n",
106123
__func__, err);
107124
}
125+
#ifdef WACOM_CLEANUP_FREE
126+
#else
127+
kfree(buf);
128+
#endif
108129
}
109130
}
110131

4.18/wacom_w8001.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static int w8001_command(struct w8001 *w8001, unsigned char command,
375375
return rc;
376376
}
377377

378+
#ifdef WACOM_SCOPED_GUARD
378379
static int w8001_open(struct input_dev *dev)
379380
{
380381
struct w8001 *w8001 = input_get_drvdata(dev);
@@ -393,15 +394,42 @@ static int w8001_open(struct input_dev *dev)
393394

394395
return -EINTR;
395396
}
397+
#else
398+
static int w8001_open(struct input_dev *dev)
399+
{
400+
struct w8001 *w8001 = input_get_drvdata(dev);
401+
int err;
402+
403+
err = mutex_lock_interruptible(&w8001->mutex);
404+
if (err)
405+
return err;
406+
407+
if (w8001->open_count++ == 0) {
408+
err = w8001_command(w8001, W8001_CMD_START, false);
409+
if (err)
410+
w8001->open_count--;
411+
}
412+
413+
mutex_unlock(&w8001->mutex);
414+
return err;
415+
}
416+
#endif
396417

397418
static void w8001_close(struct input_dev *dev)
398419
{
399420
struct w8001 *w8001 = input_get_drvdata(dev);
400-
421+
#ifdef WACOM_GUARD
401422
guard(mutex)(&w8001->mutex);
423+
#else
424+
mutex_lock(&w8001->mutex);
425+
#endif
402426

403427
if (--w8001->open_count == 0)
404428
w8001_command(w8001, W8001_CMD_STOP, false);
429+
#ifdef WACOM_GUARD
430+
#else
431+
mutex_unlock(&w8001->mutex);
432+
#endif
405433
}
406434

407435
static int w8001_detect(struct w8001 *w8001)
@@ -596,7 +624,11 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
596624
char basename[64] = "Wacom Serial";
597625
int err, err_pen, err_touch;
598626

627+
#ifdef WACOM_KZALLOC_OBJ
599628
w8001 = kzalloc_obj(*w8001);
629+
#else
630+
w8001 = kzalloc(sizeof(*w8001), GFP_KERNEL);
631+
#endif
600632
input_dev_pen = input_allocate_device();
601633
input_dev_touch = input_allocate_device();
602634
if (!w8001 || !input_dev_pen || !input_dev_touch) {

configure.ac

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,91 @@ WACOM_LINUX_TRY_COMPILE([
385385
AC_MSG_RESULT([no])
386386
])
387387

388+
dnl Check if hid_warn_ratelimited exists
389+
AC_MSG_CHECKING(hid_warn_ratelimited)
390+
WACOM_LINUX_TRY_COMPILE([
391+
#include <linux/hid.h>
392+
#ifndef hid_warn_ratelimited
393+
#error "hid_warn_ratelimited is not defined"
394+
#endif
395+
],[
396+
],[
397+
HAVE_HID_WARN_RATELIMITED=yes
398+
AC_MSG_RESULT([yes])
399+
AC_DEFINE([WACOM_HID_WARN_RATELIMITED], [], [kernel defines hid_warn_ratelimited from v6.17])
400+
],[
401+
HAVE_HID_WARN_RATELIMITED=no
402+
AC_MSG_RESULT([no])
403+
])
404+
405+
dnl Check if __free exists
406+
AC_MSG_CHECKING(__free)
407+
WACOM_LINUX_TRY_COMPILE([
408+
#include <linux/cleanup.h>
409+
#ifndef __free
410+
#error "__free is not defined"
411+
#endif
412+
],[
413+
],[
414+
HAVE_CLEANUP_FREE=yes
415+
AC_MSG_RESULT([yes])
416+
AC_DEFINE([WACOM_CLEANUP_FREE], [], [kernel defines __free from v6.5])
417+
],[
418+
HAVE_CLEANUP_FREE=no
419+
AC_MSG_RESULT([no])
420+
])
421+
422+
dnl Check if scoped_guard exists
423+
AC_MSG_CHECKING(scoped_guard)
424+
WACOM_LINUX_TRY_COMPILE([
425+
#include <linux/cleanup.h>
426+
#ifndef scoped_guard
427+
#error "scoped_guard is not defined"
428+
#endif
429+
],[
430+
],[
431+
HAVE_SCOPED_GUARD=yes
432+
AC_MSG_RESULT([yes])
433+
AC_DEFINE([WACOM_SCOPED_GUARD], [], [kernel defines scoped_guard from v6.5])
434+
],[
435+
HAVE_SCOPED_GUARD=no
436+
AC_MSG_RESULT([no])
437+
])
438+
439+
dnl Check if guard exists
440+
AC_MSG_CHECKING(guard)
441+
WACOM_LINUX_TRY_COMPILE([
442+
#include <linux/cleanup.h>
443+
#ifndef guard
444+
#error "guard is not defined"
445+
#endif
446+
],[
447+
],[
448+
HAVE_GUARD=yes
449+
AC_MSG_RESULT([yes])
450+
AC_DEFINE([WACOM_GUARD], [], [kernel defines guard from v6.5])
451+
],[
452+
HAVE_GUARD=no
453+
AC_MSG_RESULT([no])
454+
])
455+
456+
dnl Check if define_simple_dev_pm_ops exists
457+
AC_MSG_CHECKING(define_simple_dev_pm_ops)
458+
WACOM_LINUX_TRY_COMPILE([
459+
#include <linux/pm.h>
460+
#ifndef DEFINE_SIMPLE_DEV_PM_OPS
461+
#error "define_simple_dev_pm_ops is not defined"
462+
#endif
463+
],[
464+
],[
465+
HAVE_DEFINE_SIMPLE_DEV_PM_OPS=yes
466+
AC_MSG_RESULT([yes])
467+
AC_DEFINE([WACOM_DEFINE_SIMPLE_DEV_PM_OPS], [], [kernel defines define_simple_dev_pm_ops from v5.17])
468+
],[
469+
HAVE_DEFINE_SIMPLE_DEV_PM_OPS=no
470+
AC_MSG_RESULT([no])
471+
])
472+
388473
dnl Check which version of the driver we should compile
389474
AC_DEFUN([WCM_EXPLODE], [$(echo "$1" | awk '{split($[0],x,"[[^0-9]]"); printf("%03d%03d%03d\n",x[[1]],x[[2]],x[[3]]);}')])
390475
EXPLODED_VER="WCM_EXPLODE($MODUTS)"

0 commit comments

Comments
 (0)