lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 18 Jul 2022 16:08:35 +0800
From:   ChiYuan Huang <u0084500@...il.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     ChiaEn Wu <peterwu.pub@...il.com>,
        Lee Jones <lee.jones@...aro.org>,
        Daniel Thompson <daniel.thompson@...aro.org>,
        Jingoo Han <jingoohan1@...il.com>, Pavel Machek <pavel@....cz>,
        Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        Sebastian Reichel <sre@...nel.org>,
        Chunfeng Yun <chunfeng.yun@...iatek.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Liam Girdwood <lgirdwood@...il.com>,
        Mark Brown <broonie@...nel.org>,
        Guenter Roeck <linux@...ck-us.net>,
        "Krogerus, Heikki" <heikki.krogerus@...ux.intel.com>,
        Helge Deller <deller@....de>,
        ChiaEn Wu <chiaen_wu@...htek.com>,
        Alice Chen <alice_chen@...htek.com>,
        cy_huang <cy_huang@...htek.com>,
        dri-devel <dri-devel@...ts.freedesktop.org>,
        Linux LED Subsystem <linux-leds@...r.kernel.org>,
        devicetree <devicetree@...r.kernel.org>,
        linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>,
        "moderated list:ARM/Mediatek SoC support" 
        <linux-mediatek@...ts.infradead.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Linux PM <linux-pm@...r.kernel.org>,
        USB <linux-usb@...r.kernel.org>,
        linux-iio <linux-iio@...r.kernel.org>,
        "open list:FRAMEBUFFER LAYER" <linux-fbdev@...r.kernel.org>,
        szuni chen <szunichen@...il.com>,
        ChiYuan Huang <u0084500@...il.com>
Subject: Re: [PATCH v5 08/13] usb: typec: tcpci_mt6370: Add MediaTek MT6370
 tcpci driver

On Fri, Jul 15, 2022 at 03:10:42PM +0200, Andy Shevchenko wrote:
> On Fri, Jul 15, 2022 at 1:28 PM ChiaEn Wu <peterwu.pub@...il.com> wrote:
> 
> > The MT6370 is a highly-integrated smart power management IC, which
> > includes a single cell Li-Ion/Li-Polymer switching battery charger,
> > a USB Type-C & Power Delivery (PD) controller, dual Flash LED current
> > sources, a RGB LED driver, a backlight WLED driver, a display bias
> > driver and a general LDO for portable devices.
> >
> > This commit add support for the Type-C & Power Delivery controller in
> 
> This commit add -> Add
> 
Upper case? Or rewrite it as 'This commit is to add .....'?
> 
> > MediaTek MT6370 IC.
> 
> 
> > +static int mt6370_tcpc_probe(struct platform_device *pdev)
> > +{
> > +       struct mt6370_priv *priv;
> > +       struct device *dev = &pdev->dev;
> > +       int ret;
> > +
> > +       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > +       if (!priv)
> > +               return -ENOMEM;
> > +
> > +       priv->dev = dev;
> > +       platform_set_drvdata(pdev, priv);
> > +
> > +       priv->tcpci_data.regmap = dev_get_regmap(dev->parent, NULL);
> > +       if (!priv->tcpci_data.regmap)
> > +               return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n");
> > +
> > +       ret = mt6370_check_vendor_info(priv);
> > +       if (ret)
> > +               return ret;
> > +
> > +       priv->irq = platform_get_irq(pdev, 0);
> > +       if (priv->irq < 0)
> > +               return priv->irq;
> > +
> > +       /* Assign TCPCI feature and ops */
> > +       priv->tcpci_data.auto_discharge_disconnect = 1;
> > +       priv->tcpci_data.init = mt6370_tcpc_init;
> > +       priv->tcpci_data.set_vconn = mt6370_tcpc_set_vconn;
> > +
> > +       priv->vbus = devm_regulator_get_optional(dev, "vbus");
> > +       if (!IS_ERR(priv->vbus))
> > +               priv->tcpci_data.set_vbus = mt6370_tcpc_set_vbus;
> > +
> > +       priv->tcpci = tcpci_register_port(dev, &priv->tcpci_data);
> > +       if (IS_ERR(priv->tcpci))
> > +               return dev_err_probe(dev, PTR_ERR(priv->tcpci),
> > +                                    "Failed to register tcpci port\n");
> > +
> > +       ret = devm_request_threaded_irq(dev, priv->irq, NULL,
> > +                                       mt6370_irq_handler, IRQF_ONESHOT,
> > +                                       dev_name(dev), priv);
> > +       if (ret) {
> 
> > +               tcpci_unregister_port(priv->tcpci);
> 
> This is wrong.
> You mixed devm_ with non-devm. Either drop devm_ *after* the first
> non-devm_ call, or convert everything to be managed.
> 
How about to add 'devm_add_action_or_reset' for tcpci_unregister_port?
This will convert all as 'devm_' version.
> > +               return dev_err_probe(dev, ret, "Failed to allocate irq\n");
> > +       }
> > +
> > +       device_init_wakeup(dev, true);
> > +       dev_pm_set_wake_irq(dev, priv->irq);
> > +
> > +       return 0;
> > +}
> > +
> > +static int mt6370_tcpc_remove(struct platform_device *pdev)
> > +{
> > +       struct mt6370_priv *priv = platform_get_drvdata(pdev);
> 
> > +       disable_irq(priv->irq);
> 
> Why?
> An ugly workaround due to ordering issues in ->probe()?
>
Yes, due to the ordering in probe.
'bus remove' will be called before device resource releases.

Like as you said, another way is to convert all as non-devm
version after 'tcpci_unregister_port'.

If to keep the original order, 'disable_irq' before
'tcpci_unregister_port' can make the flow more safe.

Or you can think one case if irq triggers after
'tcpci_unregister_port'. Null pointer occurs.

Anyway, in next revision, I'll convert all to be 'devm_' version.
For this remove callback, only 'dev_pm_clear_wake_irq' and
'device_init_wakeup' will be kept.

Is this better?

> > +       tcpci_unregister_port(priv->tcpci);
> > +       dev_pm_clear_wake_irq(&pdev->dev);
> > +       device_init_wakeup(&pdev->dev, false);
> > +
> > +       return 0;
> > +}
> 
> -- 
> With Best Regards,
> Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ