From: "Pranay Kr. Srivastava" <pranjas@gmail.com>
To: w.d.hubbs@gmail.com, chris@the-brannons.com, kirk@reisers.ca,
samuel.thibault@ens-lyon.org, gregkh@linuxfoundation.org,
sfr@canb.auug.org.au, speakup@linux-speakup.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Cc: "Pranay Kr. Srivastava" <pranjas@gmail.com>
Subject: [PATCH staging/speakup v3 1/3] return same error value from spk_set_key_info
Date: Tue, 21 Mar 2017 12:40:22 +0530 [thread overview]
Message-ID: <20170321071024.2328-2-pranjas@gmail.com> (raw)
In-Reply-To: <20170321071024.2328-1-pranjas@gmail.com>
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@gmail.com>
---
drivers/staging/speakup/main.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index c2f70ef..a1d5b66 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -1216,13 +1216,19 @@ 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("too many key_infos (%d over %u)\n",
+ key_data_len + SHIFT_TBL_SIZE + 4, (unsigned int)(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 +1239,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("(%d) not valid shift state (max_allowed = %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("(%d), not valid key, (max_allowed = %d)\n", ch, MAX_KEY);
+ return -EINVAL;
+ }
spk_our_keys[ch] = cp1;
cp1 += states + 1;
}
--
2.10.2
next prev parent reply other threads:[~2017-03-21 7:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 8:27 [PATCH SPEAKUP v2 0/3] cleanup error and initilization Pranay Kr. Srivastava
2017-02-28 8:27 ` [PATCH SPEAKUP v2 1/3] return same error value from spk_set_key_info Pranay Kr. Srivastava
2017-02-28 9:04 ` Samuel Thibault
2017-03-01 7:51 ` Greg KH
2017-03-21 7:10 ` [PATCH staging/speakup v3 0/3] cleanup error and initilization Pranay Kr. Srivastava
2017-03-21 7:10 ` Pranay Kr. Srivastava [this message]
2017-03-21 7:10 ` [PATCH staging/speakup v3 2/3] remove unnecessary initial allocation of vc Pranay Kr. Srivastava
2017-03-21 7:10 ` [PATCH staging/speakup v3 3/3] use speakup_allocate as per required context Pranay Kr. Srivastava
2017-03-23 13:17 ` Greg KH
2017-03-24 8:37 ` [[RESEND]PATCH " Pranay Kr. Srivastava
2017-03-24 8:43 ` Greg KH
2017-03-24 10:14 ` Pranay Srivastava
2017-02-28 8:27 ` [PATCH SPEAKUP v2 2/3] remove unecessary initial allocation of vc Pranay Kr. Srivastava
2017-02-28 9:05 ` Samuel Thibault
2017-02-28 8:27 ` [PATCH SPEAKUP v2 3/3] use spkeaup_allocate as per required context Pranay Kr. Srivastava
2017-02-28 9:05 ` Samuel Thibault
2017-03-01 7:51 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170321071024.2328-2-pranjas@gmail.com \
--to=pranjas@gmail.com \
--cc=chris@the-brannons.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=kirk@reisers.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=sfr@canb.auug.org.au \
--cc=speakup@linux-speakup.org \
--cc=w.d.hubbs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.