From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751963AbdB1JPp (ORCPT ); Tue, 28 Feb 2017 04:15:45 -0500 Received: from hera.aquilenet.fr ([141.255.128.1]:52073 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123AbdB1JPJ (ORCPT ); Tue, 28 Feb 2017 04:15:09 -0500 Date: Tue, 28 Feb 2017 10:04:44 +0100 From: Samuel Thibault To: "Pranay Kr. Srivastava" Cc: w.d.hubbs@gmail.com, chris@the-brannons.com, kirk@reisers.ca, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, speakup@linux-speakup.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH SPEAKUP v2 1/3] return same error value from spk_set_key_info Message-ID: <20170228090444.seq7cmny6l432ix4@var.youpi.perso.aquilenet.fr> Mail-Followup-To: Samuel Thibault , "Pranay Kr. Srivastava" , w.d.hubbs@gmail.com, chris@the-brannons.com, kirk@reisers.ca, gregkh@linuxfoundation.org, sfr@canb.auug.org.au, speakup@linux-speakup.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20170228082755.53396-1-pranjas@gmail.com> <20170228082755.53396-2-pranjas@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170228082755.53396-2-pranjas@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pranay Kr. Srivastava, on mar. 28 févr. 2017 13:57:53 +0530, wrote: > 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 Reviewed-by: Samuel Thibault > --- > 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 > -- Samuel Progress (n.): The process through which the Internet has evolved from smart people in front of dumb terminals to dumb people in front of smart terminals.