Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1511022 > unrolled thread

[PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()

Started byBrian Masney <masneyb@onstation.org>
First post2016-10-28 12:10 +0200
Last post2016-10-30 18:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte() Brian Masney <masneyb@onstation.org> - 2016-10-28 12:10 +0200
    Re: [PATCH 02/10] staging: iio: tsl2583: check for error code from  i2c_smbus_read_byte() Jonathan Cameron <jic23@kernel.org> - 2016-10-30 18:50 +0100

#1511022 — [PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()

FromBrian Masney <masneyb@onstation.org>
Date2016-10-28 12:10 +0200
Subject[PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()
Message-ID<sxcgO-6SN-9@gated-at.bofh.it>
taos_i2c_read() and taos_als_calibrate() does not check to see if the
value returned by i2c_smbus_read_byte() was an error code. This patch
adds the appropriate error handling.

Signed-off-by: Brian Masney <masneyb@onstation.org>
---
 drivers/staging/iio/light/tsl2583.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index fd4b6ef..35c1696 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -171,7 +171,14 @@ taos_i2c_read(struct i2c_client *client, u8 reg, u8 *val, unsigned int len)
 			return ret;
 		}
 		/* read the data */
-		*val = i2c_smbus_read_byte(client);
+		ret = i2c_smbus_read_byte(client);
+		if (ret < 0) {
+			dev_err(&client->dev,
+				"%s failed to read byte after writing to register %x\n",
+				__func__, reg);
+			return ret;
+		}
+		*val = ret;
 		val++;
 		reg++;
 	}
@@ -355,6 +362,13 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 	}
 
 	reg_val = i2c_smbus_read_byte(chip->client);
+	if (reg_val < 0) {
+		dev_err(&chip->client->dev,
+			"%s failed to read after writing to the CNTRL register\n",
+			__func__);
+		return ret;
+	}
+
 	if ((reg_val & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
 			!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
 		dev_err(&chip->client->dev,
@@ -371,6 +385,12 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
 		return ret;
 	}
 	reg_val = i2c_smbus_read_byte(chip->client);
+	if (reg_val < 0) {
+		dev_err(&chip->client->dev,
+			"%s failed to read after writing to the STATUS register\n",
+			__func__);
+		return ret;
+	}
 
 	if ((reg_val & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
 		dev_err(&chip->client->dev,
-- 
2.7.4

[toc] | [next] | [standalone]


#1512152 — Re: [PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()

FromJonathan Cameron <jic23@kernel.org>
Date2016-10-30 18:50 +0100
SubjectRe: [PATCH 02/10] staging: iio: tsl2583: check for error code from i2c_smbus_read_byte()
Message-ID<sy2p3-7HR-13@gated-at.bofh.it>
In reply to#1511022
On 28/10/16 11:00, Brian Masney wrote:
> taos_i2c_read() and taos_als_calibrate() does not check to see if the
> value returned by i2c_smbus_read_byte() was an error code. This patch
> adds the appropriate error handling.
> 
> Signed-off-by: Brian Masney <masneyb@onstation.org>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders
to play with it.

Also Cc'd Jon on basis he might want to run his eye of these.
> ---
>  drivers/staging/iio/light/tsl2583.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
> index fd4b6ef..35c1696 100644
> --- a/drivers/staging/iio/light/tsl2583.c
> +++ b/drivers/staging/iio/light/tsl2583.c
> @@ -171,7 +171,14 @@ taos_i2c_read(struct i2c_client *client, u8 reg, u8 *val, unsigned int len)
>  			return ret;
>  		}
>  		/* read the data */
> -		*val = i2c_smbus_read_byte(client);
> +		ret = i2c_smbus_read_byte(client);
> +		if (ret < 0) {
> +			dev_err(&client->dev,
> +				"%s failed to read byte after writing to register %x\n",
> +				__func__, reg);
> +			return ret;
> +		}
> +		*val = ret;
>  		val++;
>  		reg++;
>  	}
> @@ -355,6 +362,13 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  	}
>  
>  	reg_val = i2c_smbus_read_byte(chip->client);
> +	if (reg_val < 0) {
> +		dev_err(&chip->client->dev,
> +			"%s failed to read after writing to the CNTRL register\n",
> +			__func__);
> +		return ret;
> +	}
> +
>  	if ((reg_val & (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON))
>  			!= (TSL258X_CNTL_ADC_ENBL | TSL258X_CNTL_PWR_ON)) {
>  		dev_err(&chip->client->dev,
> @@ -371,6 +385,12 @@ static int taos_als_calibrate(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	reg_val = i2c_smbus_read_byte(chip->client);
> +	if (reg_val < 0) {
> +		dev_err(&chip->client->dev,
> +			"%s failed to read after writing to the STATUS register\n",
> +			__func__);
> +		return ret;
> +	}
>  
>  	if ((reg_val & TSL258X_STA_ADC_VALID) != TSL258X_STA_ADC_VALID) {
>  		dev_err(&chip->client->dev,
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web