[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <95e236e16e25978d1a0280302cecd3bf59687e98.1695844349.git.jahau@rocketmail.com>
Date: Wed, 27 Sep 2023 22:26:01 +0200
From: Jakob Hauser <jahau@...ketmail.com>
To: Sebastian Reichel <sre@...nel.org>
Cc: Lee Jones <lee@...nel.org>,
Stephen Rothwell <sfr@...b.auug.org.au>,
Yang Yingliang <yangyingliang@...wei.com>,
Christophe Jaillet <christophe.jaillet@...adoo.fr>,
Stephan Gerhold <stephan@...hold.net>,
Raymond Hackley <raymondhackley@...tonmail.com>,
Henrik Grimler <henrik@...mler.se>, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org,
~postmarketos/upstreaming@...ts.sr.ht,
Jakob Hauser <jahau@...ketmail.com>
Subject: [PATCH 4/5] power: supply: rt5033_charger: Simplify initialization of rt5033_charger_data
Currently the struct "rt5033_charger_data" is initialized rather complicated.
The cause lies inside of the struct "rt5033_charger", where struct
"rt5033_charger_data" is implemented as a pointer *chg.
Therefore, inside of struct "rt5033_charger" change the struct
"rt5033_charger_data" to non-pointer "chg". It is then initialized right
away and can be accessed more easily.
Signed-off-by: Jakob Hauser <jahau@...ketmail.com>
---
drivers/power/supply/rt5033_charger.c | 29 +++++++++++----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c
index 091ca4a21f29..b34ef0ea6f8a 100644
--- a/drivers/power/supply/rt5033_charger.c
+++ b/drivers/power/supply/rt5033_charger.c
@@ -29,7 +29,7 @@ struct rt5033_charger {
struct device *dev;
struct regmap *regmap;
struct power_supply *psy;
- struct rt5033_charger_data *chg;
+ struct rt5033_charger_data chg;
struct extcon_dev *edev;
struct notifier_block extcon_nb;
struct work_struct extcon_work;
@@ -131,7 +131,7 @@ static int rt5033_get_charger_const_voltage(struct rt5033_charger *charger)
static inline int rt5033_init_const_charge(struct rt5033_charger *charger)
{
- struct rt5033_charger_data *chg = charger->chg;
+ struct rt5033_charger_data *chg = &charger->chg;
int ret;
unsigned int val;
u8 reg_data;
@@ -205,7 +205,7 @@ static inline int rt5033_init_const_charge(struct rt5033_charger *charger)
static inline int rt5033_init_fast_charge(struct rt5033_charger *charger)
{
- struct rt5033_charger_data *chg = charger->chg;
+ struct rt5033_charger_data *chg = &charger->chg;
int ret;
unsigned int val;
u8 reg_data;
@@ -250,7 +250,7 @@ static inline int rt5033_init_fast_charge(struct rt5033_charger *charger)
static inline int rt5033_init_pre_charge(struct rt5033_charger *charger)
{
- struct rt5033_charger_data *chg = charger->chg;
+ struct rt5033_charger_data *chg = &charger->chg;
int ret;
unsigned int val;
u8 reg_data;
@@ -550,21 +550,16 @@ static int rt5033_charger_get_property(struct power_supply *psy,
return 0;
}
-static struct rt5033_charger_data *rt5033_charger_dt_init(
- struct rt5033_charger *charger)
+static int rt5033_charger_dt_init(struct rt5033_charger *charger)
{
- struct rt5033_charger_data *chg;
+ struct rt5033_charger_data *chg = &charger->chg;
struct power_supply_battery_info *info;
int ret;
- chg = devm_kzalloc(charger->dev, sizeof(*chg), GFP_KERNEL);
- if (!chg)
- return ERR_PTR(-ENOMEM);
-
ret = power_supply_get_battery_info(charger->psy, &info);
if (ret)
- return ERR_PTR(dev_err_probe(charger->dev, -EINVAL,
- "missing battery info\n"));
+ return dev_err_probe(charger->dev, -EINVAL,
+ "missing battery info\n");
/* Assign data. Validity will be checked in the init functions. */
chg->pre_uamp = info->precharge_current_ua;
@@ -573,7 +568,7 @@ static struct rt5033_charger_data *rt5033_charger_dt_init(
chg->pre_uvolt = info->precharge_voltage_max_uv;
chg->const_uvolt = info->constant_charge_voltage_max_uv;
- return chg;
+ return 0;
}
static void rt5033_charger_extcon_work(struct work_struct *work)
@@ -690,9 +685,9 @@ static int rt5033_charger_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(charger->psy),
"Failed to register power supply\n");
- charger->chg = rt5033_charger_dt_init(charger);
- if (IS_ERR_OR_NULL(charger->chg))
- return PTR_ERR(charger->chg);
+ ret = rt5033_charger_dt_init(charger);
+ if (ret)
+ return ret;
ret = rt5033_charger_reg_init(charger);
if (ret)
--
2.39.2
Powered by blists - more mailing lists