[PATCH v2 2/6] i2c: core: Unify the firmware node type check

Andy Shevchenko posted 6 patches 10 months ago
There is a newer version of this series
[PATCH v2 2/6] i2c: core: Unify the firmware node type check
Posted by Andy Shevchenko 10 months ago
OF and ACPI currently are using asymmetrical APIs to check
for the firmware node type. Unify them by using is_*_node()
against struct fwnode_handle pointer.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-core-base.c  | 14 ++++++++------
 drivers/i2c/i2c-core-slave.c | 11 +++++++----
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index c14ffd6190d3..edab56e5d5e5 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -490,6 +490,7 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client)
 
 static int i2c_device_probe(struct device *dev)
 {
+	struct fwnode_handle	*fwnode = dev_fwnode(dev);
 	struct i2c_client	*client = i2c_verify_client(dev);
 	struct i2c_driver	*driver;
 	bool do_power_on;
@@ -508,11 +509,11 @@ static int i2c_device_probe(struct device *dev)
 			/* Keep adapter active when Host Notify is required */
 			pm_runtime_get_sync(&client->adapter->dev);
 			irq = i2c_smbus_host_notify_to_irq(client);
-		} else if (dev->of_node) {
+		} else if (is_of_node(fwnode)) {
 			irq = of_irq_get_byname(dev->of_node, "irq");
 			if (irq == -EINVAL || irq == -ENODATA)
 				irq = of_irq_get(dev->of_node, 0);
-		} else if (ACPI_COMPANION(dev)) {
+		} else if (is_acpi_device_node(fwnode)) {
 			bool wake_capable;
 
 			irq = i2c_acpi_get_irq(client, &wake_capable);
@@ -1054,15 +1055,16 @@ EXPORT_SYMBOL_GPL(i2c_new_client_device);
  */
 void i2c_unregister_device(struct i2c_client *client)
 {
+	struct fwnode_handle *fwnode;
+
 	if (IS_ERR_OR_NULL(client))
 		return;
 
-	if (client->dev.of_node) {
+	fwnode = dev_fwnode(&client->dev);
+	if (is_of_node(fwnode)) {
 		of_node_clear_flag(client->dev.of_node, OF_POPULATED);
 		of_node_put(client->dev.of_node);
-	}
-
-	if (ACPI_COMPANION(&client->dev))
+	} else if (is_acpi_device_node(fwnode))
 		acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
 
 	device_remove_software_node(&client->dev);
diff --git a/drivers/i2c/i2c-core-slave.c b/drivers/i2c/i2c-core-slave.c
index faefe1dfa8e5..3c5cb61b8c39 100644
--- a/drivers/i2c/i2c-core-slave.c
+++ b/drivers/i2c/i2c-core-slave.c
@@ -11,6 +11,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/of.h>
+#include <linux/property.h>
 
 #include "i2c-core.h"
 
@@ -108,15 +109,17 @@ EXPORT_SYMBOL_GPL(i2c_slave_event);
  */
 bool i2c_detect_slave_mode(struct device *dev)
 {
-	if (IS_BUILTIN(CONFIG_OF) && dev->of_node) {
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	if (is_of_node(fwnode)) {
 		u32 reg;
 
-		for_each_child_of_node_scoped(dev->of_node, child) {
-			of_property_read_u32(child, "reg", &reg);
+		for_each_child_node_scoped(fwnode, child) {
+			fwnode_property_read_u32(child, "reg", &reg);
 			if (reg & I2C_OWN_SLAVE_ADDRESS)
 				return true;
 		}
-	} else if (IS_BUILTIN(CONFIG_ACPI) && ACPI_HANDLE(dev)) {
+	} else if (is_acpi_device_node(fwnode)) {
 		dev_dbg(dev, "ACPI slave is not supported yet\n");
 	}
 	return false;
-- 
2.47.2
Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
Posted by kernel test robot 10 months ago
Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
config: arm-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/202504072133.J8njROAD-lkp@intel.com/config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 92c93f5286b9ff33f27ff694d2dc33da1c07afdd)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/202504072133.J8njROAD-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/202504072133.J8njROAD-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/i2c/i2c-core-slave.c:117:3: error: call to undeclared function 'for_each_child_node_scoped'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                 ^
>> drivers/i2c/i2c-core-slave.c:117:44: error: expected ';' after expression
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                          ^
         |                                                          ;
>> drivers/i2c/i2c-core-slave.c:117:38: error: use of undeclared identifier 'child'; did you mean 'ihold'?
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                    ^~~~~
         |                                                    ihold
   include/linux/fs.h:2758:13: note: 'ihold' declared here
    2758 | extern void ihold(struct inode * inode);
         |             ^
   drivers/i2c/i2c-core-slave.c:118:29: error: use of undeclared identifier 'child'; did you mean 'ihold'?
     118 |                         fwnode_property_read_u32(child, "reg", &reg);
         |                                                  ^~~~~
         |                                                  ihold
   include/linux/fs.h:2758:13: note: 'ihold' declared here
    2758 | extern void ihold(struct inode * inode);
         |             ^
   4 errors generated.


vim +/for_each_child_node_scoped +117 drivers/i2c/i2c-core-slave.c

    97	
    98	/**
    99	 * i2c_detect_slave_mode - detect operation mode
   100	 * @dev: The device owning the bus
   101	 *
   102	 * This checks the device nodes for an I2C slave by checking the address
   103	 * used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
   104	 * flag this means the device is configured to act as a I2C slave and it will
   105	 * be listening at that address.
   106	 *
   107	 * Returns true if an I2C own slave address is detected, otherwise returns
   108	 * false.
   109	 */
   110	bool i2c_detect_slave_mode(struct device *dev)
   111	{
   112		struct fwnode_handle *fwnode = dev_fwnode(dev);
   113	
   114		if (is_of_node(fwnode)) {
   115			u32 reg;
   116	
 > 117			for_each_child_node_scoped(fwnode, child) {

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
Posted by kernel test robot 10 months ago
Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on linus/master v6.15-rc1 next-20250407]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
config: arc-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/202504072041.Bv9mOk4o-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/202504072041.Bv9mOk4o-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/202504072041.Bv9mOk4o-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/i2c/i2c-core-slave.c: In function 'i2c_detect_slave_mode':
>> drivers/i2c/i2c-core-slave.c:117:17: error: implicit declaration of function 'for_each_child_node_scoped'; did you mean 'for_each_child_of_node_scoped'? [-Wimplicit-function-declaration]
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
         |                 for_each_child_of_node_scoped
>> drivers/i2c/i2c-core-slave.c:117:52: error: 'child' undeclared (first use in this function)
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                    ^~~~~
   drivers/i2c/i2c-core-slave.c:117:52: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/i2c/i2c-core-slave.c:117:58: error: expected ';' before '{' token
     117 |                 for_each_child_node_scoped(fwnode, child) {
         |                                                          ^~
         |                                                          ;
>> drivers/i2c/i2c-core-slave.c:115:21: warning: unused variable 'reg' [-Wunused-variable]
     115 |                 u32 reg;
         |                     ^~~


vim +117 drivers/i2c/i2c-core-slave.c

    97	
    98	/**
    99	 * i2c_detect_slave_mode - detect operation mode
   100	 * @dev: The device owning the bus
   101	 *
   102	 * This checks the device nodes for an I2C slave by checking the address
   103	 * used in the reg property. If the address match the I2C_OWN_SLAVE_ADDRESS
   104	 * flag this means the device is configured to act as a I2C slave and it will
   105	 * be listening at that address.
   106	 *
   107	 * Returns true if an I2C own slave address is detected, otherwise returns
   108	 * false.
   109	 */
   110	bool i2c_detect_slave_mode(struct device *dev)
   111	{
   112		struct fwnode_handle *fwnode = dev_fwnode(dev);
   113	
   114		if (is_of_node(fwnode)) {
 > 115			u32 reg;
   116	
 > 117			for_each_child_node_scoped(fwnode, child) {

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
Posted by Andy Shevchenko 10 months ago
On Mon, Apr 07, 2025 at 08:45:14PM +0800, kernel test robot wrote:
> Hi Andy,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on wsa/i2c/for-next]
> [also build test ERROR on linus/master v6.15-rc1 next-20250407]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/i2c-core-Drop-duplicate-check-before-calling-OF-APIs/20250407-180528
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
> patch link:    https://lore.kernel.org/r/20250407095852.215809-3-andriy.shevchenko%40linux.intel.com
> patch subject: [PATCH v2 2/6] i2c: core: Unify the firmware node type check
> config: arc-randconfig-002-20250407 (https://download.01.org/0day-ci/archive/20250407/202504072041.Bv9mOk4o-lkp@intel.com/config)
> compiler: arc-linux-gcc (GCC) 14.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250407/202504072041.Bv9mOk4o-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/202504072041.Bv9mOk4o-lkp@intel.com/
> 

> All error/warnings (new ones prefixed by >>):

Ah, I should compile-test the slave part as well...
Will be fixed in v3. Since v3 is required, Tomi, I'm going to add the media
patch to its end.

-- 
With Best Regards,
Andy Shevchenko