power-supply: Constify static psy_tzd_ops struct
PATCH 1/1 power-supply: Constify static psy_tzd_ops struct
From: dongjian <[email protected]>
The usage of this struct is to assign operation function's address to the field in thermal_zone_device_ops, it is a const pointer. make it const to allow the compiler to put it in read-only memory.
--- drivers/power/supply/power_supply_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/power_supply_core.c +1 -1
@@ -952,7 +952,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,return ret; } -static struct thermal_zone_device_ops psy_tzd_ops = { +static const struct thermal_zone_device_ops psy_tzd_ops = { .get_temp = power_supply_read_temp, };
Signature · 1 line
1.9.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Jian,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[also build test WARNING on v5.11-rc4 next-20210120]
[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/Jian-Dong/power-supply-Constify-static-psy_tzd_ops-struct/20210121-020328 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: powerpc-allyesconfig (attached as .config) compiler: powerpc64-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/250990c10e4f818c6fda0c43f489a5e7559bdb9c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jian-Dong/power-supply-Constify-static-psy_tzd_ops-struct/20210121-020328 git checkout 250990c10e4f818c6fda0c43f489a5e7559bdb9c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/power/supply/power_supply_core.c: In function 'psy_register_thermal':
>> drivers/power/supply/power_supply_core.c:970:17: warning: passing argument 5 of 'thermal_zone_device_register' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
970 | 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
| ^~~~~~~~~~~~ In file included from drivers/power/supply/power_supply_core.c:23:
include/linux/thermal.h:370:29: note: expected 'struct thermal_zone_device_ops *' but argument is of type 'const struct thermal_zone_device_ops *'
370 | struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +970 drivers/power/supply/power_supply_core.c
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 958
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 959 static int psy_register_thermal(struct power_supply *psy)
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 960 {
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 961 int i, ret;
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 962
297d716f6260cc9 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 963 if (psy->desc->no_thermal)
a69d82b9bdf1e53 drivers/power/power_supply_core.c Krzysztof Kozlowski 2014-10-07 964 return 0;
a69d82b9bdf1e53 drivers/power/power_supply_core.c Krzysztof Kozlowski 2014-10-07 965
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 966 /* Register battery zone device psy reports temperature */
297d716f6260cc9 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 967 for (i = 0; i < psy->desc->num_properties; i++) {
297d716f6260cc9 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 968 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
297d716f6260cc9 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 969 psy->tzd = thermal_zone_device_register(psy->desc->name,
297d716f6260cc9 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 @970 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 971 if (IS_ERR(psy->tzd))
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 972 return PTR_ERR(psy->tzd);
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 973 ret = thermal_zone_device_enable(psy->tzd);
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 974 if (ret)
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 975 thermal_zone_device_unregister(psy->tzd);
bbcf90c0646ac79 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 976 return ret;
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 977 }
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 978 }
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 979 return 0;
3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 980 }3be330bf8860dc6 drivers/power/power_supply_core.c Jenny TC 2012-05-09 981
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Jian,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on power-supply/for-next]
[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/Jian-Dong/power-supply-Constify-static-psy_tzd_ops-struct/20210121-020328 base: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next config: x86_64-randconfig-s022-20210120 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-208-g46a52ca4-dirty # https://github.com/0day-ci/linux/commit/250990c10e4f818c6fda0c43f489a5e7559bdb9c git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jian-Dong/power-supply-Constify-static-psy_tzd_ops-struct/20210121-020328 git checkout 250990c10e4f818c6fda0c43f489a5e7559bdb9c # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
"sparse warnings: (new ones prefixed by >>)"
>> drivers/power/supply/power_supply_core.c:970:53: sparse: sparse: incorrect type in argument 5 (different modifiers) @@ expected struct thermal_zone_device_ops * @@ got struct thermal_zone_device_ops const * @@
drivers/power/supply/power_supply_core.c:970:53: sparse: expected struct thermal_zone_device_ops *
drivers/power/supply/power_supply_core.c:970:53: sparse: got struct thermal_zone_device_ops const *
vim +970 drivers/power/supply/power_supply_core.c
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 958
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 959 static int psy_register_thermal(struct power_supply *psy)
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 960 {
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 961 int i, ret;
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 962
297d716f6260cc94 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 963 if (psy->desc->no_thermal)
a69d82b9bdf1e53e drivers/power/power_supply_core.c Krzysztof Kozlowski 2014-10-07 964 return 0;
a69d82b9bdf1e53e drivers/power/power_supply_core.c Krzysztof Kozlowski 2014-10-07 965
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 966 /* Register battery zone device psy reports temperature */
297d716f6260cc94 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 967 for (i = 0; i < psy->desc->num_properties; i++) {
297d716f6260cc94 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 968 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
297d716f6260cc94 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 969 psy->tzd = thermal_zone_device_register(psy->desc->name,
297d716f6260cc94 drivers/power/power_supply_core.c Krzysztof Kozlowski 2015-03-12 @970 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 971 if (IS_ERR(psy->tzd))
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 972 return PTR_ERR(psy->tzd);
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 973 ret = thermal_zone_device_enable(psy->tzd);
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 974 if (ret)
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 975 thermal_zone_device_unregister(psy->tzd);
bbcf90c0646ac797 drivers/power/supply/power_supply_core.c Andrzej Pietrasiewicz 2020-06-29 976 return ret;
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 977 }
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 978 }
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 979 return 0;
3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 980 }3be330bf8860dc60 drivers/power/power_supply_core.c Jenny TC 2012-05-09 981
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Hi,
Quoted 8 lines · Jian Dong
From: dongjian <[email protected]>
The usage of this struct is to assign operation function's address to the field in
thermal_zone_device_ops, it is a const pointer. make it const to allow the compiler to put it in read-only memory.Signed-off-by dongjian <[email protected]>---
As pointed out by the static checkers, you need to add const support to the thermal framework first (i.e. making sure, that thermal_zone_device_register takes a const pointer as argument). Once that has happened I will gladly apply this change.
Thanks,
-- Sebastian
Quoted 20 lines
drivers/power/supply/power_supply_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/power_supply_core.c +1
-1@@ -952,7 +952,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,return ret; } -static struct thermal_zone_device_ops psy_tzd_ops = { +static const struct thermal_zone_device_ops psy_tzd_ops = { .get_temp = power_supply_read_temp, };Signature · 1 line
1.9.1