From: "Chaotian Jing (井朝天)" <Chaotian.Jing@mediatek.com>
To: "Peter Wang (王信友)" <peter.wang@mediatek.com>,
"Chunfeng Yun (云春峰)" <Chunfeng.Yun@mediatek.com>,
"nicolas.frattaroli@collabora.com"
<nicolas.frattaroli@collabora.com>,
"kishon@kernel.org" <kishon@kernel.org>,
"avri.altman@wdc.com" <avri.altman@wdc.com>,
"bvanassche@acm.org" <bvanassche@acm.org>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
"broonie@kernel.org" <broonie@kernel.org>,
"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
"chu.stanley@gmail.com" <chu.stanley@gmail.com>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
"robh@kernel.org" <robh@kernel.org>,
"James.Bottomley@HansenPartnership.com"
<James.Bottomley@HansenPartnership.com>,
"lgirdwood@gmail.com" <lgirdwood@gmail.com>,
"vkoul@kernel.org" <vkoul@kernel.org>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"kernel@collabora.com" <kernel@collabora.com>,
Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-phy@lists.infradead.org" <linux-phy@lists.infradead.org>
Subject: Re: [PATCH v3 10/24] scsi: ufs: mediatek: Rework probe function
Date: Wed, 5 Nov 2025 06:28:39 +0000 [thread overview]
Message-ID: <90a10fba2e41db4df4c28a72d182c5f0df8c016d.camel@mediatek.com> (raw)
In-Reply-To: <20251023-mt8196-ufs-v3-10-0f04b4a795ff@collabora.com>
On Thu, 2025-10-23 at 21:49 +0200, Nicolas Frattaroli wrote:
> Remove the ti,syscon-reset cruft.
>
> Make PHY mandatory. All the compatibles supported by the binding make
> it
> mandatory.
>
why make the PHY mandatory ? note that not all of MediaTek SoCs have
the PHY node.
> Entertain this driver's insistence on playing with the PHY's RPM, but
> at
> least fix the part where it doesn't increase the reference count,
> which
> would lead to use-after-free.
>
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> ---
> drivers/ufs/host/ufs-mediatek.c | 87 +++++++++++++++--------------
> ------------
> 1 file changed, 32 insertions(+), 55 deletions(-)
>
> diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-
> mediatek.c
> index 9c0ac72d6e43..889a1d58a041 100644
> --- a/drivers/ufs/host/ufs-mediatek.c
> +++ b/drivers/ufs/host/ufs-mediatek.c
> @@ -2353,74 +2353,49 @@ MODULE_DEVICE_TABLE(of, ufs_mtk_of_match);
> */
> static int ufs_mtk_probe(struct platform_device *pdev)
> {
> - int err;
> - struct device *dev = &pdev->dev, *phy_dev = NULL;
> - struct device_node *reset_node, *phy_node = NULL;
> - struct platform_device *reset_pdev, *phy_pdev = NULL;
> - struct device_link *link;
> - struct ufs_hba *hba;
> + struct platform_device *phy_pdev;
> + struct device *dev = &pdev->dev;
> + struct device_node *phy_node;
> struct ufs_mtk_host *host;
> + struct device *phy_dev;
> + struct ufs_hba *hba;
> + int err;
>
> - reset_node = of_find_compatible_node(NULL, NULL,
> - "ti,syscon-reset");
> - if (!reset_node) {
> - dev_notice(dev, "find ti,syscon-reset fail\n");
> - goto skip_reset;
> - }
> - reset_pdev = of_find_device_by_node(reset_node);
> - if (!reset_pdev) {
> - dev_notice(dev, "find reset_pdev fail\n");
> - goto skip_reset;
> - }
> - link = device_link_add(dev, &reset_pdev->dev,
> - DL_FLAG_AUTOPROBE_CONSUMER);
> - put_device(&reset_pdev->dev);
> - if (!link) {
> - dev_notice(dev, "add reset device_link fail\n");
> - goto skip_reset;
> - }
> - /* supplier is not probed */
> - if (link->status == DL_STATE_DORMANT) {
> - err = -EPROBE_DEFER;
> - goto out;
> - }
> -
> -skip_reset:
> /* find phy node */
> phy_node = of_parse_phandle(dev->of_node, "phys", 0);
> + if (!phy_node)
> + return dev_err_probe(dev, -ENOENT, "No PHY node
> found\n");
>
> - if (phy_node) {
> - phy_pdev = of_find_device_by_node(phy_node);
> - if (!phy_pdev)
> - goto skip_phy;
> - phy_dev = &phy_pdev->dev;
> + phy_pdev = of_find_device_by_node(phy_node);
> + of_node_put(phy_node);
> + if (!phy_pdev)
> + return dev_err_probe(dev, -ENODEV, "No PHY device
> found\n");
>
> - pm_runtime_set_active(phy_dev);
> - pm_runtime_enable(phy_dev);
> - pm_runtime_get_sync(phy_dev);
> + phy_dev = &phy_pdev->dev;
>
> - put_device(phy_dev);
> - dev_info(dev, "phys node found\n");
> - } else {
> - dev_notice(dev, "phys node not found\n");
> + err = pm_runtime_set_active(phy_dev);
> + if (err) {
> + dev_err_probe(dev, err, "Failed to activate PHY
> RPM\n");
> + goto err_put_phy;
> + }
> + pm_runtime_enable(phy_dev);
> + err = pm_runtime_get_sync(phy_dev);
> + if (err) {
> + dev_err_probe(dev, err, "Failed to power on PHY\n");
> + goto err_put_phy;
> }
>
> -skip_phy:
> /* perform generic probe */
> err = ufshcd_pltfrm_init(pdev, &ufs_hba_mtk_vops);
> if (err) {
> - dev_err(dev, "probe failed %d\n", err);
> - goto out;
> + dev_err_probe(dev, err, "Generic platform probe
> failed\n");
> + goto err_put_phy;
> }
>
> hba = platform_get_drvdata(pdev);
> - if (!hba)
> - goto out;
>
> - if (phy_node && phy_dev) {
> - host = ufshcd_get_variant(hba);
> - host->phy_dev = phy_dev;
> - }
> + host = ufshcd_get_variant(hba);
> + host->phy_dev = phy_dev;
>
> /*
> * Because the default power setting of VSx (the upper layer of
> @@ -2429,9 +2404,11 @@ static int ufs_mtk_probe(struct
> platform_device *pdev)
> */
> ufs_mtk_dev_vreg_set_lpm(hba, false);
>
> -out:
> - of_node_put(phy_node);
> - of_node_put(reset_node);
> + return 0;
> +
> +err_put_phy:
> + put_device(phy_dev);
> +
> return err;
> }
>
>
next prev parent reply other threads:[~2025-11-05 6:28 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 19:49 [PATCH v3 00/24] MediaTek UFS Cleanup and MT8196 Enablement Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 01/24] dt-bindings: phy: Add mediatek,mt8196-ufsphy variant Nicolas Frattaroli
2025-10-24 17:09 ` Conor Dooley
2025-10-23 19:49 ` [PATCH v3 02/24] dt-bindings: ufs: mediatek,ufs: Complete the binding Nicolas Frattaroli
2025-10-24 17:25 ` Conor Dooley
2025-11-04 5:43 ` Chaotian Jing (井朝天)
2025-10-23 19:49 ` [PATCH v3 03/24] dt-bindings: ufs: mediatek,ufs: Add mt8196 variant Nicolas Frattaroli
2025-10-24 17:13 ` Conor Dooley
2025-10-24 17:51 ` Nicolas Frattaroli
2025-10-26 22:25 ` Conor Dooley
2025-10-23 19:49 ` [PATCH v3 04/24] scsi: ufs: mediatek: Move MTK_SIP_UFS_CONTROL to mtk_sip_svc.h Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 05/24] phy: mediatek: ufs: Add support for resets Nicolas Frattaroli
2025-10-24 9:06 ` Philipp Zabel
2025-10-23 19:49 ` [PATCH v3 06/24] scsi: ufs: mediatek: Rework resets Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 07/24] scsi: ufs: mediatek: Rework 0.9V regulator Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 08/24] scsi: ufs: mediatek: Rework init function Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 09/24] scsi: ufs: mediatek: Rework the crypt-boost stuff Nicolas Frattaroli
2025-11-04 7:28 ` Chaotian Jing (井朝天)
2025-11-10 9:19 ` Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 10/24] scsi: ufs: mediatek: Rework probe function Nicolas Frattaroli
2025-11-05 6:28 ` Chaotian Jing (井朝天) [this message]
2025-11-10 9:23 ` Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 11/24] scsi: ufs: mediatek: Remove vendor kernel quirks cruft Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 12/24] scsi: ufs: mediatek: Use the common PHY framework Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 13/24] scsi: ufs: mediatek: Switch to newer PM ops helpers Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 14/24] scsi: ufs: mediatek: Remove mediatek,ufs-broken-rtc property Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 15/24] scsi: ufs: mediatek: Rework _ufs_mtk_clk_scale error paths Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 16/24] scsi: ufs: mediatek: Add vendor prefix to clk-scale-up-vcore-min Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 17/24] scsi: ufs: mediatek: Clean up logging prints Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 18/24] scsi: ufs: mediatek: Rework ufs_mtk_wait_idle_state Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 19/24] scsi: ufs: mediatek: Don't acquire dvfsrc-vcore twice Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 20/24] scsi: ufs: mediatek: Rework hardware version reading Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 21/24] scsi: ufs: mediatek: Back up idle timer in per-instance struct Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 22/24] scsi: ufs: mediatek: Make scale_us in setup_clk_gating const Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 23/24] scsi: ufs: mediatek: Remove ret local from link_startup_notify Nicolas Frattaroli
2025-10-23 19:49 ` [PATCH v3 24/24] scsi: ufs: mediatek: Add MT8196 compatible, update copyright Nicolas Frattaroli
2025-10-24 9:00 ` [PATCH v3 00/24] MediaTek UFS Cleanup and MT8196 Enablement AngeloGioacchino Del Regno
2025-10-24 17:22 ` Conor Dooley
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=90a10fba2e41db4df4c28a72d182c5f0df8c016d.camel@mediatek.com \
--to=chaotian.jing@mediatek.com \
--cc=Chunfeng.Yun@mediatek.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=avri.altman@wdc.com \
--cc=broonie@kernel.org \
--cc=bvanassche@acm.org \
--cc=chu.stanley@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@collabora.com \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=louisalexis.eyraud@collabora.com \
--cc=martin.petersen@oracle.com \
--cc=matthias.bgg@gmail.com \
--cc=nicolas.frattaroli@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=peter.wang@mediatek.com \
--cc=robh@kernel.org \
--cc=vkoul@kernel.org \
/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
all inboxes | Powered by JetHome®