mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] return same error value from spk_set_key_info
@ 2017-02-21 11:54 Pranay Kr. Srivastava
  2017-02-21 12:24 ` Samuel Thibault
  0 siblings, 1 reply; 6+ messages in thread
From: Pranay Kr. Srivastava @ 2017-02-21 11:54 UTC (permalink / raw)
  To: w.d.hubbs, chris, kirk, samuel.thibault, gregkh, sfr, speakup,
	devel, linux-kernel
  Cc: Pranay Kr. Srivastava

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.

Retain the previous error values as debug messages
instead.

Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
 drivers/staging/speakup/main.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index c2f70ef..396a57a 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -1216,13 +1216,17 @@ 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 mismatch %d\n", -1);
+		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("Data len and Shift table too big %d\n", -2);
+		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 +1237,18 @@ 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("Key table size overflow %d\n", -3);
+			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("Max Key overflow %d\n", -4);
+			return -EINVAL;
+		}
 		spk_our_keys[ch] = cp1;
 		cp1 += states + 1;
 	}
-- 
2.10.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-21 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21 11:54 [PATCH] return same error value from spk_set_key_info Pranay Kr. Srivastava
2017-02-21 12:24 ` Samuel Thibault
2017-02-21 13:44   ` [PATCH Speakup v2] " Pranay Kr. Srivastava
2017-02-21 13:54     ` Samuel Thibault
2017-02-21 15:21     ` kbuild test robot
2017-02-21 15:36     ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®