[PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()

Tomi Valkeinen posted 15 patches 2 weeks, 5 days ago
[PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
Posted by Tomi Valkeinen 2 weeks, 5 days ago
Add error handling to ub913_hw_init() using a new helper function,
ub913_update_bits().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/i2c/ds90ub913.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ds90ub913.c b/drivers/media/i2c/ds90ub913.c
index 150d6641516f..5db11b6e7e2b 100644
--- a/drivers/media/i2c/ds90ub913.c
+++ b/drivers/media/i2c/ds90ub913.c
@@ -146,6 +146,19 @@ static int ub913_write(const struct ub913_data *priv, u8 reg, u8 val)
 	return ret;
 }
 
+static int ub913_update_bits(const struct ub913_data *priv, u8 reg, u8 mask,
+			     u8 val)
+{
+	int ret;
+
+	ret = regmap_update_bits(priv->regmap, reg, mask, val);
+	if (ret < 0)
+		dev_err(&priv->client->dev,
+			"Cannot update register 0x%02x %d!\n", reg, ret);
+
+	return ret;
+}
+
 /*
  * GPIO chip
  */
@@ -733,10 +746,13 @@ static int ub913_hw_init(struct ub913_data *priv)
 	if (ret)
 		return dev_err_probe(dev, ret, "i2c master init failed\n");
 
-	ub913_read(priv, UB913_REG_GENERAL_CFG, &v);
-	v &= ~UB913_REG_GENERAL_CFG_PCLK_RISING;
-	v |= priv->pclk_polarity_rising ? UB913_REG_GENERAL_CFG_PCLK_RISING : 0;
-	ub913_write(priv, UB913_REG_GENERAL_CFG, v);
+	ret = ub913_update_bits(priv, UB913_REG_GENERAL_CFG,
+				UB913_REG_GENERAL_CFG_PCLK_RISING,
+				FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
+					   priv->pclk_polarity_rising));
+
+	if (ret)
+		return ret;
 
 	return 0;
 }

-- 
2.43.0
Re: [PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
Posted by kernel test robot 2 weeks, 5 days ago
Hi Tomi,

kernel test robot noticed the following build errors:

[auto build test ERROR on 98f7e32f20d28ec452afb208f9cffc08448a2652]

url:    https://github.com/intel-lab-lkp/linux/commits/Tomi-Valkeinen/media-i2c-ds90ub9x3-Fix-extra-fwnode_handle_put/20241108-173952
base:   98f7e32f20d28ec452afb208f9cffc08448a2652
patch link:    https://lore.kernel.org/r/20241108-ub9xx-fixes-v2-13-c7db3b2ad89f%40ideasonboard.com
patch subject: [PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
config: x86_64-buildonly-randconfig-002-20241108 (https://download.01.org/0day-ci/archive/20241109/202411090151.d5LTbJyn-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241109/202411090151.d5LTbJyn-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/202411090151.d5LTbJyn-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/media/i2c/ds90ub913.c:16:
   In file included from include/linux/i2c-atr.h:14:
   In file included from include/linux/i2c.h:19:
   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:2232:
   include/linux/vmstat.h:517:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     517 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/media/i2c/ds90ub913.c:751:5: error: call to undeclared function 'FIELD_PREP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     751 |                                 FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
         |                                 ^
   1 warning and 1 error generated.


vim +/FIELD_PREP +751 drivers/media/i2c/ds90ub913.c

   722	
   723	static int ub913_hw_init(struct ub913_data *priv)
   724	{
   725		struct device *dev = &priv->client->dev;
   726		bool mode_override;
   727		u8 mode;
   728		int ret;
   729		u8 v;
   730	
   731		ret = ub913_read(priv, UB913_REG_MODE_SEL, &v);
   732		if (ret)
   733			return ret;
   734	
   735		if (!(v & UB913_REG_MODE_SEL_MODE_UP_TO_DATE))
   736			return dev_err_probe(dev, -ENODEV,
   737					     "Mode value not stabilized\n");
   738	
   739		mode_override = v & UB913_REG_MODE_SEL_MODE_OVERRIDE;
   740		mode = v & UB913_REG_MODE_SEL_MODE_MASK;
   741	
   742		dev_dbg(dev, "mode from %s: %#x\n",
   743			mode_override ? "reg" : "deserializer", mode);
   744	
   745		ret = ub913_i2c_master_init(priv);
   746		if (ret)
   747			return dev_err_probe(dev, ret, "i2c master init failed\n");
   748	
   749		ret = ub913_update_bits(priv, UB913_REG_GENERAL_CFG,
   750					UB913_REG_GENERAL_CFG_PCLK_RISING,
 > 751					FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
   752						   priv->pclk_polarity_rising));
   753	
   754		if (ret)
   755			return ret;
   756	
   757		return 0;
   758	}
   759	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
Posted by kernel test robot 2 weeks, 5 days ago
Hi Tomi,

kernel test robot noticed the following build errors:

[auto build test ERROR on 98f7e32f20d28ec452afb208f9cffc08448a2652]

url:    https://github.com/intel-lab-lkp/linux/commits/Tomi-Valkeinen/media-i2c-ds90ub9x3-Fix-extra-fwnode_handle_put/20241108-173952
base:   98f7e32f20d28ec452afb208f9cffc08448a2652
patch link:    https://lore.kernel.org/r/20241108-ub9xx-fixes-v2-13-c7db3b2ad89f%40ideasonboard.com
patch subject: [PATCH v2 13/15] media: i2c: ds90ub913: Add error handling to ub913_hw_init()
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20241109/202411090141.ZzfAF7jL-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241109/202411090141.ZzfAF7jL-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/202411090141.ZzfAF7jL-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/media/i2c/ds90ub913.c: In function 'ub913_hw_init':
>> drivers/media/i2c/ds90ub913.c:751:33: error: implicit declaration of function 'FIELD_PREP' [-Wimplicit-function-declaration]
     751 |                                 FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
         |                                 ^~~~~~~~~~


vim +/FIELD_PREP +751 drivers/media/i2c/ds90ub913.c

   722	
   723	static int ub913_hw_init(struct ub913_data *priv)
   724	{
   725		struct device *dev = &priv->client->dev;
   726		bool mode_override;
   727		u8 mode;
   728		int ret;
   729		u8 v;
   730	
   731		ret = ub913_read(priv, UB913_REG_MODE_SEL, &v);
   732		if (ret)
   733			return ret;
   734	
   735		if (!(v & UB913_REG_MODE_SEL_MODE_UP_TO_DATE))
   736			return dev_err_probe(dev, -ENODEV,
   737					     "Mode value not stabilized\n");
   738	
   739		mode_override = v & UB913_REG_MODE_SEL_MODE_OVERRIDE;
   740		mode = v & UB913_REG_MODE_SEL_MODE_MASK;
   741	
   742		dev_dbg(dev, "mode from %s: %#x\n",
   743			mode_override ? "reg" : "deserializer", mode);
   744	
   745		ret = ub913_i2c_master_init(priv);
   746		if (ret)
   747			return dev_err_probe(dev, ret, "i2c master init failed\n");
   748	
   749		ret = ub913_update_bits(priv, UB913_REG_GENERAL_CFG,
   750					UB913_REG_GENERAL_CFG_PCLK_RISING,
 > 751					FIELD_PREP(UB913_REG_GENERAL_CFG_PCLK_RISING,
   752						   priv->pclk_polarity_rising));
   753	
   754		if (ret)
   755			return ret;
   756	
   757		return 0;
   758	}
   759	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki