Skip to contentSkip to conversation

Staging: iio: signedness bug

PATCH In review Dan Carpenter 2 participants 2 messages Aug 10, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Staging: iio: signedness bug

i2c_smbus_read_byte_data() returns an s32 type. We need to change "rate" to signed for the error handling to work.

Also I changed it to propogate the error code instead of just returning -EINVAL. Other error codes could be -EAGAIN for example.

drivers/staging/iio/magnetometer/hmc5843.c +2 -2
index 92f6c6f..3d3bac4 100644
@@ -385,11 +385,11 @@ static ssize_t show_sampling_frequency(struct device *dev,
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u32 rate;
+	s32 rate;
 
 	rate = i2c_smbus_read_byte_data(client,  this_attr->address);
 	if (rate < 0)
-		return -EINVAL;
+		return rate;
 	rate = (rate & RATE_BITMASK) >> RATE_OFFSET;
 	return sprintf(buf, "%s\n", regval_to_samp_freq[rate]);
 }
Acked-by on v1 1/2
#1 lore raw
Quoted 7 lines · Dan Carpenter

i2c_smbus_read_byte_data() returns an s32 type. We need to change "rate" to signed for the error handling to work.

Also I changed it to propogate the error code instead of just returning -EINVAL. Other error codes could be -EAGAIN for example.

Thanks

Quoted 19 lines
drivers/staging/iio/magnetometer/hmc5843.c +2 -2
index 92f6c6f..3d3bac4 100644
@@ -385,11 +385,11 @@ static ssize_t show_sampling_frequency(struct device *dev,
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct i2c_client *client = to_i2c_client(indio_dev->dev.parent);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u32 rate;
+	s32 rate;
 
 	rate = i2c_smbus_read_byte_data(client,  this_attr->address);
 	if (rate < 0)
-		return -EINVAL;
+		return rate;
 	rate = (rate & RATE_BITMASK) >> RATE_OFFSET;
 	return sprintf(buf, "%s\n", regval_to_samp_freq[rate]);
 }