[PATCH] cdx: make cdx_bus_type constant

Kunwu Chan posted 1 patch 1 year, 5 months ago
There is a newer version of this series
drivers/cdx/cdx.c           | 2 +-
include/linux/cdx/cdx_bus.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[PATCH] cdx: make cdx_bus_type constant
Posted by Kunwu Chan 1 year, 5 months ago
From: Kunwu Chan <chentao@kylinos.cn>

Since commit d492cc2573a0 ("driver core: device.h: make struct
bus_type a const *"), the driver core can properly handle constant
struct bus_type, move the cdx_bus_type variable to be a constant
structure as well, placing it into read-only memory which can not be
modified at runtime.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/cdx/cdx.c           | 2 +-
 include/linux/cdx/cdx_bus.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index 07371cb653d3..e92164ae88a9 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -643,7 +643,7 @@ static struct attribute *cdx_bus_attrs[] = {
 };
 ATTRIBUTE_GROUPS(cdx_bus);
 
-struct bus_type cdx_bus_type = {
+const struct bus_type cdx_bus_type = {
 	.name		= "cdx",
 	.match		= cdx_bus_match,
 	.probe		= cdx_probe,
diff --git a/include/linux/cdx/cdx_bus.h b/include/linux/cdx/cdx_bus.h
index 79bb80e56790..b1ba97f6c9ad 100644
--- a/include/linux/cdx/cdx_bus.h
+++ b/include/linux/cdx/cdx_bus.h
@@ -234,7 +234,7 @@ int __must_check __cdx_driver_register(struct cdx_driver *cdx_driver,
  */
 void cdx_driver_unregister(struct cdx_driver *cdx_driver);
 
-extern struct bus_type cdx_bus_type;
+extern const struct bus_type cdx_bus_type;
 
 /**
  * cdx_dev_reset - Reset CDX device
-- 
2.41.0
Re: [PATCH] cdx: make cdx_bus_type constant
Posted by kernel test robot 1 year, 5 months ago
Hi Kunwu,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.11-rc5 next-20240826]
[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/Kunwu-Chan/cdx-make-cdx_bus_type-constant/20240826-123621
base:   linus/master
patch link:    https://lore.kernel.org/r/20240823071412.130246-1-kunwu.chan%40linux.dev
patch subject: [PATCH] cdx: make cdx_bus_type constant
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20240827/202408270946.gKlAW6oT-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 08e5a1de8227512d4774a534b91cb2353cef6284)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240827/202408270946.gKlAW6oT-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/202408270946.gKlAW6oT-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/cdx/cdx.c:66:
   In file included from include/linux/mm.h:2228:
   include/linux/vmstat.h:503:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     503 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     504 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:510:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     510 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     511 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   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_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:523:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     523 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     524 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/cdx/cdx.c:615:25: error: passing 'const struct bus_type *' to parameter of type 'struct bus_type *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
     615 |         cdx_unregister_devices(&cdx_bus_type);
         |                                ^~~~~~~~~~~~~
   drivers/cdx/cdx.c:173:53: note: passing argument to parameter 'bus' here
     173 | static void cdx_unregister_devices(struct bus_type *bus)
         |                                                     ^
   4 warnings and 1 error generated.


vim +615 drivers/cdx/cdx.c

cf60af04edfe51 Abhijit Gangurde 2023-12-22  597  
d06f5a3f714092 Linus Torvalds   2023-04-27  598  static ssize_t rescan_store(const struct bus_type *bus,
2959ab247061e6 Nipun Gupta      2023-03-13  599  			    const char *buf, size_t count)
2959ab247061e6 Nipun Gupta      2023-03-13  600  {
2959ab247061e6 Nipun Gupta      2023-03-13  601  	struct cdx_controller *cdx;
54b406e10f0334 Abhijit Gangurde 2023-10-17  602  	struct platform_device *pd;
54b406e10f0334 Abhijit Gangurde 2023-10-17  603  	struct device_node *np;
2959ab247061e6 Nipun Gupta      2023-03-13  604  	bool val;
2959ab247061e6 Nipun Gupta      2023-03-13  605  
2959ab247061e6 Nipun Gupta      2023-03-13  606  	if (kstrtobool(buf, &val) < 0)
2959ab247061e6 Nipun Gupta      2023-03-13  607  		return -EINVAL;
2959ab247061e6 Nipun Gupta      2023-03-13  608  
2959ab247061e6 Nipun Gupta      2023-03-13  609  	if (!val)
2959ab247061e6 Nipun Gupta      2023-03-13  610  		return -EINVAL;
2959ab247061e6 Nipun Gupta      2023-03-13  611  
f0af816834667b Abhijit Gangurde 2023-10-17  612  	mutex_lock(&cdx_controller_lock);
f0af816834667b Abhijit Gangurde 2023-10-17  613  
2959ab247061e6 Nipun Gupta      2023-03-13  614  	/* Unregister all the devices on the bus */
2959ab247061e6 Nipun Gupta      2023-03-13 @615  	cdx_unregister_devices(&cdx_bus_type);
2959ab247061e6 Nipun Gupta      2023-03-13  616  
2959ab247061e6 Nipun Gupta      2023-03-13  617  	/* Rescan all the devices */
54b406e10f0334 Abhijit Gangurde 2023-10-17  618  	for_each_compatible_node(np, NULL, compat_node_name) {
54b406e10f0334 Abhijit Gangurde 2023-10-17  619  		pd = of_find_device_by_node(np);
87736ae12e1427 Dan Carpenter    2024-01-02  620  		if (!pd) {
87736ae12e1427 Dan Carpenter    2024-01-02  621  			of_node_put(np);
1960932eef9183 Dan Carpenter    2024-01-02  622  			count = -EINVAL;
1960932eef9183 Dan Carpenter    2024-01-02  623  			goto unlock;
87736ae12e1427 Dan Carpenter    2024-01-02  624  		}
54b406e10f0334 Abhijit Gangurde 2023-10-17  625  
54b406e10f0334 Abhijit Gangurde 2023-10-17  626  		cdx = platform_get_drvdata(pd);
54b406e10f0334 Abhijit Gangurde 2023-10-17  627  		if (cdx && cdx->controller_registered && cdx->ops->scan)
54b406e10f0334 Abhijit Gangurde 2023-10-17  628  			cdx->ops->scan(cdx);
54b406e10f0334 Abhijit Gangurde 2023-10-17  629  
54b406e10f0334 Abhijit Gangurde 2023-10-17  630  		put_device(&pd->dev);
2959ab247061e6 Nipun Gupta      2023-03-13  631  	}
2959ab247061e6 Nipun Gupta      2023-03-13  632  
1960932eef9183 Dan Carpenter    2024-01-02  633  unlock:
f0af816834667b Abhijit Gangurde 2023-10-17  634  	mutex_unlock(&cdx_controller_lock);
f0af816834667b Abhijit Gangurde 2023-10-17  635  
2959ab247061e6 Nipun Gupta      2023-03-13  636  	return count;
2959ab247061e6 Nipun Gupta      2023-03-13  637  }
2959ab247061e6 Nipun Gupta      2023-03-13  638  static BUS_ATTR_WO(rescan);
2959ab247061e6 Nipun Gupta      2023-03-13  639  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] cdx: make cdx_bus_type constant
Posted by kernel test robot 1 year, 5 months ago
Hi Kunwu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.11-rc5 next-20240826]
[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/Kunwu-Chan/cdx-make-cdx_bus_type-constant/20240826-123621
base:   linus/master
patch link:    https://lore.kernel.org/r/20240823071412.130246-1-kunwu.chan%40linux.dev
patch subject: [PATCH] cdx: make cdx_bus_type constant
config: arm64-randconfig-002-20240826 (https://download.01.org/0day-ci/archive/20240826/202408262114.VRSL0Knh-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240826/202408262114.VRSL0Knh-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/202408262114.VRSL0Knh-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/cdx/cdx.c: In function 'rescan_store':
>> drivers/cdx/cdx.c:615:32: warning: passing argument 1 of 'cdx_unregister_devices' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     615 |         cdx_unregister_devices(&cdx_bus_type);
         |                                ^~~~~~~~~~~~~
   drivers/cdx/cdx.c:173:53: note: expected 'struct bus_type *' but argument is of type 'const struct bus_type *'
     173 | static void cdx_unregister_devices(struct bus_type *bus)
         |                                    ~~~~~~~~~~~~~~~~~^~~


vim +615 drivers/cdx/cdx.c

cf60af04edfe51f Abhijit Gangurde 2023-12-22  597  
d06f5a3f7140921 Linus Torvalds   2023-04-27  598  static ssize_t rescan_store(const struct bus_type *bus,
2959ab247061e67 Nipun Gupta      2023-03-13  599  			    const char *buf, size_t count)
2959ab247061e67 Nipun Gupta      2023-03-13  600  {
2959ab247061e67 Nipun Gupta      2023-03-13  601  	struct cdx_controller *cdx;
54b406e10f0334e Abhijit Gangurde 2023-10-17  602  	struct platform_device *pd;
54b406e10f0334e Abhijit Gangurde 2023-10-17  603  	struct device_node *np;
2959ab247061e67 Nipun Gupta      2023-03-13  604  	bool val;
2959ab247061e67 Nipun Gupta      2023-03-13  605  
2959ab247061e67 Nipun Gupta      2023-03-13  606  	if (kstrtobool(buf, &val) < 0)
2959ab247061e67 Nipun Gupta      2023-03-13  607  		return -EINVAL;
2959ab247061e67 Nipun Gupta      2023-03-13  608  
2959ab247061e67 Nipun Gupta      2023-03-13  609  	if (!val)
2959ab247061e67 Nipun Gupta      2023-03-13  610  		return -EINVAL;
2959ab247061e67 Nipun Gupta      2023-03-13  611  
f0af816834667b6 Abhijit Gangurde 2023-10-17  612  	mutex_lock(&cdx_controller_lock);
f0af816834667b6 Abhijit Gangurde 2023-10-17  613  
2959ab247061e67 Nipun Gupta      2023-03-13  614  	/* Unregister all the devices on the bus */
2959ab247061e67 Nipun Gupta      2023-03-13 @615  	cdx_unregister_devices(&cdx_bus_type);
2959ab247061e67 Nipun Gupta      2023-03-13  616  
2959ab247061e67 Nipun Gupta      2023-03-13  617  	/* Rescan all the devices */
54b406e10f0334e Abhijit Gangurde 2023-10-17  618  	for_each_compatible_node(np, NULL, compat_node_name) {
54b406e10f0334e Abhijit Gangurde 2023-10-17  619  		pd = of_find_device_by_node(np);
87736ae12e1427b Dan Carpenter    2024-01-02  620  		if (!pd) {
87736ae12e1427b Dan Carpenter    2024-01-02  621  			of_node_put(np);
1960932eef9183e Dan Carpenter    2024-01-02  622  			count = -EINVAL;
1960932eef9183e Dan Carpenter    2024-01-02  623  			goto unlock;
87736ae12e1427b Dan Carpenter    2024-01-02  624  		}
54b406e10f0334e Abhijit Gangurde 2023-10-17  625  
54b406e10f0334e Abhijit Gangurde 2023-10-17  626  		cdx = platform_get_drvdata(pd);
54b406e10f0334e Abhijit Gangurde 2023-10-17  627  		if (cdx && cdx->controller_registered && cdx->ops->scan)
54b406e10f0334e Abhijit Gangurde 2023-10-17  628  			cdx->ops->scan(cdx);
54b406e10f0334e Abhijit Gangurde 2023-10-17  629  
54b406e10f0334e Abhijit Gangurde 2023-10-17  630  		put_device(&pd->dev);
2959ab247061e67 Nipun Gupta      2023-03-13  631  	}
2959ab247061e67 Nipun Gupta      2023-03-13  632  
1960932eef9183e Dan Carpenter    2024-01-02  633  unlock:
f0af816834667b6 Abhijit Gangurde 2023-10-17  634  	mutex_unlock(&cdx_controller_lock);
f0af816834667b6 Abhijit Gangurde 2023-10-17  635  
2959ab247061e67 Nipun Gupta      2023-03-13  636  	return count;
2959ab247061e67 Nipun Gupta      2023-03-13  637  }
2959ab247061e67 Nipun Gupta      2023-03-13  638  static BUS_ATTR_WO(rescan);
2959ab247061e67 Nipun Gupta      2023-03-13  639  

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