All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power-supply: Constify static psy_tzd_ops struct
@ 2021-01-20  9:54 Jian Dong
  2021-01-20 19:16 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jian Dong @ 2021-01-20  9:54 UTC (permalink / raw)
  To: sre; +Cc: linux-pm, dongjian, huyue2, zhangwen

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(-)

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] power-supply: Constify static psy_tzd_ops struct
  2021-01-20  9:54 [PATCH] power-supply: Constify static psy_tzd_ops struct Jian Dong
@ 2021-01-20 19:16 ` kernel test robot
  2021-01-20 21:50   ` kernel test robot
  2021-01-28  0:30 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-01-20 19:16 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5342 bytes --]

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
Reported-by: kernel test robot <lkp@intel.com>

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 72485 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] power-supply: Constify static psy_tzd_ops struct
  2021-01-20  9:54 [PATCH] power-supply: Constify static psy_tzd_ops struct Jian Dong
@ 2021-01-20 21:50   ` kernel test robot
  2021-01-20 21:50   ` kernel test robot
  2021-01-28  0:30 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-01-20 21:50 UTC (permalink / raw)
  To: Jian Dong, sre; +Cc: kbuild-all, linux-pm, dongjian, huyue2, zhangwen

[-- Attachment #1: Type: text/plain, Size: 4860 bytes --]

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36546 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] power-supply: Constify static psy_tzd_ops struct
@ 2021-01-20 21:50   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-01-20 21:50 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4924 bytes --]

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(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36546 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] power-supply: Constify static psy_tzd_ops struct
  2021-01-20  9:54 [PATCH] power-supply: Constify static psy_tzd_ops struct Jian Dong
  2021-01-20 19:16 ` kernel test robot
  2021-01-20 21:50   ` kernel test robot
@ 2021-01-28  0:30 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2021-01-28  0:30 UTC (permalink / raw)
  To: Jian Dong; +Cc: linux-pm, dongjian, huyue2, zhangwen

[-- Attachment #1: Type: text/plain, Size: 1316 bytes --]

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
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-28  0:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20  9:54 [PATCH] power-supply: Constify static psy_tzd_ops struct Jian Dong
2021-01-20 19:16 ` kernel test robot
2021-01-20 21:50 ` kernel test robot
2021-01-20 21:50   ` kernel test robot
2021-01-28  0:30 ` Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.