diff mbox series

[04/14] power: supply: ab8500: use power_supply_for_each_psy()

Message ID 20241208-power-supply-dev_to_psy-v1-4-f95de9117558@weissschuh.net
State Superseded
Headers show
Series power: supply: intruduce and use power_supply_for_each_psy() and dev_to_psy() | expand

Commit Message

Thomas Weißschuh Dec. 8, 2024, 1:02 p.m. UTC
Simplify the callbacks by removing the need to convert a 'struct device'
into a 'struct power_supply'.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/power/supply/ab8500_btemp.c    | 5 ++---
 drivers/power/supply/ab8500_chargalg.c | 5 ++---
 drivers/power/supply/ab8500_charger.c  | 5 ++---
 drivers/power/supply/ab8500_fg.c       | 5 ++---
 4 files changed, 8 insertions(+), 12 deletions(-)

Comments

kernel test robot Dec. 9, 2024, 4:29 p.m. UTC | #1
Hi Thomas,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 39f3bd9c9a27d526858da153090376decdf7bfea]

url:    https://github.com/intel-lab-lkp/linux/commits/Thomas-Wei-schuh/power-supply-mm8013-use-accessor-for-driver-data/20241208-210605
base:   39f3bd9c9a27d526858da153090376decdf7bfea
patch link:    https://lore.kernel.org/r/20241208-power-supply-dev_to_psy-v1-4-f95de9117558%40weissschuh.net
patch subject: [PATCH 04/14] power: supply: ab8500: use power_supply_for_each_psy()
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20241209/202412092219.bRJmBwIP-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241209/202412092219.bRJmBwIP-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/202412092219.bRJmBwIP-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/power/supply/ab8500_btemp.c:543:49: warning: 'struct power_supply_ext' declared inside parameter list will not be visible outside of this definition or declaration
     543 | static int ab8500_btemp_get_ext_psy_data(struct power_supply_ext *ext, void *data)
         |                                                 ^~~~~~~~~~~~~~~~
   drivers/power/supply/ab8500_btemp.c: In function 'ab8500_btemp_get_ext_psy_data':
   drivers/power/supply/ab8500_btemp.c:546:54: error: invalid use of undefined type 'struct power_supply_ext'
     546 |         const char **supplicants = (const char **)ext->supplied_to;
         |                                                      ^~
   drivers/power/supply/ab8500_btemp.c:558:42: error: invalid use of undefined type 'struct power_supply_ext'
     558 |         j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
         |                                          ^~
   drivers/power/supply/ab8500_btemp.c:563:28: error: invalid use of undefined type 'struct power_supply_ext'
     563 |         for (j = 0; j < ext->desc->num_properties; j++) {
         |                            ^~
   drivers/power/supply/ab8500_btemp.c:565:27: error: invalid use of undefined type 'struct power_supply_ext'
     565 |                 prop = ext->desc->properties[j];
         |                           ^~
   drivers/power/supply/ab8500_btemp.c:567:47: error: passing argument 1 of 'power_supply_get_property' from incompatible pointer type [-Wincompatible-pointer-types]
     567 |                 if (power_supply_get_property(ext, prop, &ret))
         |                                               ^~~
         |                                               |
         |                                               struct power_supply_ext *
   In file included from drivers/power/supply/ab8500_btemp.c:21:
   include/linux/power_supply.h:855:59: note: expected 'struct power_supply *' but argument is of type 'struct power_supply_ext *'
     855 | extern int power_supply_get_property(struct power_supply *psy,
         |                                      ~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/power/supply/ab8500_btemp.c:572:36: error: invalid use of undefined type 'struct power_supply_ext'
     572 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_btemp.c: In function 'ab8500_btemp_external_power_changed':
   drivers/power/supply/ab8500_btemp.c:619:40: error: passing argument 2 of 'power_supply_for_each_psy' from incompatible pointer type [-Wincompatible-pointer-types]
     619 |         power_supply_for_each_psy(psy, ab8500_btemp_get_ext_psy_data);
         |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                        |
         |                                        int (*)(struct power_supply_ext *, void *)
   include/linux/power_supply.h:885:56: note: expected 'int (*)(struct power_supply *, void *)' but argument is of type 'int (*)(struct power_supply_ext *, void *)'
     885 | extern int power_supply_for_each_psy(void *data, int (*fn)(struct power_supply *psy, void *data));
         |                                                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
>> drivers/power/supply/ab8500_chargalg.c:847:52: warning: 'struct power_supply_ext' declared inside parameter list will not be visible outside of this definition or declaration
     847 | static int ab8500_chargalg_get_ext_psy_data(struct power_supply_ext *ext, void *data)
         |                                                    ^~~~~~~~~~~~~~~~
   drivers/power/supply/ab8500_chargalg.c: In function 'ab8500_chargalg_get_ext_psy_data':
   drivers/power/supply/ab8500_chargalg.c:850:54: error: invalid use of undefined type 'struct power_supply_ext'
     850 |         const char **supplicants = (const char **)ext->supplied_to;
         |                                                      ^~
   drivers/power/supply/ab8500_chargalg.c:859:42: error: invalid use of undefined type 'struct power_supply_ext'
     859 |         j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
         |                                          ^~
   drivers/power/supply/ab8500_chargalg.c:868:40: error: passing argument 1 of 'power_supply_get_property' from incompatible pointer type [-Wincompatible-pointer-types]
     868 |         if (!power_supply_get_property(ext, POWER_SUPPLY_PROP_CAPACITY, &ret)) {
         |                                        ^~~
         |                                        |
         |                                        struct power_supply_ext *
   In file included from drivers/power/supply/ab8500_chargalg.c:24:
   include/linux/power_supply.h:855:59: note: expected 'struct power_supply *' but argument is of type 'struct power_supply_ext *'
     855 | extern int power_supply_get_property(struct power_supply *psy,
         |                                      ~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/power/supply/ab8500_chargalg.c:874:28: error: invalid use of undefined type 'struct power_supply_ext'
     874 |         for (j = 0; j < ext->desc->num_properties; j++) {
         |                            ^~
   drivers/power/supply/ab8500_chargalg.c:876:27: error: invalid use of undefined type 'struct power_supply_ext'
     876 |                 prop = ext->desc->properties[j];
         |                           ^~
   drivers/power/supply/ab8500_chargalg.c:882:28: error: invalid use of undefined type 'struct power_supply_ext'
     882 |                         ext->desc->type == POWER_SUPPLY_TYPE_MAINS)
         |                            ^~
   In file included from drivers/power/supply/ab8500_chargalg.c:35:
   drivers/power/supply/ab8500_chargalg.c:883:59: error: passing argument 1 of 'power_supply_get_drvdata' from incompatible pointer type [-Wincompatible-pointer-types]
     883 |                         di->ac_chg = psy_to_ux500_charger(ext);
         |                                                           ^~~
         |                                                           |
         |                                                           struct power_supply_ext *
   drivers/power/supply/ab8500-chargalg.h:18:58: note: in definition of macro 'psy_to_ux500_charger'
      18 | #define psy_to_ux500_charger(x) power_supply_get_drvdata(x)
         |                                                          ^
   include/linux/power_supply.h:883:60: note: expected 'struct power_supply *' but argument is of type 'struct power_supply_ext *'
     883 | extern void *power_supply_get_drvdata(struct power_supply *psy);
         |                                       ~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/power/supply/ab8500_chargalg.c:885:28: error: invalid use of undefined type 'struct power_supply_ext'
     885 |                         ext->desc->type == POWER_SUPPLY_TYPE_USB)
         |                            ^~
   drivers/power/supply/ab8500_chargalg.c:886:60: error: passing argument 1 of 'power_supply_get_drvdata' from incompatible pointer type [-Wincompatible-pointer-types]
     886 |                         di->usb_chg = psy_to_ux500_charger(ext);
         |                                                            ^~~
         |                                                            |
         |                                                            struct power_supply_ext *
   drivers/power/supply/ab8500-chargalg.h:18:58: note: in definition of macro 'psy_to_ux500_charger'
      18 | #define psy_to_ux500_charger(x) power_supply_get_drvdata(x)
         |                                                          ^
   include/linux/power_supply.h:883:60: note: expected 'struct power_supply *' but argument is of type 'struct power_supply_ext *'
     883 | extern void *power_supply_get_drvdata(struct power_supply *psy);
         |                                       ~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/power/supply/ab8500_chargalg.c:888:47: error: passing argument 1 of 'power_supply_get_property' from incompatible pointer type [-Wincompatible-pointer-types]
     888 |                 if (power_supply_get_property(ext, prop, &ret))
         |                                               ^~~
         |                                               |
         |                                               struct power_supply_ext *
   include/linux/power_supply.h:855:59: note: expected 'struct power_supply *' but argument is of type 'struct power_supply_ext *'
     855 | extern int power_supply_get_property(struct power_supply *psy,
         |                                      ~~~~~~~~~~~~~~~~~~~~~^~~
   drivers/power/supply/ab8500_chargalg.c:892:36: error: invalid use of undefined type 'struct power_supply_ext'
     892 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:939:36: error: invalid use of undefined type 'struct power_supply_ext'
     939 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:984:36: error: invalid use of undefined type 'struct power_supply_ext'
     984 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:1068:36: error: invalid use of undefined type 'struct power_supply_ext'
    1068 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:1084:36: error: invalid use of undefined type 'struct power_supply_ext'
    1084 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:1109:36: error: invalid use of undefined type 'struct power_supply_ext'
    1109 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:1127:36: error: invalid use of undefined type 'struct power_supply_ext'
    1127 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c:1143:36: error: invalid use of undefined type 'struct power_supply_ext'
    1143 |                         switch (ext->desc->type) {
         |                                    ^~
   drivers/power/supply/ab8500_chargalg.c: In function 'ab8500_chargalg_algorithm':
   drivers/power/supply/ab8500_chargalg.c:1233:53: error: passing argument 2 of 'power_supply_for_each_psy' from incompatible pointer type [-Wincompatible-pointer-types]
    1233 |         power_supply_for_each_psy(di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);
         |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                                     |
         |                                                     int (*)(struct power_supply_ext *, void *)
   include/linux/power_supply.h:885:56: note: expected 'int (*)(struct power_supply *, void *)' but argument is of type 'int (*)(struct power_supply_ext *, void *)'
     885 | extern int power_supply_for_each_psy(void *data, int (*fn)(struct power_supply *psy, void *data));
         |                                                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +543 drivers/power/supply/ab8500_btemp.c

   542	
 > 543	static int ab8500_btemp_get_ext_psy_data(struct power_supply_ext *ext, void *data)
   544	{
   545		struct power_supply *psy;
   546		const char **supplicants = (const char **)ext->supplied_to;
   547		struct ab8500_btemp *di;
   548		union power_supply_propval ret;
   549		int j;
   550	
   551		psy = (struct power_supply *)data;
   552		di = power_supply_get_drvdata(psy);
   553	
   554		/*
   555		 * For all psy where the name of your driver
   556		 * appears in any supplied_to
   557		 */
   558		j = match_string(supplicants, ext->num_supplicants, psy->desc->name);
   559		if (j < 0)
   560			return 0;
   561	
   562		/* Go through all properties for the psy */
   563		for (j = 0; j < ext->desc->num_properties; j++) {
   564			enum power_supply_property prop;
   565			prop = ext->desc->properties[j];
   566	
   567			if (power_supply_get_property(ext, prop, &ret))
   568				continue;
   569	
   570			switch (prop) {
   571			case POWER_SUPPLY_PROP_PRESENT:
   572				switch (ext->desc->type) {
   573				case POWER_SUPPLY_TYPE_MAINS:
   574					/* AC disconnected */
   575					if (!ret.intval && di->events.ac_conn) {
   576						di->events.ac_conn = false;
   577					}
   578					/* AC connected */
   579					else if (ret.intval && !di->events.ac_conn) {
   580						di->events.ac_conn = true;
   581						if (!di->events.usb_conn)
   582							ab8500_btemp_periodic(di, true);
   583					}
   584					break;
   585				case POWER_SUPPLY_TYPE_USB:
   586					/* USB disconnected */
   587					if (!ret.intval && di->events.usb_conn) {
   588						di->events.usb_conn = false;
   589					}
   590					/* USB connected */
   591					else if (ret.intval && !di->events.usb_conn) {
   592						di->events.usb_conn = true;
   593						if (!di->events.ac_conn)
   594							ab8500_btemp_periodic(di, true);
   595					}
   596					break;
   597				default:
   598					break;
   599				}
   600				break;
   601			default:
   602				break;
   603			}
   604		}
   605		return 0;
   606	}
   607
diff mbox series

Patch

diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c
index 37039e28fc4bd27844e36ee69e700fed24d5ee8d..0c13867a33539d7f300965fe5543e09829f38b2b 100644
--- a/drivers/power/supply/ab8500_btemp.c
+++ b/drivers/power/supply/ab8500_btemp.c
@@ -540,10 +540,9 @@  static int ab8500_btemp_get_property(struct power_supply *psy,
 	return 0;
 }
 
-static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
+static int ab8500_btemp_get_ext_psy_data(struct power_supply_ext *ext, void *data)
 {
 	struct power_supply *psy;
-	struct power_supply *ext = dev_get_drvdata(dev);
 	const char **supplicants = (const char **)ext->supplied_to;
 	struct ab8500_btemp *di;
 	union power_supply_propval ret;
@@ -617,7 +616,7 @@  static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
  */
 static void ab8500_btemp_external_power_changed(struct power_supply *psy)
 {
-	power_supply_for_each_device(psy, ab8500_btemp_get_ext_psy_data);
+	power_supply_for_each_psy(psy, ab8500_btemp_get_ext_psy_data);
 }
 
 /* ab8500 btemp driver interrupts and their respective isr */
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index 14e1b448bd39b286404f31509dbe006d16390877..3af92b1f9b1709e5929fee26cad7bd4de3b3417f 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -844,10 +844,9 @@  static void handle_maxim_chg_curr(struct ab8500_chargalg *di)
 	}
 }
 
-static int ab8500_chargalg_get_ext_psy_data(struct device *dev, void *data)
+static int ab8500_chargalg_get_ext_psy_data(struct power_supply_ext *ext, void *data)
 {
 	struct power_supply *psy;
-	struct power_supply *ext = dev_get_drvdata(dev);
 	const char **supplicants = (const char **)ext->supplied_to;
 	struct ab8500_chargalg *di;
 	union power_supply_propval ret;
@@ -1231,7 +1230,7 @@  static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
 	int ret;
 
 	/* Collect data from all power_supply class devices */
-	power_supply_for_each_device(di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);
+	power_supply_for_each_psy(di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);
 
 	ab8500_chargalg_end_of_charge(di);
 	ab8500_chargalg_check_temp(di);
diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index cece8d6753ac14f8970c13ce6b2d91e678733574..1042d37424f5b0351edd02b5c76e58dd447d1783 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -1894,10 +1894,9 @@  static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
 	return ret;
 }
 
-static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
+static int ab8500_charger_get_ext_psy_data(struct power_supply *ext, void *data)
 {
 	struct power_supply *psy;
-	struct power_supply *ext = dev_get_drvdata(dev);
 	const char **supplicants = (const char **)ext->supplied_to;
 	struct ab8500_charger *di;
 	union power_supply_propval ret;
@@ -1961,7 +1960,7 @@  static void ab8500_charger_check_vbat_work(struct work_struct *work)
 	struct ab8500_charger *di = container_of(work,
 		struct ab8500_charger, check_vbat_work.work);
 
-	power_supply_for_each_device(&di->usb_chg, ab8500_charger_get_ext_psy_data);
+	power_supply_for_each_psy(&di->usb_chg, ab8500_charger_get_ext_psy_data);
 
 	/* First run old_vbat is 0. */
 	if (di->old_vbat == 0)
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index 78871a2143de34c7e1a81882ab7105fbf19387ec..549403c6f73c1581d373c6df83cbc255ab1c2e82 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -2174,10 +2174,9 @@  static int ab8500_fg_get_property(struct power_supply *psy,
 	return 0;
 }
 
-static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
+static int ab8500_fg_get_ext_psy_data(struct power_supply *ext, void *data)
 {
 	struct power_supply *psy;
-	struct power_supply *ext = dev_get_drvdata(dev);
 	const char **supplicants = (const char **)ext->supplied_to;
 	struct ab8500_fg *di;
 	struct power_supply_battery_info *bi;
@@ -2402,7 +2401,7 @@  static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)
  */
 static void ab8500_fg_external_power_changed(struct power_supply *psy)
 {
-	power_supply_for_each_device(psy, ab8500_fg_get_ext_psy_data);
+	power_supply_for_each_psy(psy, ab8500_fg_get_ext_psy_data);
 }
 
 /**