diff mbox series

[2/2] phy: mapphone-mdm6600: fix an error code problem in inv_mpu6050_read_raw

Message ID 20231020091413.205743-2-suhui@nfschina.com (mailing list archive)
State Changes Requested
Headers show
Series None | expand

Commit Message

Su Hui Oct. 20, 2023, 9:14 a.m. UTC
inv_mpu6050_sensor_show() can return -EINVAL or IIO_VAL_INT. Return the
true value rather than only return IIO_VAL_INT.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron Oct. 20, 2023, 3:55 p.m. UTC | #1
On Fri, 20 Oct 2023 17:14:14 +0800
Su Hui <suhui@nfschina.com> wrote:

> inv_mpu6050_sensor_show() can return -EINVAL or IIO_VAL_INT. Return the
> true value rather than only return IIO_VAL_INT.

What does this have to do with the phy: mapphone-mdm6600?

> 
> Signed-off-by: Su Hui <suhui@nfschina.com>

I'm not sure why inv_mpu6050_sensor_show() doesn't return
the actual error code from the regmap_bulk_read() and instead replaces it
with -EINVAL.  Given you are tidying up this related issues perhaps change
that as well?

static int inv_mpu6050_sensor_show(struct inv_mpu6050_state  *st, int reg,
				   int axis, int *val)
{
	int ind, result;
	__be16 d;

	ind = (axis - IIO_MOD_X) * 2;
	result = regmap_bulk_read(st->map, reg + ind, &d, sizeof(d));
	if (result)
		return -EINVAL;
//Make this return result;


	*val = (short)be16_to_cpup(&d);

	return IIO_VAL_INT;
}
> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 29f906c884bd..a9a5fb266ef1 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -749,13 +749,13 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
>  			ret = inv_mpu6050_sensor_show(st, st->reg->gyro_offset,
>  						chan->channel2, val);
>  			mutex_unlock(&st->lock);
> -			return IIO_VAL_INT;
> +			return ret;
>  		case IIO_ACCEL:
>  			mutex_lock(&st->lock);
>  			ret = inv_mpu6050_sensor_show(st, st->reg->accl_offset,
>  						chan->channel2, val);
>  			mutex_unlock(&st->lock);
> -			return IIO_VAL_INT;
> +			return ret;
>  
>  		default:
>  			return -EINVAL;
Su Hui Oct. 23, 2023, 1:33 a.m. UTC | #2
On 2023/10/20 23:55, Jonathan Cameron wrote:
> What does this have to do with the phy: mapphone-mdm6600?
Oh, really sorry for this. My careless mistake :( .
> I'm not sure why inv_mpu6050_sensor_show() doesn't return
> the actual error code from the regmap_bulk_read() and instead replaces it
> with -EINVAL.  Given you are tidying up this related issues perhaps change
> that as well?
>
> static int inv_mpu6050_sensor_show(struct inv_mpu6050_state  *st, int reg,
> 				   int axis, int *val)
> {
> 	int ind, result;
> 	__be16 d;
>
> 	ind = (axis - IIO_MOD_X) * 2;
> 	result = regmap_bulk_read(st->map, reg + ind, &d, sizeof(d));
> 	if (result)
> 		return -EINVAL;
> //Make this return result;

Sure, I will tidy up this, Thanks for your suggestion!

Su Hui
Su Hui Oct. 23, 2023, 3:29 a.m. UTC | #3
On 2023/10/23 09:33, Su Hui wrote:
> On 2023/10/20 23:55, Jonathan Cameron wrote:
>> I'm not sure why inv_mpu6050_sensor_show() doesn't return
>> the actual error code from the regmap_bulk_read() and instead 
>> replaces it
>> with -EINVAL.  Given you are tidying up this related issues perhaps 
>> change
>> that as well?
>>
>> static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int 
>> reg,
>>                    int axis, int *val)
>> {
>>     int ind, result;
>>     __be16 d;
>>
>>     ind = (axis - IIO_MOD_X) * 2;
>>     result = regmap_bulk_read(st->map, reg + ind, &d, sizeof(d));
>>     if (result)
>>         return -EINVAL;
>> //Make this return result;
>
> Sure, I will tidy up this, Thanks for your suggestion!

I'm not sure  whether the caller could handler this  when return 
'result' rather than '-EINVAL'.

This is not a big problem, maybe we shouldn't modify this code.

Su Hui
diff mbox series

Patch

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 29f906c884bd..a9a5fb266ef1 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -749,13 +749,13 @@  inv_mpu6050_read_raw(struct iio_dev *indio_dev,
 			ret = inv_mpu6050_sensor_show(st, st->reg->gyro_offset,
 						chan->channel2, val);
 			mutex_unlock(&st->lock);
-			return IIO_VAL_INT;
+			return ret;
 		case IIO_ACCEL:
 			mutex_lock(&st->lock);
 			ret = inv_mpu6050_sensor_show(st, st->reg->accl_offset,
 						chan->channel2, val);
 			mutex_unlock(&st->lock);
-			return IIO_VAL_INT;
+			return ret;
 
 		default:
 			return -EINVAL;