From: Guenter Roeck <linux@roeck-us.net>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH 2/4] hwmon: (applesmc) Do not return random value in error case
Date: Wed, 20 Jun 2012 15:00:42 +0000 [thread overview]
Message-ID: <20120620150042.GA14640@roeck-us.net> (raw)
In-Reply-To: <1340120803-23543-2-git-send-email-linux@roeck-us.net>
On Wed, Jun 20, 2012 at 04:44:05PM +0200, Jean Delvare wrote:
> On Tue, 19 Jun 2012 08:46:41 -0700, Guenter Roeck wrote:
> > If a bad parameter is passed to applesmc_read_motion_sensor(), an uninitialized
> > and thus arbitrary value is returned. Fix by returning immediately if a bad
> > parameter is detected.
> >
> > Cc: Henrik Rydberg <rydberg@euromail.se>
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> > drivers/hwmon/applesmc.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
> > index f082e48..cc8dd57 100644
> > --- a/drivers/hwmon/applesmc.c
> > +++ b/drivers/hwmon/applesmc.c
> > @@ -450,7 +450,7 @@ static int applesmc_read_motion_sensor(int index, s16 *value)
> > ret = applesmc_read_key(MOTION_SENSOR_Z_KEY, buffer, 2);
> > break;
> > default:
> > - ret = -EINVAL;
> > + return -EINVAL;
> > }
> >
> > *value = ((s16)buffer[0] << 8) | buffer[1];
>
> It doesn't really matter as this code is never executed anyway. That
> would be a driver bug if it was. A better fix would probably be to get
> rid of this branch altogether.
>
If we do that, the compiler will likely complain that ret may be used but not set.
I could add BUG() or WARN(), but I am not sure if that is worth it.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2012-06-20 15:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-19 15:46 [lm-sensors] [PATCH 2/4] hwmon: (applesmc) Do not return random value in error case Guenter Roeck
2012-06-19 17:37 ` Henrik Rydberg
2012-06-20 14:44 ` Jean Delvare
2012-06-20 15:00 ` Guenter Roeck [this message]
2012-06-20 16:01 ` Jean Delvare
2012-06-20 16:03 ` Henrik Rydberg
2012-06-20 16:38 ` Guenter Roeck
2012-06-20 17:34 ` Jean Delvare
2012-06-20 17:48 ` Guenter Roeck
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=20120620150042.GA14640@roeck-us.net \
--to=linux@roeck-us.net \
--cc=lm-sensors@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 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.