public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakob Hauser <jahau@rocketmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Sebastian Reichel <sre@kernel.org>, Lee Jones <lee@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Beomho Seo <beomho.seo@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Stephan Gerhold <stephan@gerhold.net>,
	Raymond Hackley <raymondhackley@protonmail.com>,
	Pavel Machek <pavel@ucw.cz>, Axel Lin <axel.lin@ingics.com>,
	ChiYuan Huang <cy_huang@richtek.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Henrik Grimler <henrik@grimler.se>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH v5 05/10] power: supply: rt5033_charger: Add RT5033 charger device driver
Date: Sun, 14 May 2023 19:03:03 +0200	[thread overview]
Message-ID: <b2a52060-6727-b91d-79aa-55cdb3cbc63c@rocketmail.com> (raw)
In-Reply-To: <2e0f37ef-b80c-1a4d-2159-29598ac11156@wanadoo.fr>

Hi Christophe, Hi all,

On 14.05.23 16:31, Christophe JAILLET wrote:
> Le 14/05/2023 à 14:31, Jakob Hauser a écrit :

...

>> +static int rt5033_charger_probe(struct platform_device *pdev)
>> +{
>> +    struct rt5033_charger *charger;
>> +    struct power_supply_config psy_cfg = {};
>> +    int ret;
>> +
>> +    charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
>> +    if (!charger)
>> +        return -ENOMEM;
>> +
>> +    platform_set_drvdata(pdev, charger);
>> +    charger->dev = &pdev->dev;
>> +    charger->regmap = dev_get_regmap(pdev->dev.parent, NULL);
>> +
>> +    psy_cfg.of_node = pdev->dev.of_node;
>> +    psy_cfg.drv_data = charger;
>> +
>> +    charger->psy = devm_power_supply_register(&pdev->dev,
>> +                          &rt5033_charger_desc,
>> +                          &psy_cfg);
>> +    if (IS_ERR(charger->psy))
>> +        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))
> 
> Hi,
> 
> Nit: charger->chg can't be NULL.
> 
>> +        return -ENODEV;
> 
> Why bother returning specific error code in rt5033_charger_dt_init() if 
> they are eaten here.
> 
> return PTR_ERR(charger->chg)?
> 

Thanks for the heads-up.

...

Writing towards the list:

The way it is done in the current patchset is taken from the original 
patchset of March 2015 [2]. I kept the original as far as possible.

By now I'm not happy with the way of initializing "struct 
rt5033_charger_data". I realized this in the course of the review. As I 
didn't want to disturb the review with this, I had planned a small 
clean-up patch after this review is finished.

The cause of the complicated handling of "struct rt5033_charger_data" 
lies inside of the "struct rt5033_charger". There the "struct 
rt5033_charger_data" is initialized as pointer *chg.

The clean-up would be:

  - Inside of "struct rt5033_charger" change the
    "struct rt5033_charger_data" to non-pointer "chg". It is then
    initialized right away.

       struct rt5033_charger_data      chg;

  - Change function rt5033_charger_dt_init() from type
    "struct rt5033_charger_data" to type "int".

       static int rt5033_charger_dt_init(struct rt5033_charger *charger)

  - In the probe function, call the function rt5033_charger_dt_init() in
    the same way like e.g. the following rt5033_charger_reg_init():

       ret = rt5033_charger_dt_init(charger);
               if (ret)
                       return ret;

  - Within function rt5033_charger_dt_init() and all other functions
    using the charger data, get the address of the already-initialized
    struct &charger->chg.

       struct rt5033_charger_data *chg = &charger->chg;

This would also solve the issue reported by Christophe because the 
errors inside function rt5033_charger_dt_init() would be passed to the 
probe function by the "ret =" and being returned there with "return ret".

I'm not sure how to handle this now. I would prefer to get the review of 
this patchset finished and send a clean-up patch afterwards.

[2] 
https://lore.kernel.org/lkml/1425864191-4121-1-git-send-email-beomho.seo@samsung.com/T/#u

Kind regards,
Jakob

  reply	other threads:[~2023-05-14 17:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230514123130.41172-1-jahau.ref@rocketmail.com>
2023-05-14 12:31 ` [PATCH v5 00/10] Add RT5033 charger device driver Jakob Hauser
2023-05-14 12:31   ` [PATCH v5 01/10] mfd: rt5033: Drop rt5033-battery sub-device Jakob Hauser
2023-05-14 12:31   ` [PATCH v5 02/10] mfd: rt5033: Fix chip revision readout Jakob Hauser
2023-05-14 12:31   ` [PATCH v5 03/10] mfd: rt5033: Fix STAT_MASK, HZ_MASK and AICR defines Jakob Hauser
2023-05-14 12:31   ` [PATCH v5 04/10] mfd: rt5033: Apply preparatory changes before adding rt5033-charger driver Jakob Hauser
2023-05-14 12:31   ` [PATCH v5 05/10] power: supply: rt5033_charger: Add RT5033 charger device driver Jakob Hauser
2023-05-14 12:54     ` Jakob Hauser
2023-05-14 14:31     ` Christophe JAILLET
2023-05-14 17:03       ` Jakob Hauser [this message]
2023-05-14 22:51         ` Sebastian Reichel
2023-05-14 12:31   ` [PATCH v5 06/10] power: supply: rt5033_charger: Add cable detection and USB OTG supply Jakob Hauser
2023-05-14 22:47     ` Sebastian Reichel
2023-05-14 12:31   ` [PATCH v5 07/10] power: supply: rt5033_battery: Move struct rt5033_battery to battery driver Jakob Hauser
2023-05-14 22:47     ` Sebastian Reichel
2023-05-14 12:31   ` [PATCH v5 08/10] power: supply: rt5033_battery: Adopt status property from charger Jakob Hauser
2023-05-14 22:48     ` Sebastian Reichel
2023-05-14 12:31   ` [PATCH v5 09/10] dt-bindings: power: supply: rt5033-battery: Add power-supplies as a property Jakob Hauser
2023-05-14 16:43     ` Krzysztof Kozlowski
2023-05-14 12:31   ` [PATCH v5 10/10] dt-bindings: Add rt5033 mfd, regulator and charger Jakob Hauser
2023-05-14 16:44     ` Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b2a52060-6727-b91d-79aa-55cdb3cbc63c@rocketmail.com \
    --to=jahau@rocketmail.com \
    --cc=axel.lin@ingics.com \
    --cc=beomho.seo@samsung.com \
    --cc=broonie@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=cw00.choi@samsung.com \
    --cc=cy_huang@richtek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=henrik@grimler.se \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lee@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=phone-devel@vger.kernel.org \
    --cc=raymondhackley@protonmail.com \
    --cc=robh+dt@kernel.org \
    --cc=sre@kernel.org \
    --cc=stephan@gerhold.net \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox