Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: gameport - provide default trigger() and read()

Instead of constantly checking pointer(s) for non-NULL-ness provide
default implementations of trigger() and read() and instantiate them during
pore registration if driver-specific versions were not provided.

Link: https://lore.kernel.org/r/ZGvoqP5PAAsJuky4@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+18 -11
+16 -2
drivers/input/gameport/gameport.c
··· 11 11 12 12 #include <linux/stddef.h> 13 13 #include <linux/module.h> 14 + #include <linux/io.h> 14 15 #include <linux/ioport.h> 15 16 #include <linux/init.h> 16 17 #include <linux/gameport.h> ··· 21 20 #include <linux/sched.h> /* HZ */ 22 21 #include <linux/mutex.h> 23 22 #include <linux/timekeeping.h> 24 - 25 - /*#include <asm/io.h>*/ 26 23 27 24 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 28 25 MODULE_DESCRIPTION("Generic gameport layer"); ··· 517 518 } 518 519 EXPORT_SYMBOL(gameport_set_phys); 519 520 521 + static void gameport_default_trigger(struct gameport *gameport) 522 + { 523 + outb(0xff, gameport->io); 524 + } 525 + 526 + static unsigned char gameport_default_read(struct gameport *gameport) 527 + { 528 + return inb(gameport->io); 529 + } 530 + 520 531 /* 521 532 * Prepare gameport port for registration. 522 533 */ ··· 544 535 gameport->dev.release = gameport_release_port; 545 536 if (gameport->parent) 546 537 gameport->dev.parent = &gameport->parent->dev; 538 + 539 + if (!gameport->trigger) 540 + gameport->trigger = gameport_default_trigger; 541 + if (!gameport->read) 542 + gameport->read = gameport_default_read; 547 543 548 544 INIT_LIST_HEAD(&gameport->node); 549 545 spin_lock_init(&gameport->timer_lock);
+2 -9
include/linux/gameport.h
··· 5 5 #ifndef _GAMEPORT_H 6 6 #define _GAMEPORT_H 7 7 8 - #include <asm/io.h> 9 8 #include <linux/types.h> 10 9 #include <linux/list.h> 11 10 #include <linux/mutex.h> ··· 164 165 165 166 static inline void gameport_trigger(struct gameport *gameport) 166 167 { 167 - if (gameport->trigger) 168 - gameport->trigger(gameport); 169 - else 170 - outb(0xff, gameport->io); 168 + gameport->trigger(gameport); 171 169 } 172 170 173 171 static inline unsigned char gameport_read(struct gameport *gameport) 174 172 { 175 - if (gameport->read) 176 - return gameport->read(gameport); 177 - else 178 - return inb(gameport->io); 173 + return gameport->read(gameport); 179 174 } 180 175 181 176 static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)