device property: Unify access to of_node
Subsystems (3)
Andy Shevchenko
reviewerPATCH 1/1 device property: Unify access to of_node
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.
--- drivers/base/property.c | 29 +++++++++++++---------------- include/linux/property.h | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-)
drivers/base/property.c +13 -16
@@ -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)
include/linux/property.h +1 -1
@@ -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);
Signature · 1 line
2.30.2
Greg Kroah-Hartman
maintainerQuoted 10 lines · Andy Shevchenko
Historically we have a few variants how we access
dev->fwnodeanddev->of_node. Some of the functions during development gained different versions of the getters. Unify access toof_nodeand as a side change slightly refactor ACPI specific branches.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/base/property.c | 29 +++++++++++++---------------- include/linux/property.h | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-)
Less code and const structures are always a win. If I get an ack from Rafael I will merge this in my tree.
thanks,
greg k-h
kernel test robot
build botI love your patch! Perhaps something to improve:
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
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(a)lists.01.org
Andy Shevchenko
reviewerQuoted 3 lines · kernel test robot
Hi Andy,
I love your patch! Perhaps something to improve:
Definitely. Thanks for report!
Quoted 21 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
drivers/base/property.c: In function 'device_dma_supported':Quoted 1 line
Quoted 1 line
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 'structfwnode_handle*' but argument is of type 'const structfwnode_handle*'
768 | static inline structacpi_device*to_acpi_device_node(structfwnode_handle*fwnode)
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botI love your patch! Perhaps something to improve:
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
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
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(a)lists.01.org
Andy Shevchenko
reviewerQuoted 26 lines · kernel test robot
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.0reproduce:
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 checkoutdfc2a97acf9b5c5ba11d180bf411721f723a9042
# 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
Quoted 2 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>
Oh là là, just in time when I sent v2...
I'll look at this :-)
Quoted 7 lines
sparse warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
drivers/base/property.c:875:55: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected structfwnode_handle*fwnode @@ got structfwnode_handleconst *fwnode @@
drivers/base/property.c:875:55: sparse: expected structfwnode_handle*fwnode
drivers/base/property.c:875:55: sparse: got structfwnode_handleconst *fwnode
drivers/base/property.c:890:62: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected structfwnode_handle*fwnode @@ got structfwnode_handleconst *fwnode @@
drivers/base/property.c:890:62: sparse: expected structfwnode_handle*fwnode
drivers/base/property.c:890:62: sparse: got structfwnode_handleconst *fwnode
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botI love your patch! Yet something to improve:
Hi Andy,
I love your patch! Yet something to improve:
[auto build test ERROR 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: arm64-randconfig-r016-20210604 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 5c0d1b2f902aa6a9cf47cc7e42c5b83bb2217cf9)
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
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# 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=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/base/property.c:875:48: error: passing 'const struct fwnode_handle *' to parameter of type 'struct fwnode_handle *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return acpi_dma_supported(to_acpi_device_node(fwnode));
^~~~~~
include/linux/acpi.h:768:77: note: passing argument to parameter 'fwnode' here
static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
^
drivers/base/property.c:890:48: error: passing 'const struct fwnode_handle *' to parameter of type 'struct fwnode_handle *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
attr = acpi_get_dma_attr(to_acpi_device_node(fwnode));
^~~~~~
include/linux/acpi.h:768:77: note: passing argument to parameter 'fwnode' here
static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
^2 errors generated.
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(a)lists.01.org