diff mbox series

[v2] iio: adc: ad7380: use if_not_cond_guard for claim direct

Message ID 20241024-cleanup-if_not_cond_guard-v2-1-1bef98c9fd2e@baylibre.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [v2] iio: adc: ad7380: use if_not_cond_guard for claim direct | expand

Commit Message

David Lechner Oct. 24, 2024, 4:12 p.m. UTC
Replace usage of iio_device_claim_direct_scoped() with
if_not_cond_guard().

This makes fewer lines of code, less indentation, avoids having the
error return statement in the macro args, and avoids needing to use
unreachable().

Signed-off-by: David Lechner <dlechner@baylibre.com>
---
This is addressing the build failure reported on Peter's locking/test
branch [1]. I've done a test compile locally with LLVM=1 and it compiles
successfully.

[1]: https://lore.kernel.org/oe-kbuild-all/202410240802.VMztsHsW-lkp@intel.com/
---
Changes in v2:
- Add {} around case statements to avoid clang compiler error
- Link to v1: https://lore.kernel.org/r/20241001-cleanup-if_not_cond_guard-v1-0-7753810b0f7a@baylibre.com
---
 drivers/iio/adc/ad7380.c | 76 ++++++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 38 deletions(-)


---
base-commit: 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
change-id: 20241001-cleanup-if_not_cond_guard-0981d867ddf8

Best regards,

Comments

Peter Zijlstra Oct. 25, 2024, 8:03 a.m. UTC | #1
On Thu, Oct 24, 2024 at 11:12:10AM -0500, David Lechner wrote:
> Replace usage of iio_device_claim_direct_scoped() with
> if_not_cond_guard().
> 
> This makes fewer lines of code, less indentation, avoids having the
> error return statement in the macro args, and avoids needing to use
> unreachable().
> 
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> This is addressing the build failure reported on Peter's locking/test
> branch [1]. I've done a test compile locally with LLVM=1 and it compiles
> successfully.

Updated it. Do note, I had to still: s/if_not_cond_guard/if_not_guard/g on
this.

Assuming it all builds now, I'll push out the two cleanup patches to
tip.
kernel test robot Oct. 27, 2024, 4:27 a.m. UTC | #2
Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/iio-adc-ad7380-use-if_not_cond_guard-for-claim-direct/20241025-001415
base:   431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
patch link:    https://lore.kernel.org/r/20241024-cleanup-if_not_cond_guard-v2-1-1bef98c9fd2e%40baylibre.com
patch subject: [PATCH v2] iio: adc: ad7380: use if_not_cond_guard for claim direct
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20241027/202410271218.9sti93hi-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/202410271218.9sti93hi-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410271218.9sti93hi-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/iio/adc/ad7380.c: In function 'ad7380_debugfs_reg_access':
>> drivers/iio/adc/ad7380.c:574:9: error: implicit declaration of function 'if_not_cond_guard' [-Werror=implicit-function-declaration]
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |         ^~~~~~~~~~~~~~~~~
>> drivers/iio/adc/ad7380.c:574:27: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                           ^~~~~~~~~~~~~~~~~~~~
         |                           class_iio_claim_direct_try_t
   drivers/iio/adc/ad7380.c:574:27: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/iio/adc/ad7380.c:574:59: error: expected ';' before 'return'
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                           ^
         |                                                           ;
     575 |                 return -EBUSY;
         |                 ~~~~~~                                     
   drivers/iio/adc/ad7380.c: In function 'ad7380_read_raw':
   drivers/iio/adc/ad7380.c:823:35: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                   ^~~~~~~~~~~~~~~~~~~~
         |                                   class_iio_claim_direct_try_t
   drivers/iio/adc/ad7380.c:823:67: error: expected ';' before 'return'
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                                   ^
         |                                                                   ;
     824 |                         return -EBUSY;
         |                         ~~~~~~                                     
   drivers/iio/adc/ad7380.c: In function 'ad7380_write_raw':
   drivers/iio/adc/ad7380.c:912:35: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
     912 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                   ^~~~~~~~~~~~~~~~~~~~
         |                                   class_iio_claim_direct_try_t
   drivers/iio/adc/ad7380.c:912:67: error: expected ';' before 'return'
     912 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                                   ^
         |                                                                   ;
     913 |                         return -EBUSY;
         |                         ~~~~~~                                     
   cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for MODVERSIONS
   Depends on [n]: MODULES [=y] && !COMPILE_TEST [=y]
   Selected by [y]:
   - RANDSTRUCT_FULL [=y] && (CC_HAS_RANDSTRUCT [=n] || GCC_PLUGINS [=y]) && MODULES [=y]
   WARNING: unmet direct dependencies detected for GET_FREE_REGION
   Depends on [n]: SPARSEMEM [=n]
   Selected by [m]:
   - RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]


vim +/if_not_cond_guard +574 drivers/iio/adc/ad7380.c

   568	
   569	static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
   570					     u32 writeval, u32 *readval)
   571	{
   572		struct ad7380_state *st = iio_priv(indio_dev);
   573	
 > 574		if_not_cond_guard(iio_claim_direct_try, indio_dev)
   575			return -EBUSY;
   576	
   577		if (readval)
   578			return regmap_read(st->regmap, reg, readval);
   579	
   580		return regmap_write(st->regmap, reg, writeval);
   581	}
   582
kernel test robot Oct. 27, 2024, 5:09 a.m. UTC | #3
Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/iio-adc-ad7380-use-if_not_cond_guard-for-claim-direct/20241025-001415
base:   431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
patch link:    https://lore.kernel.org/r/20241024-cleanup-if_not_cond_guard-v2-1-1bef98c9fd2e%40baylibre.com
patch subject: [PATCH v2] iio: adc: ad7380: use if_not_cond_guard for claim direct
config: arm-randconfig-001-20241027 (https://download.01.org/0day-ci/archive/20241027/202410271212.2EFjrzX0-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 5886454669c3c9026f7f27eab13509dd0241f2d6)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241027/202410271212.2EFjrzX0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410271212.2EFjrzX0-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/iio/adc/ad7380.c:27:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/iio/adc/ad7380.c:574:2: error: call to undeclared function 'if_not_cond_guard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |         ^
>> drivers/iio/adc/ad7380.c:574:52: error: expected ';' after expression
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                           ^
         |                                                           ;
>> drivers/iio/adc/ad7380.c:574:20: error: use of undeclared identifier 'iio_claim_direct_try'
     574 |         if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                           ^
   drivers/iio/adc/ad7380.c:823:3: error: call to undeclared function 'if_not_cond_guard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   drivers/iio/adc/ad7380.c:823:53: error: expected ';' after expression
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                                   ^
         |                                                                   ;
   drivers/iio/adc/ad7380.c:823:21: error: use of undeclared identifier 'iio_claim_direct_try'
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                   ^
   drivers/iio/adc/ad7380.c:912:3: error: call to undeclared function 'if_not_cond_guard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     912 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   drivers/iio/adc/ad7380.c:912:53: error: expected ';' after expression
     912 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                                                   ^
         |                                                                   ;
   drivers/iio/adc/ad7380.c:912:21: error: use of undeclared identifier 'iio_claim_direct_try'
     912 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                                   ^
   1 warning and 9 errors generated.


vim +/if_not_cond_guard +574 drivers/iio/adc/ad7380.c

   568	
   569	static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
   570					     u32 writeval, u32 *readval)
   571	{
   572		struct ad7380_state *st = iio_priv(indio_dev);
   573	
 > 574		if_not_cond_guard(iio_claim_direct_try, indio_dev)
   575			return -EBUSY;
   576	
   577		if (readval)
   578			return regmap_read(st->regmap, reg, readval);
   579	
   580		return regmap_write(st->regmap, reg, writeval);
   581	}
   582
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index e8bddfb0d07d..34adc5aeb6f3 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -569,15 +569,15 @@  static const struct regmap_config ad7380_regmap_config = {
 static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
 				     u32 writeval, u32 *readval)
 {
-	iio_device_claim_direct_scoped(return  -EBUSY, indio_dev) {
-		struct ad7380_state *st = iio_priv(indio_dev);
+	struct ad7380_state *st = iio_priv(indio_dev);
 
-		if (readval)
-			return regmap_read(st->regmap, reg, readval);
-		else
-			return regmap_write(st->regmap, reg, writeval);
-	}
-	unreachable();
+	if_not_cond_guard(iio_claim_direct_try, indio_dev)
+		return -EBUSY;
+
+	if (readval)
+		return regmap_read(st->regmap, reg, readval);
+
+	return regmap_write(st->regmap, reg, writeval);
 }
 
 /*
@@ -819,12 +819,12 @@  static int ad7380_read_raw(struct iio_dev *indio_dev,
 		return PTR_ERR(scan_type);
 
 	switch (info) {
-	case IIO_CHAN_INFO_RAW:
-		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
-			return ad7380_read_direct(st, chan->scan_index,
-						  scan_type, val);
-		}
-		unreachable();
+	case IIO_CHAN_INFO_RAW: {
+		if_not_cond_guard(iio_claim_direct_try, indio_dev)
+			return -EBUSY;
+
+		return ad7380_read_direct(st, chan->scan_index, scan_type, val);
+	}
 	case IIO_CHAN_INFO_SCALE:
 		/*
 		 * According to the datasheet, the LSB size is:
@@ -901,7 +901,7 @@  static int ad7380_write_raw(struct iio_dev *indio_dev,
 	int ret, osr, boost;
 
 	switch (mask) {
-	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+	case IIO_CHAN_INFO_OVERSAMPLING_RATIO: {
 		osr = ad7380_osr_to_regval(val);
 		if (osr < 0)
 			return osr;
@@ -909,31 +909,31 @@  static int ad7380_write_raw(struct iio_dev *indio_dev,
 		/* always enable resolution boost when oversampling is enabled */
 		boost = osr > 0 ? 1 : 0;
 
-		iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
-			ret = regmap_update_bits(st->regmap,
-					AD7380_REG_ADDR_CONFIG1,
-					AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
-					FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
-					FIELD_PREP(AD7380_CONFIG1_RES, boost));
+		if_not_cond_guard(iio_claim_direct_try, indio_dev)
+			return -EBUSY;
 
-			if (ret)
-				return ret;
+		ret = regmap_update_bits(st->regmap,
+					 AD7380_REG_ADDR_CONFIG1,
+					 AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
+					 FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
+					 FIELD_PREP(AD7380_CONFIG1_RES, boost));
 
-			st->oversampling_ratio = val;
-			st->resolution_boost_enabled = boost;
-
-			/*
-			 * Perform a soft reset. This will flush the oversampling
-			 * block and FIFO but will maintain the content of the
-			 * configurable registers.
-			 */
-			return regmap_update_bits(st->regmap,
-					AD7380_REG_ADDR_CONFIG2,
-					AD7380_CONFIG2_RESET,
-					FIELD_PREP(AD7380_CONFIG2_RESET,
-						   AD7380_CONFIG2_RESET_SOFT));
-		}
-		unreachable();
+		if (ret)
+			return ret;
+
+		st->oversampling_ratio = val;
+		st->resolution_boost_enabled = boost;
+
+		/*
+		 * Perform a soft reset. This will flush the oversampling block
+		 * and FIFO but will maintain the content of the configurable
+		 * registers.
+		 */
+		return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
+					  AD7380_CONFIG2_RESET,
+					  FIELD_PREP(AD7380_CONFIG2_RESET,
+						     AD7380_CONFIG2_RESET_SOFT));
+	}
 	default:
 		return -EINVAL;
 	}