From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: chris.hudson.comp.eng@gmail.com
Cc: linux-input@vger.kernel.org, jic23@cam.ac.uk,
Chris Hudson <chudson@kionix.com>
Subject: Re: [PATCH] input:Misc changes against kxtj9 v5 patch
Date: Tue, 5 Jul 2011 13:05:48 -0700 [thread overview]
Message-ID: <20110705200548.GB15876@core.coreip.homeip.net> (raw)
In-Reply-To: <1309895754-5441-1-git-send-email-chris.hudson.comp.eng@gmail.com>
On Tue, Jul 05, 2011 at 03:55:54PM -0400, chris.hudson.comp.eng@gmail.com wrote:
> From: Chris Hudson <chudson@kionix.com>
>
> As requested, miscellaneous changes originally suggested by Jonathan Cameron,
> patched against the original kxtj9 v5 patch.
>
> Signed-off-by: Chris Hudson <chudson@kionix.com>
> ---
> drivers/input/misc/kxtj9.c | 38 +++++++++++++-------------------------
> include/linux/input/kxtj9.h | 10 +---------
> 2 files changed, 14 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/input/misc/kxtj9.c b/drivers/input/misc/kxtj9.c
> index 7faf155..b2da841 100644
> --- a/drivers/input/misc/kxtj9.c
> +++ b/drivers/input/misc/kxtj9.c
> @@ -71,6 +71,15 @@ static const struct {
> { 0, ODR12_5F},
> };
>
> +static const struct {
> + u8 g_range;
> + u8 shift;
> +} kxtj9_range[] = {
> + { 0, 4 }, /* +/-2g */
> + { (1 << 3), 3 }, /* +/-4g */
> + { (1 << 4), 2 }, /* +/-8g */
> +};
> +
> struct kxtj9_data {
> struct i2c_client *client;
> struct kxtj9_platform_data pdata;
> @@ -129,25 +138,9 @@ static void kxtj9_report_acceleration_data(struct kxtj9_data *tj9)
>
> static int kxtj9_update_g_range(struct kxtj9_data *tj9, u8 new_g_range)
> {
> - switch (new_g_range) {
> - case KXTJ9_G_2G:
> - tj9->shift = SHIFT_ADJ_2G;
> - break;
> -
> - case KXTJ9_G_4G:
> - tj9->shift = SHIFT_ADJ_4G;
> - break;
> -
> - case KXTJ9_G_8G:
> - tj9->shift = SHIFT_ADJ_8G;
> - break;
> -
> - default:
> - return -EINVAL;
> - }
> -
> + tj9->shift = kxtj9_range[new_g_range].shift;
This is not safe, you still need to sanitize input to make sure you do
not go beyond array boundaries.
--
Dmitry
next prev parent reply other threads:[~2011-07-05 20:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-05 19:55 [PATCH] input:Misc changes against kxtj9 v5 patch chris.hudson.comp.eng
2011-07-05 20:05 ` Dmitry Torokhov [this message]
[not found] ` <CAB7Re7XDB6Rmckxidgr+90Br5LhYk_5Pi_JQXTLd9QS2V+Vm0A@mail.gmail.com>
[not found] ` <20110705203502.GC15876@core.coreip.homeip.net>
2011-07-06 15:42 ` Christopher Hudson
2011-07-06 15:58 ` Christopher Hudson
2011-07-07 5:19 ` Dmitry Torokhov
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=20110705200548.GB15876@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=chris.hudson.comp.eng@gmail.com \
--cc=chudson@kionix.com \
--cc=jic23@cam.ac.uk \
--cc=linux-input@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).