Skip to contentSkip to conversation

iio: cros_ec_accel_legacy: Always release lock when returning from _read()

PATCH In review Matthias Kaehlcke 4 participants 7 messages Jul 15, 2019

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

PATCH 1/1 iio: cros_ec_accel_legacy: Always release lock when returning from _read()

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/cros_ec_accel_legacy.c +2 -1
index 46bb2e421bb9..27ca4a64dddf 100644
@@ -206,7 +206,8 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_CALIBBIAS:
 		/* Calibration not supported. */
 		*val = 0;
-		return IIO_VAL_INT;
+		ret = IIO_VAL_INT;
+		break;
 	default:
 		return -EINVAL;
 	}
Signature · 1 line
2.22.0.510.g264f2c817a-goog
#1 lore raw

Hi,

Quoted 8 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Quoted 5 lines
Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

See also <https://lkml.kernel.org/r/[email protected]>

Actually, the "Fixes" tag is wrong here, though. The problem only exists because we have <https://crrev.com/c/1632659> in our tree, AKA ("FROMLIST: iio: cros_ec : Extend legacy support to ARM device"). Before that there was no mutex. For upstream purposes this could probably be squashed into the original patch.

-Doug

#2 lore raw
Quoted 17 lines · Doug Anderson

Hi,

Quoted 8 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Quoted 5 lines
Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 7 lines

See also <https://lkml.kernel.org/r/[email protected]>

Actually, the "Fixes" tag is wrong here, though. The problem only exists because we have <https://crrev.com/c/1632659> in our tree, AKA ("FROMLIST: iio: cros_ec : Extend legacy support to ARM device"). Before that there was no mutex. For upstream purposes this could probably be squashed into the original patch.

Oops, I didn't realize that upstream doesn't have the mutex. In this case the entire patch as is with it's commit message doesn't make much sense.

#3 lore raw
In reply to Matthias Kaehlcke

Hi Matthias,

Quoted 18 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/accel/cros_ec_accel_legacy.c +0 -0
index 46bb2e421bb9..27ca4a64dddf 100644

drivers/iio/accel/cros_ec_accel_legacy.c static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · line 210

Quoted 6 lines
drivers/iio/accel/cros_ec_accel_legacy.c +2 -1
@@ -206,7 +206,8 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_CALIBBIAS:
 		/* Calibration not supported. */
 		*val = 0;
-		return IIO_VAL_INT;
+		ret = IIO_VAL_INT;
+		break;

The value of ret is not used below this. It seems to be only used in case IIO_CHAN_INFO_RAW. In fact, with your change, there's no return value at all and we just reach the end of cros_ec_accel_legacy_read.

Quoted 6 lines
drivers/iio/accel/cros_ec_accel_legacy.c +0 -0
 	default:
 		return -EINVAL;
 	}
Signature · 1 line
2.22.0.510.g264f2c817a-goog
Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
#4 lore raw

Hi Benson,

Quoted 16 lines · Benson Leung

Hi Matthias,

Quoted 13 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 21 lines

drivers/iio/accel/cros_ec_accel_legacy.c static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · line 210

Quoted 11 lines
drivers/iio/accel/cros_ec_accel_legacy.c +2 -1
index 46bb2e421bb9..27ca4a64dddf 100644
@@ -206,7 +206,8 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_CALIBBIAS:
 		/* Calibration not supported. */
 		*val = 0;
-		return IIO_VAL_INT;
+		ret = IIO_VAL_INT;
+		break;

The value of ret is not used below this. It seems to be only used in case IIO_CHAN_INFO_RAW. In fact, with your change, there's no return value at all and we just reach the end of cros_ec_accel_legacy_read.

Quoted 3 lines
drivers/iio/accel/cros_ec_accel_legacy.c +0 -0
 	default:
 		return -EINVAL;
 	}

I messed up. I was over-confident that a FROMLIST patch in our 4.19 kernel + this patch applying on upstream means that upstream uses the same code. I should have double-checked that the upstream context is actually the same.

Sorry for the noise.

#5 lore raw

Sorry for the original mistake. I upload a patch at
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1702884.

Quoted 48 lines · Matthias Kaehlcke

Hi Benson,

Quoted 16 lines · Benson Leung

Hi Matthias,

Quoted 13 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 21 lines

drivers/iio/accel/cros_ec_accel_legacy.c static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · line 210

Quoted 11 lines
drivers/iio/accel/cros_ec_accel_legacy.c +2 -1
index 46bb2e421bb9..27ca4a64dddf 100644
@@ -206,7 +206,8 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
    case IIO_CHAN_INFO_CALIBBIAS:
            /* Calibration not supported. */
            *val = 0;
-           return IIO_VAL_INT;
+           ret = IIO_VAL_INT;
+           break;

The value of ret is not used below this. It seems to be only used in case IIO_CHAN_INFO_RAW. In fact, with your change, there's no return value at all and we just reach the end of cros_ec_accel_legacy_read.

Quoted 3 lines
drivers/iio/accel/cros_ec_accel_legacy.c +0 -0
    default:
            return -EINVAL;
    }

I messed up. I was over-confident that a FROMLIST patch in our 4.19 kernel + this patch applying on upstream means that upstream uses the same code. I should have double-checked that the upstream context is actually the same.

Sorry for the noise.

#6 lore raw

Let's use Matthias CL.

Quoted 53 lines · Gwendal Grignou

Sorry for the original mistake. I upload a patch at
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1702884.

Quoted 48 lines · Matthias Kaehlcke

Hi Benson,

Quoted 16 lines · Benson Leung

Hi Matthias,

Quoted 13 lines · Matthias Kaehlcke

Before doing any actual work cros_ec_accel_legacy_read() acquires a mutex, which is released at the end of the function. However for 'calibbias' channels the function returns directly, without releasing the lock. The next attempt to acquire the lock blocks forever. Instead of an explicit return statement use the common return path, which releases the lock.

Fixes 11b86c7004ef1 ("platform/chrome: Add cros_ec_accel_legacy driver")
---
 drivers/iio/accel/cros_ec_accel_legacy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 21 lines

drivers/iio/accel/cros_ec_accel_legacy.c static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev, · line 210

Quoted 11 lines
drivers/iio/accel/cros_ec_accel_legacy.c +2 -1
index 46bb2e421bb9..27ca4a64dddf 100644
@@ -206,7 +206,8 @@ static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
    case IIO_CHAN_INFO_CALIBBIAS:
            /* Calibration not supported. */
            *val = 0;
-           return IIO_VAL_INT;
+           ret = IIO_VAL_INT;
+           break;

The value of ret is not used below this. It seems to be only used in case IIO_CHAN_INFO_RAW. In fact, with your change, there's no return value at all and we just reach the end of cros_ec_accel_legacy_read.

Quoted 3 lines
drivers/iio/accel/cros_ec_accel_legacy.c +0 -0
    default:
            return -EINVAL;
    }

I messed up. I was over-confident that a FROMLIST patch in our 4.19 kernel + this patch applying on upstream means that upstream uses the same code. I should have double-checked that the upstream context is actually the same.

Sorry for the noise.