diff mbox series

[v1,1/1] device property: Unify access to of_node

Message ID 20210604131343.62016-1-andriy.shevchenko@linux.intel.com
State Accepted
Commit fb38f314fbd173e2e9f9f0f2e720a5f4889562da
Headers show
Series [v1,1/1] device property: Unify access to of_node | expand

Commit Message

Andy Shevchenko June 4, 2021, 1:13 p.m. UTC
Historically we have a few variants how we access dev->fwnode
and dev->of_node. Some of the functions during development
gained different versions of the getters. Unify access to of_node
and as a side change slightly refactor ACPI specific branches.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/base/property.c  | 29 +++++++++++++----------------
 include/linux/property.h |  2 +-
 2 files changed, 14 insertions(+), 17 deletions(-)

Comments

kernel test robot June 4, 2021, 2:55 p.m. UTC | #1
Hi Andy,

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20210604]
[cannot apply to driver-core/driver-core-testing linux/master linus/master v5.13-rc4 v5.13-rc3 v5.13-rc2 v5.13-rc4]
[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]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/device-property-Unify-access-to-of_node/20210604-211443
base:    ccc252d2e818f6a479441119ad453c3ce7c7c461
config: csky-randconfig-r024-20210604 (attached as .config)
compiler: csky-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/dfc2a97acf9b5c5ba11d180bf411721f723a9042
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Andy-Shevchenko/device-property-Unify-access-to-of_node/20210604-211443
        git checkout dfc2a97acf9b5c5ba11d180bf411721f723a9042
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=csky 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/base/property.c: In function 'device_dma_supported':
>> drivers/base/property.c:875:48: warning: passing argument 1 of 'to_acpi_device_node' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     875 |  return acpi_dma_supported(to_acpi_device_node(fwnode));
         |                                                ^~~~~~
   In file included from drivers/base/property.c:10:
   include/linux/acpi.h:768:77: note: expected 'struct fwnode_handle *' but argument is of type 'const struct fwnode_handle *'
     768 | static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
         |                                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
   drivers/base/property.c: In function 'device_get_dma_attr':
   drivers/base/property.c:890:48: warning: passing argument 1 of 'to_acpi_device_node' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     890 |   attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
         |                                                ^~~~~~
   In file included from drivers/base/property.c:10:
   include/linux/acpi.h:768:77: note: expected 'struct fwnode_handle *' but argument is of type 'const struct fwnode_handle *'
     768 | static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
         |                                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~


vim +875 drivers/base/property.c

   863	
   864	bool device_dma_supported(struct device *dev)
   865	{
   866		const struct fwnode_handle *fwnode = dev_fwnode(dev);
   867	
   868		/* For DT, this is always supported.
   869		 * For ACPI, this depends on CCA, which
   870		 * is determined by the acpi_dma_supported().
   871		 */
   872		if (is_of_node(fwnode))
   873			return true;
   874	
 > 875		return acpi_dma_supported(to_acpi_device_node(fwnode));
   876	}
   877	EXPORT_SYMBOL_GPL(device_dma_supported);
   878	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Andy Shevchenko June 4, 2021, 3:55 p.m. UTC | #2
On Fri, Jun 04, 2021 at 10:55:05PM +0800, kernel test robot wrote:
> Hi Andy,
> 
> I love your patch! Perhaps something to improve:

Definitely. Thanks for report!

> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>    drivers/base/property.c: In function 'device_dma_supported':
> >> drivers/base/property.c:875:48: warning: passing argument 1 of 'to_acpi_device_node' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
>      875 |  return acpi_dma_supported(to_acpi_device_node(fwnode));
>          |                                                ^~~~~~
>    In file included from drivers/base/property.c:10:
>    include/linux/acpi.h:768:77: note: expected 'struct fwnode_handle *' but argument is of type 'const struct fwnode_handle *'
>      768 | static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
>          |                                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
>    drivers/base/property.c: In function 'device_get_dma_attr':
>    drivers/base/property.c:890:48: warning: passing argument 1 of 'to_acpi_device_node' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
>      890 |   attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
>          |                                                ^~~~~~
>    In file included from drivers/base/property.c:10:
>    include/linux/acpi.h:768:77: note: expected 'struct fwnode_handle *' but argument is of type 'const struct fwnode_handle *'
>      768 | static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
>          |                                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
Andy Shevchenko June 4, 2021, 4:36 p.m. UTC | #3
On Sat, Jun 05, 2021 at 12:14:45AM +0800, kernel test robot wrote:
> Hi Andy,
> 
> I love your patch! Perhaps something to improve:
> 
> [auto build test WARNING on next-20210604]
> [cannot apply to driver-core/driver-core-testing linux/master linus/master v5.13-rc4 v5.13-rc3 v5.13-rc2 v5.13-rc4]
> [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]
> 
> url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/device-property-Unify-access-to-of_node/20210604-211443
> base:    ccc252d2e818f6a479441119ad453c3ce7c7c461
> config: sparc64-randconfig-s032-20210604 (attached as .config)
> compiler: sparc64-linux-gcc (GCC) 9.3.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # apt-get install sparse
>         # sparse version: v0.6.3-341-g8af24329-dirty
>         # https://github.com/0day-ci/linux/commit/dfc2a97acf9b5c5ba11d180bf411721f723a9042
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Andy-Shevchenko/device-property-Unify-access-to-of_node/20210604-211443
>         git checkout dfc2a97acf9b5c5ba11d180bf411721f723a9042
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=sparc64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>

Oh là là, just in time when I sent v2...
I'll look at this :-)

> sparse warnings: (new ones prefixed by >>)
> >> drivers/base/property.c:875:55: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct fwnode_handle *fwnode @@     got struct fwnode_handle const *fwnode @@
>    drivers/base/property.c:875:55: sparse:     expected struct fwnode_handle *fwnode
>    drivers/base/property.c:875:55: sparse:     got struct fwnode_handle const *fwnode
>    drivers/base/property.c:890:62: sparse: sparse: incorrect type in argument 1 (different modifiers) @@     expected struct fwnode_handle *fwnode @@     got struct fwnode_handle const *fwnode @@
>    drivers/base/property.c:890:62: sparse:     expected struct fwnode_handle *fwnode
>    drivers/base/property.c:890:62: sparse:     got struct fwnode_handle const *fwnode
diff mbox series

Patch

diff --git a/drivers/base/property.c b/drivers/base/property.c
index c26370aacdc6..d0874f6c29bb 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -759,13 +759,8 @@  EXPORT_SYMBOL_GPL(fwnode_get_next_available_child_node);
 struct fwnode_handle *device_get_next_child_node(struct device *dev,
 						 struct fwnode_handle *child)
 {
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-	struct fwnode_handle *fwnode = NULL, *next;
-
-	if (dev->of_node)
-		fwnode = of_fwnode_handle(dev->of_node);
-	else if (adev)
-		fwnode = acpi_fwnode_handle(adev);
+	const struct fwnode_handle *fwnode = dev_fwnode(dev);
+	struct fwnode_handle *next;
 
 	/* Try to find a child in primary fwnode */
 	next = fwnode_get_next_child_node(fwnode, child);
@@ -868,28 +863,31 @@  EXPORT_SYMBOL_GPL(device_get_child_node_count);
 
 bool device_dma_supported(struct device *dev)
 {
+	const struct fwnode_handle *fwnode = dev_fwnode(dev);
+
 	/* For DT, this is always supported.
 	 * For ACPI, this depends on CCA, which
 	 * is determined by the acpi_dma_supported().
 	 */
-	if (IS_ENABLED(CONFIG_OF) && dev->of_node)
+	if (is_of_node(fwnode))
 		return true;
 
-	return acpi_dma_supported(ACPI_COMPANION(dev));
+	return acpi_dma_supported(to_acpi_device_node(fwnode));
 }
 EXPORT_SYMBOL_GPL(device_dma_supported);
 
 enum dev_dma_attr device_get_dma_attr(struct device *dev)
 {
+	const struct fwnode_handle *fwnode = dev_fwnode(dev);
 	enum dev_dma_attr attr = DEV_DMA_NOT_SUPPORTED;
 
-	if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
-		if (of_dma_is_coherent(dev->of_node))
+	if (is_of_node(fwnode)) {
+		if (of_dma_is_coherent(to_of_node(fwnode)))
 			attr = DEV_DMA_COHERENT;
 		else
 			attr = DEV_DMA_NON_COHERENT;
 	} else
-		attr = acpi_get_dma_attr(ACPI_COMPANION(dev));
+		attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
 
 	return attr;
 }
@@ -1007,14 +1005,13 @@  EXPORT_SYMBOL(device_get_mac_address);
  * Returns Linux IRQ number on success. Other values are determined
  * accordingly to acpi_/of_ irq_get() operation.
  */
-int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index)
+int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index)
 {
-	struct device_node *of_node = to_of_node(fwnode);
 	struct resource res;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_OF) && of_node)
-		return of_irq_get(of_node, index);
+	if (is_of_node(fwnode))
+		return of_irq_get(to_of_node(fwnode), index);
 
 	ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), index, &res);
 	if (ret)
diff --git a/include/linux/property.h b/include/linux/property.h
index 0d876316e61d..073e680c35e2 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -119,7 +119,7 @@  struct fwnode_handle *device_get_named_child_node(struct device *dev,
 struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
 void fwnode_handle_put(struct fwnode_handle *fwnode);
 
-int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
+int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
 
 unsigned int device_get_child_node_count(struct device *dev);