[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170221134438.59469-1-pranjas@gmail.com>
Date: Tue, 21 Feb 2017 19:14:38 +0530
From: "Pranay Kr. Srivastava" <pranjas@...il.com>
To: w.d.hubbs@...il.com, chris@...-brannons.com, kirk@...sers.ca,
samuel.thibault@...-lyon.org, gregkh@...uxfoundation.org,
sfr@...b.auug.org.au, speakup@...ux-speakup.org,
devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org
Cc: "Pranay Kr. Srivastava" <pranjas@...il.com>
Subject: [PATCH Speakup v2] return same error value from spk_set_key_info
This patch makes spk_set_key_info return -EINVAL
in case of failure instead of returning 4 different
values for the type of error that occurred.
Print the offending values instead as debug message.
Signed-off-by: Pranay Kr. Srivastava <pranjas@...il.com>
---
drivers/staging/speakup/main.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index c2f70ef..ad95905 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -1216,13 +1216,20 @@ int spk_set_key_info(const u_char *key_info, u_char *k_buffer)
u_char ch, version, num_keys;
version = *cp++;
- if (version != KEY_MAP_VER)
- return -1;
+ if (version != KEY_MAP_VER) {
+ pr_debug("version found %d should be %d\n",
+ version, KEY_MAP_VER);
+ return -EINVAL;
+ }
num_keys = *cp;
states = (int)cp[1];
key_data_len = (states + 1) * (num_keys + 1);
- if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(spk_key_buf))
- return -2;
+ if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(spk_key_buf)) {
+ pr_debug("key_data_len = %d, SHIFT_TBL_SIZE + 4 = %d,\t"
+ "sizeof(spk_key_buf) = %lu\n", key_data_len,
+ SHIFT_TBL_SIZE + 4, sizeof(spk_key_buf));
+ return -EINVAL;
+ }
memset(k_buffer, 0, SHIFT_TBL_SIZE);
memset(spk_our_keys, 0, sizeof(spk_our_keys));
spk_shift_table = k_buffer;
@@ -1233,14 +1240,19 @@ int spk_set_key_info(const u_char *key_info, u_char *k_buffer)
cp1 += 2; /* now pointing at shift states */
for (i = 1; i <= states; i++) {
ch = *cp1++;
- if (ch >= SHIFT_TBL_SIZE)
- return -3;
+ if (ch >= SHIFT_TBL_SIZE) {
+ pr_debug("ch = %d, SHIFT_TBL_SIZE = %d\n", ch,
+ SHIFT_TBL_SIZE);
+ return -EINVAL;
+ }
spk_shift_table[ch] = i;
}
keymap_flags = *cp1++;
while ((ch = *cp1)) {
- if (ch >= MAX_KEY)
- return -4;
+ if (ch >= MAX_KEY) {
+ pr_debug("ch = %d, MAX_KEY = %d\n", ch, MAX_KEY);
+ return -EINVAL;
+ }
spk_our_keys[ch] = cp1;
cp1 += states + 1;
}
--
2.10.2
Powered by blists - more mailing lists