Re: [PATCH 2/4] hwmon: (applesmc) Do not return random value in error case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
> > Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> > ---
> >  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@xxxxxxxxxxxxxx
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors


[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux