summaryrefslogtreecommitdiffstats
path: root/arch/m68k/emu/nfcon.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 /arch/m68k/emu/nfcon.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 'arch/m68k/emu/nfcon.c')
-rw-r--r--arch/m68k/emu/nfcon.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
new file mode 100644
index 000000000..f4657d9f4
--- /dev/null
+++ b/arch/m68k/emu/nfcon.c
@@ -0,0 +1,177 @@
+/*
+ * ARAnyM console driver
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file COPYING in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+
+#include <asm/natfeat.h>
+
+static int stderr_id;
+static struct tty_port nfcon_tty_port;
+static struct tty_driver *nfcon_tty_driver;
+
+static void nfputs(const u8 *str, size_t count)
+{
+ u8 buf[68];
+ unsigned long phys = virt_to_phys(buf);
+
+ buf[64] = 0;
+ while (count > 64) {
+ memcpy(buf, str, 64);
+ nf_call(stderr_id, phys);
+ str += 64;
+ count -= 64;
+ }
+ memcpy(buf, str, count);
+ buf[count] = 0;
+ nf_call(stderr_id, phys);
+}
+
+static void nfcon_write(struct console *con, const char *str,
+ unsigned int count)
+{
+ nfputs(str, count);
+}
+
+static struct tty_driver *nfcon_device(struct console *con, int *index)
+{
+ *index = 0;
+ return nfcon_tty_driver;
+}
+
+static struct console nf_console = {
+ .name = "nfcon",
+ .write = nfcon_write,
+ .device = nfcon_device,
+ .flags = CON_PRINTBUFFER,
+ .index = -1,
+};
+
+
+static int nfcon_tty_open(struct tty_struct *tty, struct file *filp)
+{
+ return 0;
+}
+
+static void nfcon_tty_close(struct tty_struct *tty, struct file *filp)
+{
+}
+
+static ssize_t nfcon_tty_write(struct tty_struct *tty, const u8 *buf,
+ size_t count)
+{
+ nfputs(buf, count);
+ return count;
+}
+
+static int nfcon_tty_put_char(struct tty_struct *tty, u8 ch)
+{
+ u8 temp[2] = { ch, 0 };
+
+ nf_call(stderr_id, virt_to_phys(temp));
+ return 1;
+}
+
+static unsigned int nfcon_tty_write_room(struct tty_struct *tty)
+{
+ return 64;
+}
+
+static const struct tty_operations nfcon_tty_ops = {
+ .open = nfcon_tty_open,
+ .close = nfcon_tty_close,
+ .write = nfcon_tty_write,
+ .put_char = nfcon_tty_put_char,
+ .write_room = nfcon_tty_write_room,
+};
+
+#ifndef MODULE
+
+static int __init nf_debug_setup(char *arg)
+{
+ if (strcmp(arg, "nfcon"))
+ return 0;
+
+ stderr_id = nf_get_id("NF_STDERR");
+ if (stderr_id) {
+ /*
+ * The console will be enabled when debug=nfcon is specified
+ * as a kernel parameter. Since this is a non-standard way
+ * of enabling consoles, it must be explicitly enabled.
+ */
+ nf_console.flags |= CON_ENABLED;
+ register_console(&nf_console);
+ }
+
+ return 0;
+}
+
+early_param("debug", nf_debug_setup);
+
+#endif /* !MODULE */
+
+static int __init nfcon_init(void)
+{
+ struct tty_driver *driver;
+ int res;
+
+ stderr_id = nf_get_id("NF_STDERR");
+ if (!stderr_id)
+ return -ENODEV;
+
+ driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW);
+ if (IS_ERR(driver))
+ return PTR_ERR(driver);
+
+ tty_port_init(&nfcon_tty_port);
+
+ driver->driver_name = "nfcon";
+ driver->name = "nfcon";
+ driver->type = TTY_DRIVER_TYPE_SYSTEM;
+ driver->subtype = SYSTEM_TYPE_TTY;
+ driver->init_termios = tty_std_termios;
+
+ tty_set_operations(driver, &nfcon_tty_ops);
+ tty_port_link_device(&nfcon_tty_port, driver, 0);
+ res = tty_register_driver(driver);
+ if (res) {
+ pr_err("failed to register nfcon tty driver\n");
+ tty_driver_kref_put(driver);
+ tty_port_destroy(&nfcon_tty_port);
+ return res;
+ }
+
+ nfcon_tty_driver = driver;
+
+ if (!console_is_registered(&nf_console))
+ register_console(&nf_console);
+
+ return 0;
+}
+
+static void __exit nfcon_exit(void)
+{
+ unregister_console(&nf_console);
+ tty_unregister_driver(nfcon_tty_driver);
+ tty_driver_kref_put(nfcon_tty_driver);
+ tty_port_destroy(&nfcon_tty_port);
+}
+
+module_init(nfcon_init);
+module_exit(nfcon_exit);
+
+MODULE_DESCRIPTION("Atari NatFeat console driver");
+MODULE_LICENSE("GPL");