diff mbox series

power-supply: Constify static psy_tzd_ops struct

Message ID 20210120095427.10592-1-dj0227@163.com (mailing list archive)
State Not Applicable, archived
Headers show
Series power-supply: Constify static psy_tzd_ops struct | expand

Commit Message

Jian Dong Jan. 20, 2021, 9:54 a.m. UTC
From: dongjian <dongjian@yulong.com>

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 <dongjian@yulong.com>
---
 drivers/power/supply/power_supply_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

kernel test robot Jan. 20, 2021, 9:50 p.m. UTC | #1
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
Reported-by: kernel test robot <lkp@intel.com>


"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@lists.01.org
Sebastian Reichel Jan. 28, 2021, 12:30 a.m. UTC | #2
Hi,

On Wed, Jan 20, 2021 at 05:54:26PM +0800, Jian Dong wrote:
> From: dongjian <dongjian@yulong.com>
> 
> 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 <dongjian@yulong.com>
> ---

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

>  drivers/power/supply/power_supply_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 38e3aa64..ae34856 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -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,
>  };
>  
> -- 
> 1.9.1
> 
>
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 38e3aa64..ae34856 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -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,
 };