linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Li, Meng" <Meng.Li@windriver.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "Magnus Damm" <magnus.damm@gmail.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Marek Vasut" <marek.vasut+renesas@gmail.com>,
	"Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.com>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	linux-pci <linux-pci@vger.kernel.org>
Subject: RE: [PATCH] pci: pcie-rcar: add regulators support
Date: Tue, 19 Oct 2021 10:59:27 +0000	[thread overview]
Message-ID: <PH0PR11MB519149EA25F1C911C5ADA5FFF1BD9@PH0PR11MB5191.namprd11.prod.outlook.com> (raw)
In-Reply-To: <CAMuHMdUJ4nzz169=LG_q6rx7naKVdk-VUrxiQ9VzS=fxjCQ2WA@mail.gmail.com>



> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: Tuesday, October 19, 2021 6:20 PM
> To: Li, Meng <Meng.Li@windriver.com>
> Cc: Magnus Damm <magnus.damm@gmail.com>; Rob Herring
> <robh+dt@kernel.org>; Marek Vasut <marek.vasut+renesas@gmail.com>;
> Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>; Lorenzo Pieralisi
> <lorenzo.pieralisi@arm.com>; Krzysztof Wilczyński <kw@linux.com>; Bjorn
> Helgaas <bhelgaas@google.com>; Liam Girdwood <lgirdwood@gmail.com>;
> Mark Brown <broonie@kernel.org>; Linux-Renesas <linux-renesas-
> soc@vger.kernel.org>; open list:OPEN FIRMWARE AND FLATTENED DEVICE
> TREE BINDINGS <devicetree@vger.kernel.org>; Linux Kernel Mailing List
> <linux-kernel@vger.kernel.org>; linux-pci <linux-pci@vger.kernel.org>
> Subject: Re: [PATCH] pci: pcie-rcar: add regulators support
> 
> [Please note: This e-mail is from an EXTERNAL e-mail address]
> 
> Hi Meng,
> 
> On Tue, Oct 19, 2021 at 11:59 AM Meng Li <Meng.Li@windriver.com> wrote:
> > From: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
> >
> > Add PCIe regulators for KingFisher board.
> >
> > Signed-off-by: Meng Li <Meng.Li@windriver.com>
> 
> Thanks for your patch!
> 
> >  arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++
> > drivers/pci/controller/pcie-rcar-host.c  | 64 ++++++++++++++++++++++++
> 
> Please split patches touching both DT and driver sources.
> 
> > --- a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
> > +++ b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
> 
> > @@ -259,6 +303,9 @@
> >
> >  &pciec1 {
> >         status = "okay";
> > +
> > +       pcie3v3-supply = <&mpcie_3v3>;
> > +       pcie1v8-supply = <&mpcie_1v8>;
> 
> This needs an update to the R-Car PCIe DT bindings first.
> 
> > --- a/drivers/pci/controller/pcie-rcar-host.c
> > +++ b/drivers/pci/controller/pcie-rcar-host.c
> 
> > @@ -893,6 +896,36 @@ static const struct of_device_id
> rcar_pcie_of_match[] = {
> >         {},
> >  };
> >
> > +static int rcar_pcie_set_vpcie(struct rcar_pcie_host *host) {
> > +       struct device *dev = host->pcie.dev;
> > +       int err;
> > +
> > +       if (!IS_ERR(host->pcie3v3)) {
> > +               err = regulator_enable(host->pcie3v3);
> 
> This will crash if host->pcie3v3 is NULL (optional regulator not present).
> Probably you just want to check for non-NULL (see below).
> 
> > +               if (err) {
> > +                       dev_err(dev, "fail to enable vpcie3v3 regulator\n");
> > +                       goto err_out;
> > +               }
> > +       }
> > +
> > +       if (!IS_ERR(host->pcie1v8)) {
> > +               err = regulator_enable(host->pcie1v8);
> 
> Likewise.
> 
> > +               if (err) {
> > +                       dev_err(dev, "fail to enable vpcie1v8 regulator\n");
> > +                       goto err_disable_3v3;
> > +               }
> > +       }
> > +
> > +       return 0;
> > +
> > +err_disable_3v3:
> > +       if (!IS_ERR(host->pcie3v3))
> 
> Likewise.
> 
> > +               regulator_disable(host->pcie3v3);
> > +err_out:
> > +       return err;
> > +}
> > +
> >  static int rcar_pcie_probe(struct platform_device *pdev)  {
> >         struct device *dev = &pdev->dev; @@ -911,6 +944,31 @@ static
> > int rcar_pcie_probe(struct platform_device *pdev)
> >         pcie->dev = dev;
> >         platform_set_drvdata(pdev, host);
> >
> > +       host->pcie3v3 = devm_regulator_get_optional(dev, "pcie3v3");
> > +       if (IS_ERR(host->pcie3v3)) {
> > +               if (PTR_ERR(host->pcie3v3) == -EPROBE_DEFER) {
> > +                       pci_free_host_bridge(bridge);
> 
> Please drop this.  As the bridge was allocated using
> devm_pci_alloc_host_bridge(), freeing it manually will cause a double free.
> 
> > +                       return -EPROBE_DEFER;
> > +               }
> > +               dev_info(dev, "no pcie3v3 regulator found\n");
> 
> devm_regulator_get_optional() returns NULL if the regulator was not found.
> Hence if IS_ERR() is true, this indicates a real error, which you should handle:
> 
>     if (IS_ERR(host->pcie3v3))
>             return PTR_ERR(host->pcie3v3);
> 
> > +       }
> > +
> > +       host->pcie1v8 = devm_regulator_get_optional(dev, "pcie1v8");
> > +       if (IS_ERR(host->pcie1v8)) {
> > +               if (PTR_ERR(host->pcie1v8) == -EPROBE_DEFER) {
> > +                       pci_free_host_bridge(bridge);
> > +                       return -EPROBE_DEFER;
> > +               }
> > +               dev_info(dev, "no pcie1v8 regulator found\n");
> 
> Likewise.
> 
> > +       }
> > +
> > +       err = rcar_pcie_set_vpcie(host);
> > +       if (err) {
> > +               dev_err(dev, "failed to set pcie regulators\n");
> > +               pci_free_host_bridge(bridge);
> 
> Please drop this to avoid double free.
> 
> > +               return err;
> > +       }
> > +
> >         pm_runtime_enable(pcie->dev);
> >         err = pm_runtime_get_sync(pcie->dev);
> >         if (err < 0) {
> > @@ -985,6 +1043,12 @@ static int rcar_pcie_probe(struct platform_device
> *pdev)
> >         irq_dispose_mapping(host->msi.irq1);
> >
> >  err_pm_put:
> > +       if(!IS_ERR(host->pcie3v3))
> 
> if (host->pcie3v3)
> 
> > +               if (regulator_is_enabled(host->pcie3v3))
> 
> If you get here, the regulator should be enabled?
> 
> > +                       regulator_disable(host->pcie3v3);
> > +       if(!IS_ERR(host->pcie1v8))
> 
> if (host->pcie1v8)
> 
> > +               if (regulator_is_enabled(host->pcie1v8))
> > +                       regulator_disable(host->pcie1v8);
> 
> Please move this below the call to pm_runtime_disable(), to preserve
> symmetry.
> 
> >         pm_runtime_put(dev);
> >         pm_runtime_disable(dev);
> 
> Gr{oetje,eeting}s,
> 

Thanks for your professional suggest.
I will improve patches and send v2 in later

Thanks,
Limeng

>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-
> m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds

  reply	other threads:[~2021-10-19 11:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19  9:58 [PATCH] pci: pcie-rcar: add regulators support Meng Li
2021-10-19 10:19 ` Geert Uytterhoeven
2021-10-19 10:59   ` Li, Meng [this message]
2021-10-19 12:36 ` Mark Brown
2021-10-19 13:30 ` Bjorn Helgaas

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=PH0PR11MB519149EA25F1C911C5ADA5FFF1BD9@PH0PR11MB5191.namprd11.prod.outlook.com \
    --to=meng.li@windriver.com \
    --cc=bhelgaas@google.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=kw@linux.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=magnus.damm@gmail.com \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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;
as well as URLs for NNTP newsgroup(s).