diff mbox series

[2/3] iio: adc: ad7380: use if_not_cond_guard for claim direct

Message ID 20241001-cleanup-if_not_cond_guard-v1-2-7753810b0f7a@baylibre.com (mailing list archive)
State Changes Requested
Headers show
Series cleanup: add if_not_cond_guard macro | expand

Commit Message

David Lechner Oct. 1, 2024, 10:30 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>
---
 drivers/iio/adc/ad7380.c | 70 +++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 36 deletions(-)

Comments

kernel test robot Oct. 3, 2024, 4:23 a.m. UTC | #1
Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/cleanup-add-conditional-guard-helper/20241002-063209
base:   431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
patch link:    https://lore.kernel.org/r/20241001-cleanup-if_not_cond_guard-v1-2-7753810b0f7a%40baylibre.com
patch subject: [PATCH 2/3] iio: adc: ad7380: use if_not_cond_guard for claim direct
config: x86_64-randconfig-011-20241003 (https://download.01.org/0day-ci/archive/20241003/202410031215.IKHRIsat-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241003/202410031215.IKHRIsat-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/202410031215.IKHRIsat-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/iio/adc/ad7380.c:823:3: warning: label followed by a declaration is a C23 extension [-Wc23-extensions]
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:2: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |         ^
   include/linux/cleanup.h:312:2: note: expanded from macro '__if_not_cond_guard'
     312 |         CLASS(_name, _id)(args);                        \
         |         ^
   include/linux/cleanup.h:258:2: note: expanded from macro 'CLASS'
     258 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:67:1: note: expanded from here
      67 | class_iio_claim_direct_try_t
         | ^
   drivers/iio/adc/ad7380.c:851:2: error: cannot jump from switch statement to this case label
     851 |         default:
         |         ^
   drivers/iio/adc/ad7380.c:823:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:65:1: note: expanded from here
      65 | __UNIQUE_ID_guard837
         | ^
   drivers/iio/adc/ad7380.c:847:2: error: cannot jump from switch statement to this case label
     847 |         case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
         |         ^
   drivers/iio/adc/ad7380.c:823:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:65:1: note: expanded from here
      65 | __UNIQUE_ID_guard837
         | ^
   drivers/iio/adc/ad7380.c:838:2: error: cannot jump from switch statement to this case label
     838 |         case IIO_CHAN_INFO_OFFSET:
         |         ^
   drivers/iio/adc/ad7380.c:823:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:65:1: note: expanded from here
      65 | __UNIQUE_ID_guard837
         | ^
   drivers/iio/adc/ad7380.c:827:2: error: cannot jump from switch statement to this case label
     827 |         case IIO_CHAN_INFO_SCALE:
         |         ^
   drivers/iio/adc/ad7380.c:823:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:65:1: note: expanded from here
      65 | __UNIQUE_ID_guard837
         | ^
   drivers/iio/adc/ad7380.c:935:2: error: cannot jump from switch statement to this case label
     935 |         default:


vim +823 drivers/iio/adc/ad7380.c

   808	
   809	static int ad7380_read_raw(struct iio_dev *indio_dev,
   810				   struct iio_chan_spec const *chan,
   811				   int *val, int *val2, long info)
   812	{
   813		struct ad7380_state *st = iio_priv(indio_dev);
   814		const struct iio_scan_type *scan_type;
   815	
   816		scan_type = iio_get_current_scan_type(indio_dev, chan);
   817	
   818		if (IS_ERR(scan_type))
   819			return PTR_ERR(scan_type);
   820	
   821		switch (info) {
   822		case IIO_CHAN_INFO_RAW:
 > 823			if_not_cond_guard(iio_claim_direct_try, indio_dev)
   824				return -EBUSY;
   825	
   826			return ad7380_read_direct(st, chan->scan_index, scan_type, val);
   827		case IIO_CHAN_INFO_SCALE:
   828			/*
   829			 * According to the datasheet, the LSB size is:
   830			 *    * (2 × VREF) / 2^N, for differential chips
   831			 *    * VREF / 2^N, for pseudo-differential chips
   832			 * where N is the ADC resolution (i.e realbits)
   833			 */
   834			*val = st->vref_mv;
   835			*val2 = scan_type->realbits - chan->differential;
   836	
   837			return IIO_VAL_FRACTIONAL_LOG2;
   838		case IIO_CHAN_INFO_OFFSET:
   839			/*
   840			 * According to IIO ABI, offset is applied before scale,
   841			 * so offset is: vcm_mv / scale
   842			 */
   843			*val = st->vcm_mv[chan->channel] * (1 << scan_type->realbits)
   844				/ st->vref_mv;
   845	
   846			return IIO_VAL_INT;
   847		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
   848			*val = st->oversampling_ratio;
   849	
   850			return IIO_VAL_INT;
   851		default:
   852			return -EINVAL;
   853		}
   854	}
   855
kernel test robot Oct. 3, 2024, 5:35 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/cleanup-add-conditional-guard-helper/20241002-063209
base:   431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
patch link:    https://lore.kernel.org/r/20241001-cleanup-if_not_cond_guard-v1-2-7753810b0f7a%40baylibre.com
patch subject: [PATCH 2/3] iio: adc: ad7380: use if_not_cond_guard for claim direct
config: arm64-randconfig-001-20241003 (https://download.01.org/0day-ci/archive/20241003/202410031253.vjAMDYuX-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241003/202410031253.vjAMDYuX-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/202410031253.vjAMDYuX-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/iio/adc/ad7380.c:823:3: error: expected expression
     823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:2: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |         ^
   include/linux/cleanup.h:312:2: note: expanded from macro '__if_not_cond_guard'
     312 |         CLASS(_name, _id)(args);                        \
         |         ^
   include/linux/cleanup.h:258:2: note: expanded from macro 'CLASS'
     258 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
         |         ^
   <scratch space>:81:1: note: expanded from here
      81 | class_iio_claim_direct_try_t
         | ^
   drivers/iio/adc/ad7380.c:823:3: error: use of undeclared identifier '__UNIQUE_ID_guard799'
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:79:1: note: expanded from here
      79 | __UNIQUE_ID_guard799
         | ^
>> drivers/iio/adc/ad7380.c:935:2: error: cannot jump from switch statement to this case label
     935 |         default:
         |         ^
   drivers/iio/adc/ad7380.c:911:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
     911 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
         |                 ^
   include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
     316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
         |                                    ^
   include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
     189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
         |                             ^
   include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
      84 | #define __PASTE(a,b) ___PASTE(a,b)
         |                      ^
   include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
      83 | #define ___PASTE(a,b) a##b
         |                       ^
   <scratch space>:90:1: note: expanded from here
      90 | __UNIQUE_ID_guard800
         | ^
   3 errors generated.

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 [=y] || GCC_PLUGINS [=n]) && MODULES [=y]


vim +823 drivers/iio/adc/ad7380.c

   808	
   809	static int ad7380_read_raw(struct iio_dev *indio_dev,
   810				   struct iio_chan_spec const *chan,
   811				   int *val, int *val2, long info)
   812	{
   813		struct ad7380_state *st = iio_priv(indio_dev);
   814		const struct iio_scan_type *scan_type;
   815	
   816		scan_type = iio_get_current_scan_type(indio_dev, chan);
   817	
   818		if (IS_ERR(scan_type))
   819			return PTR_ERR(scan_type);
   820	
   821		switch (info) {
   822		case IIO_CHAN_INFO_RAW:
 > 823			if_not_cond_guard(iio_claim_direct_try, indio_dev)
   824				return -EBUSY;
   825	
   826			return ad7380_read_direct(st, chan->scan_index, scan_type, val);
   827		case IIO_CHAN_INFO_SCALE:
   828			/*
   829			 * According to the datasheet, the LSB size is:
   830			 *    * (2 × VREF) / 2^N, for differential chips
   831			 *    * VREF / 2^N, for pseudo-differential chips
   832			 * where N is the ADC resolution (i.e realbits)
   833			 */
   834			*val = st->vref_mv;
   835			*val2 = scan_type->realbits - chan->differential;
   836	
   837			return IIO_VAL_FRACTIONAL_LOG2;
   838		case IIO_CHAN_INFO_OFFSET:
   839			/*
   840			 * According to IIO ABI, offset is applied before scale,
   841			 * so offset is: vcm_mv / scale
   842			 */
   843			*val = st->vcm_mv[chan->channel] * (1 << scan_type->realbits)
   844				/ st->vref_mv;
   845	
   846			return IIO_VAL_INT;
   847		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
   848			*val = st->oversampling_ratio;
   849	
   850			return IIO_VAL_INT;
   851		default:
   852			return -EINVAL;
   853		}
   854	}
   855	
   856	static int ad7380_read_avail(struct iio_dev *indio_dev,
   857				     struct iio_chan_spec const *chan,
   858				     const int **vals, int *type, int *length,
   859				     long mask)
   860	{
   861		switch (mask) {
   862		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
   863			*vals = ad7380_oversampling_ratios;
   864			*length = ARRAY_SIZE(ad7380_oversampling_ratios);
   865			*type = IIO_VAL_INT;
   866	
   867			return IIO_AVAIL_LIST;
   868		default:
   869			return -EINVAL;
   870		}
   871	}
   872	
   873	/**
   874	 * ad7380_osr_to_regval - convert ratio to OSR register value
   875	 * @ratio: ratio to check
   876	 *
   877	 * Check if ratio is present in the list of available ratios and return the
   878	 * corresponding value that needs to be written to the register to select that
   879	 * ratio.
   880	 *
   881	 * Returns: register value (0 to 7) or -EINVAL if there is not an exact match
   882	 */
   883	static int ad7380_osr_to_regval(int ratio)
   884	{
   885		int i;
   886	
   887		for (i = 0; i < ARRAY_SIZE(ad7380_oversampling_ratios); i++) {
   888			if (ratio == ad7380_oversampling_ratios[i])
   889				return i;
   890		}
   891	
   892		return -EINVAL;
   893	}
   894	
   895	static int ad7380_write_raw(struct iio_dev *indio_dev,
   896				    struct iio_chan_spec const *chan, int val,
   897				    int val2, long mask)
   898	{
   899		struct ad7380_state *st = iio_priv(indio_dev);
   900		int ret, osr, boost;
   901	
   902		switch (mask) {
   903		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
   904			osr = ad7380_osr_to_regval(val);
   905			if (osr < 0)
   906				return osr;
   907	
   908			/* always enable resolution boost when oversampling is enabled */
   909			boost = osr > 0 ? 1 : 0;
   910	
   911			if_not_cond_guard(iio_claim_direct_try, indio_dev)
   912				return -EBUSY;
   913	
   914			ret = regmap_update_bits(st->regmap,
   915						 AD7380_REG_ADDR_CONFIG1,
   916						 AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
   917						 FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
   918						 FIELD_PREP(AD7380_CONFIG1_RES, boost));
   919	
   920			if (ret)
   921				return ret;
   922	
   923			st->oversampling_ratio = val;
   924			st->resolution_boost_enabled = boost;
   925	
   926			/*
   927			 * Perform a soft reset. This will flush the oversampling block
   928			 * and FIFO but will maintain the content of the configurable
   929			 * registers.
   930			 */
   931			return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
   932						  AD7380_CONFIG2_RESET,
   933						  FIELD_PREP(AD7380_CONFIG2_RESET,
   934							     AD7380_CONFIG2_RESET_SOFT));
 > 935		default:
   936			return -EINVAL;
   937		}
   938	}
   939
David Lechner Oct. 3, 2024, 2:20 p.m. UTC | #3
On 10/3/24 12:35 AM, kernel test robot wrote:
> 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/cleanup-add-conditional-guard-helper/20241002-063209
> base:   431c39f6d3edbab14f48dbf37a58ccdc0ac3be1e
> patch link:    https://lore.kernel.org/r/20241001-cleanup-if_not_cond_guard-v1-2-7753810b0f7a%40baylibre.com
> patch subject: [PATCH 2/3] iio: adc: ad7380: use if_not_cond_guard for claim direct
> config: arm64-randconfig-001-20241003 (https://download.01.org/0day-ci/archive/20241003/202410031253.vjAMDYuX-lkp@intel.com/config)
> compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241003/202410031253.vjAMDYuX-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/202410031253.vjAMDYuX-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>>> drivers/iio/adc/ad7380.c:823:3: error: expected expression
>      823 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
>          |                 ^
>    include/linux/cleanup.h:316:2: note: expanded from macro 'if_not_cond_guard'
>      316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
>          |         ^
>    include/linux/cleanup.h:312:2: note: expanded from macro '__if_not_cond_guard'
>      312 |         CLASS(_name, _id)(args);                        \
>          |         ^
>    include/linux/cleanup.h:258:2: note: expanded from macro 'CLASS'
>      258 |         class_##_name##_t var __cleanup(class_##_name##_destructor) =   \
>          |         ^
>    <scratch space>:81:1: note: expanded from here
>       81 | class_iio_claim_direct_try_t
>          | ^
>    drivers/iio/adc/ad7380.c:823:3: error: use of undeclared identifier '__UNIQUE_ID_guard799'
>    include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
>      316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
>          |                                    ^
>    include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
>      189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
>          |                             ^
>    include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
>       84 | #define __PASTE(a,b) ___PASTE(a,b)
>          |                      ^
>    include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
>       83 | #define ___PASTE(a,b) a##b
>          |                       ^
>    <scratch space>:79:1: note: expanded from here
>       79 | __UNIQUE_ID_guard799
>          | ^
>>> drivers/iio/adc/ad7380.c:935:2: error: cannot jump from switch statement to this case label
>      935 |         default:
>          |         ^
>    drivers/iio/adc/ad7380.c:911:3: note: jump bypasses initialization of variable with __attribute__((cleanup))
>      911 |                 if_not_cond_guard(iio_claim_direct_try, indio_dev)
>          |                 ^
>    include/linux/cleanup.h:316:29: note: expanded from macro 'if_not_cond_guard'
>      316 |         __if_not_cond_guard(_name, __UNIQUE_ID(guard), args)
>          |                                    ^
>    include/linux/compiler.h:189:29: note: expanded from macro '__UNIQUE_ID'
>      189 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
>          |                             ^
>    include/linux/compiler_types.h:84:22: note: expanded from macro '__PASTE'
>       84 | #define __PASTE(a,b) ___PASTE(a,b)
>          |                      ^
>    include/linux/compiler_types.h:83:23: note: expanded from macro '___PASTE'
>       83 | #define ___PASTE(a,b) a##b
>          |                       ^
>    <scratch space>:90:1: note: expanded from here
>       90 | __UNIQUE_ID_guard800
>          | ^
>    3 errors generated.
> 
> 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 [=y] || GCC_PLUGINS [=n]) && MODULES [=y]
> 
> 
> vim +823 drivers/iio/adc/ad7380.c
> 
>    808	
>    809	static int ad7380_read_raw(struct iio_dev *indio_dev,
>    810				   struct iio_chan_spec const *chan,
>    811				   int *val, int *val2, long info)
>    812	{
>    813		struct ad7380_state *st = iio_priv(indio_dev);
>    814		const struct iio_scan_type *scan_type;
>    815	
>    816		scan_type = iio_get_current_scan_type(indio_dev, chan);
>    817	
>    818		if (IS_ERR(scan_type))
>    819			return PTR_ERR(scan_type);
>    820	
>    821		switch (info) {
>    822		case IIO_CHAN_INFO_RAW:
>  > 823			if_not_cond_guard(iio_claim_direct_try, indio_dev)
>    824				return -EBUSY;
>    825	
>    826			return ad7380_read_direct(st, chan->scan_index, scan_type, val);
>    827		case IIO_CHAN_INFO_SCALE:
>    828			/*
>    829			 * According to the datasheet, the LSB size is:
>    830			 *    * (2 × VREF) / 2^N, for differential chips
>    831			 *    * VREF / 2^N, for pseudo-differential chips
>    832			 * where N is the ADC resolution (i.e realbits)
>    833			 */
>    834			*val = st->vref_mv;
>    835			*val2 = scan_type->realbits - chan->differential;
>    836	
>    837			return IIO_VAL_FRACTIONAL_LOG2;
>    838		case IIO_CHAN_INFO_OFFSET:
>    839			/*
>    840			 * According to IIO ABI, offset is applied before scale,
>    841			 * so offset is: vcm_mv / scale
>    842			 */
>    843			*val = st->vcm_mv[chan->channel] * (1 << scan_type->realbits)
>    844				/ st->vref_mv;
>    845	
>    846			return IIO_VAL_INT;
>    847		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>    848			*val = st->oversampling_ratio;
>    849	
>    850			return IIO_VAL_INT;
>    851		default:
>    852			return -EINVAL;
>    853		}
>    854	}
>    855	
>    856	static int ad7380_read_avail(struct iio_dev *indio_dev,
>    857				     struct iio_chan_spec const *chan,
>    858				     const int **vals, int *type, int *length,
>    859				     long mask)
>    860	{
>    861		switch (mask) {
>    862		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>    863			*vals = ad7380_oversampling_ratios;
>    864			*length = ARRAY_SIZE(ad7380_oversampling_ratios);
>    865			*type = IIO_VAL_INT;
>    866	
>    867			return IIO_AVAIL_LIST;
>    868		default:
>    869			return -EINVAL;
>    870		}
>    871	}
>    872	
>    873	/**
>    874	 * ad7380_osr_to_regval - convert ratio to OSR register value
>    875	 * @ratio: ratio to check
>    876	 *
>    877	 * Check if ratio is present in the list of available ratios and return the
>    878	 * corresponding value that needs to be written to the register to select that
>    879	 * ratio.
>    880	 *
>    881	 * Returns: register value (0 to 7) or -EINVAL if there is not an exact match
>    882	 */
>    883	static int ad7380_osr_to_regval(int ratio)
>    884	{
>    885		int i;
>    886	
>    887		for (i = 0; i < ARRAY_SIZE(ad7380_oversampling_ratios); i++) {
>    888			if (ratio == ad7380_oversampling_ratios[i])
>    889				return i;
>    890		}
>    891	
>    892		return -EINVAL;
>    893	}
>    894	
>    895	static int ad7380_write_raw(struct iio_dev *indio_dev,
>    896				    struct iio_chan_spec const *chan, int val,
>    897				    int val2, long mask)
>    898	{
>    899		struct ad7380_state *st = iio_priv(indio_dev);
>    900		int ret, osr, boost;
>    901	
>    902		switch (mask) {
>    903		case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>    904			osr = ad7380_osr_to_regval(val);
>    905			if (osr < 0)
>    906				return osr;
>    907	
>    908			/* always enable resolution boost when oversampling is enabled */
>    909			boost = osr > 0 ? 1 : 0;
>    910	
>    911			if_not_cond_guard(iio_claim_direct_try, indio_dev)
>    912				return -EBUSY;
>    913	
>    914			ret = regmap_update_bits(st->regmap,
>    915						 AD7380_REG_ADDR_CONFIG1,
>    916						 AD7380_CONFIG1_OSR | AD7380_CONFIG1_RES,
>    917						 FIELD_PREP(AD7380_CONFIG1_OSR, osr) |
>    918						 FIELD_PREP(AD7380_CONFIG1_RES, boost));
>    919	
>    920			if (ret)
>    921				return ret;
>    922	
>    923			st->oversampling_ratio = val;
>    924			st->resolution_boost_enabled = boost;
>    925	
>    926			/*
>    927			 * Perform a soft reset. This will flush the oversampling block
>    928			 * and FIFO but will maintain the content of the configurable
>    929			 * registers.
>    930			 */
>    931			return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
>    932						  AD7380_CONFIG2_RESET,
>    933						  FIELD_PREP(AD7380_CONFIG2_RESET,
>    934							     AD7380_CONFIG2_RESET_SOFT));
>  > 935		default:
>    936			return -EINVAL;
>    937		}
>    938	}
>    939	
> 

This warning and the "warning: label followed by a declaration
is a C23 extension" from the other bot message are both fixed
with the following modification:


diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index 19a942035e93..34adc5aeb6f3 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -819,11 +819,12 @@ static int ad7380_read_raw(struct iio_dev *indio_dev,
 		return PTR_ERR(scan_type);
 
 	switch (info) {
-	case IIO_CHAN_INFO_RAW:
+	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:
@@ -900,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;
@@ -932,6 +933,7 @@ static int ad7380_write_raw(struct iio_dev *indio_dev,
 					  AD7380_CONFIG2_RESET,
 					  FIELD_PREP(AD7380_CONFIG2_RESET,
 						     AD7380_CONFIG2_RESET_SOFT));
+	}
 	default:
 		return -EINVAL;
 	}
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index e8bddfb0d07d..19a942035e93 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);
 }
 
 /*
@@ -820,11 +820,10 @@  static int ad7380_read_raw(struct iio_dev *indio_dev,
 
 	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();
+		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:
@@ -909,31 +908,30 @@  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;
 	}