summaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/joydump.c
diff options
context:
space:
mode:
authorKees Cook <kees+treewide@kernel.org>2026-09-02 15:31:14 -0700
committerKees Cook <kees@kernel.org>2026-09-04 21:37:00 -0700
commit3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d (patch)
treec65086f9bdcd48c6360fb7cb4598bca084da1f32 /drivers/input/joystick/joydump.c
downloadlinux-stable-3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d.tar.gz
linux-stable-3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d.zip
treewide: refresh kmalloc_obj() conversionsgrafted
This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook <kees+treewide@kernel.org>
Diffstat (limited to 'drivers/input/joystick/joydump.c')
-rw-r--r--drivers/input/joystick/joydump.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
new file mode 100644
index 000000000..c9cbdcc7f
--- /dev/null
+++ b/drivers/input/joystick/joydump.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 1996-2001 Vojtech Pavlik
+ */
+
+/*
+ * This is just a very simple driver that can dump the data
+ * out of the joystick port into the syslog ...
+ */
+
+#include <linux/module.h>
+#include <linux/gameport.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+
+#define DRIVER_DESC "Gameport data dumper module"
+
+MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+
+#define BUF_SIZE 256
+
+struct joydump {
+ unsigned int time;
+ unsigned char data;
+};
+
+static int joydump_connect(struct gameport *gameport, struct gameport_driver *drv)
+{
+ struct joydump *buf; /* all entries */
+ struct joydump *dump, *prev; /* one entry each */
+ int axes[4], buttons;
+ int i, j, t, timeout;
+ unsigned long flags;
+ unsigned char u;
+
+ printk(KERN_INFO "joydump: ,------------------ START ----------------.\n");
+ printk(KERN_INFO "joydump: | Dumping: %30s |\n", gameport->phys);
+ printk(KERN_INFO "joydump: | Speed: %28d kHz |\n", gameport->speed);
+
+ if (gameport_open(gameport, drv, GAMEPORT_MODE_RAW)) {
+
+ printk(KERN_INFO "joydump: | Raw mode not available - trying cooked. |\n");
+
+ if (gameport_open(gameport, drv, GAMEPORT_MODE_COOKED)) {
+
+ printk(KERN_INFO "joydump: | Cooked not available either. Failing. |\n");
+ printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
+ return -ENODEV;
+ }
+
+ gameport_cooked_read(gameport, axes, &buttons);
+
+ for (i = 0; i < 4; i++)
+ printk(KERN_INFO "joydump: | Axis %d: %4d. |\n", i, axes[i]);
+ printk(KERN_INFO "joydump: | Buttons %02x. |\n", buttons);
+ printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
+ }
+
+ timeout = gameport_time(gameport, 10000); /* 10 ms */
+
+ buf = kmalloc_objs(struct joydump, BUF_SIZE);
+ if (!buf) {
+ printk(KERN_INFO "joydump: no memory for testing\n");
+ goto jd_end;
+ }
+ dump = buf;
+ t = 0;
+ i = 1;
+
+ local_irq_save(flags);
+
+ u = gameport_read(gameport);
+
+ dump->data = u;
+ dump->time = t;
+ dump++;
+
+ gameport_trigger(gameport);
+
+ while (i < BUF_SIZE && t < timeout) {
+
+ dump->data = gameport_read(gameport);
+
+ if (dump->data ^ u) {
+ u = dump->data;
+ dump->time = t;
+ i++;
+ dump++;
+ }
+ t++;
+ }
+
+ local_irq_restore(flags);
+
+/*
+ * Dump data.
+ */
+
+ t = i;
+ dump = buf;
+ prev = dump;
+
+ printk(KERN_INFO "joydump: >------------------ DATA -----------------<\n");
+ printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ", 0, 0);
+ for (j = 7; j >= 0; j--)
+ printk("%d", (dump->data >> j) & 1);
+ printk(" |\n");
+ dump++;
+
+ for (i = 1; i < t; i++, dump++, prev++) {
+ printk(KERN_INFO "joydump: | index: %3d delta: %3d us data: ",
+ i, dump->time - prev->time);
+ for (j = 7; j >= 0; j--)
+ printk("%d", (dump->data >> j) & 1);
+ printk(" |\n");
+ }
+ kfree(buf);
+
+jd_end:
+ printk(KERN_INFO "joydump: `------------------- END -----------------'\n");
+
+ return 0;
+}
+
+static void joydump_disconnect(struct gameport *gameport)
+{
+ gameport_close(gameport);
+}
+
+static struct gameport_driver joydump_drv = {
+ .driver = {
+ .name = "joydump",
+ },
+ .description = DRIVER_DESC,
+ .connect = joydump_connect,
+ .disconnect = joydump_disconnect,
+};
+
+module_gameport_driver(joydump_drv);