diff --git a/drivers/bmi088/bmi088_core.c b/drivers/bmi088/bmi088_core.c index 3d6a75e8..509550f5 100644 --- a/drivers/bmi088/bmi088_core.c +++ b/drivers/bmi088/bmi088_core.c @@ -1039,15 +1039,11 @@ static irqreturn_t bmi_irq_thread(int irq, void *dev_id) goto out; } -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&st->snsrs[hw].bmi_iio->mlock); -#endif + mutex_lock(BMI_MUTEX(st->snsrs[hw].bmi_iio)); ret = bmi_i2c_rd(st, hw, reg, sizeof(sample), sample); -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&st->snsrs[hw].bmi_iio->mlock); -#endif + mutex_unlock(BMI_MUTEX(st->snsrs[hw].bmi_iio)); if (!ret) { bmi_iio_push_buf(st->snsrs[hw].bmi_iio, sample, @@ -1391,9 +1387,7 @@ static int __maybe_unused bmi_suspend(struct device *dev) st->suspend_en_st = 0; for (i = 0; i < st->hw_n; i++) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio)); /* check if sensor is enabled to begin with */ old_en_st = bmi_enable(st, st->snsrs[i].cfg.snsr_id, -1, false); @@ -1405,9 +1399,7 @@ static int __maybe_unused bmi_suspend(struct device *dev) ret |= temp_ret; } -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio)); } return ret; @@ -1421,15 +1413,11 @@ static int __maybe_unused bmi_resume(struct device *dev) int ret = 0; for (i = 0; i < st->hw_n; i++) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio)); if (st->suspend_en_st & (1 << st->snsrs[i].cfg.snsr_id)) ret |= bmi_enable(st, st->snsrs[i].cfg.snsr_id, 1, false); -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio)); } st->sts &= ~BMI_STS_SUSPEND; @@ -1447,17 +1435,13 @@ static void bmi_shutdown(struct i2c_client *client) st->sts |= BMI_STS_SHUTDOWN; for (i = 0; i < st->hw_n; i++) { if (st->iio_init_done[i]) -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio)); if (bmi_enable(st, st->snsrs[i].cfg.snsr_id, -1, false)) bmi_enable(st, st->snsrs[i].cfg.snsr_id, 0, false); if (st->iio_init_done[i]) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&st->snsrs[i].bmi_iio->mlock); -#endif + mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio)); } } } diff --git a/drivers/bmi088/bmi088_iio.c b/drivers/bmi088/bmi088_iio.c index 225531ca..3e959b67 100644 --- a/drivers/bmi088/bmi088_iio.c +++ b/drivers/bmi088/bmi088_iio.c @@ -231,14 +231,10 @@ static ssize_t bmi_iio_attr_store(struct device *dev, if (!indio_dev || !st || !this_attr) return -EINVAL; -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&indio_dev->mlock); -#endif + mutex_lock(BMI_MUTEX(indio_dev)); if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return -EPERM; } @@ -269,9 +265,7 @@ static ssize_t bmi_iio_attr_store(struct device *dev, ret = -EINVAL; } -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return ret; } @@ -294,17 +288,13 @@ static ssize_t bmi_iio_attr_show(struct device *dev, st->cfg->part, st->cfg->name); case BMI_ATTR_MATRIX: -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&indio_dev->mlock); -#endif + mutex_lock(BMI_MUTEX(indio_dev)); for (i = 0; i < 8; i++) t += snprintf(buf + t, PAGE_SIZE - t, "%hhd,", st->cfg->matrix[i]); t += snprintf(buf + t, PAGE_SIZE - t, "%hhd\n", st->cfg->matrix[i]); -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return t; @@ -370,13 +360,9 @@ static int bmi_iio_read_raw(struct iio_dev *indio_dev, struct bmi_iio_state *st = iio_priv(indio_dev); int ret; -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&indio_dev->mlock); -#endif + mutex_lock(BMI_MUTEX(indio_dev)); if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return -EPERM; } @@ -419,9 +405,7 @@ static int bmi_iio_read_raw(struct iio_dev *indio_dev, } out: -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return ret; } @@ -433,13 +417,9 @@ static int bmi_iio_write_raw(struct iio_dev *indio_dev, struct bmi_iio_state *st = iio_priv(indio_dev); int ret = 0; -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_lock(&indio_dev->mlock); -#endif + mutex_lock(BMI_MUTEX(indio_dev)); if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) { -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return -EPERM; } @@ -470,9 +450,7 @@ static int bmi_iio_write_raw(struct iio_dev *indio_dev, } out: -#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE - mutex_unlock(&indio_dev->mlock); -#endif + mutex_unlock(BMI_MUTEX(indio_dev)); return ret; } diff --git a/drivers/bmi088/bmi_iio.h b/drivers/bmi088/bmi_iio.h index cb85e610..d55e0030 100644 --- a/drivers/bmi088/bmi_iio.h +++ b/drivers/bmi088/bmi_iio.h @@ -5,12 +5,21 @@ #ifndef _BMI_IIO_H_ #define _BMI_IIO_H_ +#include + #include #include +#include #define BMI_STS_SHUTDOWN (1 << 0) #define BMI_STS_SUSPEND (1 << 1) +#if defined(NV_IIO_DEV_OPAQUE_HAS_LOCK) +#define BMI_MUTEX(indio_dev) (&to_iio_dev_opaque(indio_dev)->mlock) +#else +#define BMI_MUTEX(indio_dev) (&indio_dev->mlock) +#endif + struct bmi_float { int ival; int fval; diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index fc5491dc..0d1c01e7 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -89,6 +89,7 @@ endef # NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register +NV_CONFTEST_FUNCTION_COMPILE_TESTS += iio_dev_opaque_has_mlock NV_CONFTEST_GENERIC_COMPILE_TESTS ?= NV_CONFTEST_MACRO_COMPILE_TESTS ?= NV_CONFTEST_SYMBOL_COMPILE_TESTS ?= diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index aa2480a9..2094b1dc 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6310,6 +6310,25 @@ compile_test() { compile_check_conftest "$CODE" "NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT" "" "functions" ;; + iio_dev_opaque_has_mlock) + # + # Determine if the 'iio_dev_opaque' structure has 'mlock' field. + # 'mlock' field is moved from 'indio_dev' to 'iio_dev_opaque' + # structure. + # + # Added in commit 16afe125b53f88b855d2713c8ba253d905dcf3cc (iio: core: + # move 'mlock' to 'struct iio_dev_opaque') in v6.2 2022-10-12 + + CODE=" + #include + #include + int conftest_iio_dev_opaque_has_mlock(void) { + return offsetof(struct iio_dev_opaque, mlock); + }" + + compile_check_conftest "$CODE" "NV_IIO_DEV_OPAQUE_HAS_LOCK" "" "types" + ;; + # When adding a new conftest entry, please use the correct format for # specifying the relevant upstream Linux kernel commit. #