From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Rosen Penev <rosenp@gmail.com>, linux-phy@lists.infradead.org
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>,
Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"moderated list:ARM/Mediatek USB3 PHY DRIVER"
<linux-arm-kernel@lists.infradead.org>,
"moderated list:ARM/Mediatek USB3 PHY DRIVER"
<linux-mediatek@lists.infradead.org>,
"open list:ARM/Mediatek SoC support"
<linux-kernel@vger.kernel.org>,
open "list:KERNEL" HARDENING "(not" covered by other
"areas):Keyword:b__counted_by(_le|_be)?b"
<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] phy: mediatek: xsphy: reduce main allocation
Date: Fri, 6 Mar 2026 13:13:43 +0900 [thread overview]
Message-ID: <1b50b40e-6682-4156-a60a-c2725527d648@embeddedor.com> (raw)
In-Reply-To: <20260304043420.14151-1-rosenp@gmail.com>
On 3/4/26 13:34, Rosen Penev wrote:
> Instead of kzalloc and kcalloc, we can use a flex array to reduce to a
> single allocation.
>
> Also added __counted_by() for extra possible analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
-Gustavo
> ---
> drivers/phy/mediatek/phy-mtk-xsphy.c | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c b/drivers/phy/mediatek/phy-mtk-xsphy.c
> index c0ddb9273cc3..cc1d66954212 100644
> --- a/drivers/phy/mediatek/phy-mtk-xsphy.c
> +++ b/drivers/phy/mediatek/phy-mtk-xsphy.c
> @@ -112,10 +112,10 @@ struct xsphy_instance {
> struct mtk_xsphy {
> struct device *dev;
> void __iomem *glb_base; /* only shared u3 sif */
> - struct xsphy_instance **phys;
> - int nphys;
> int src_ref_clk; /* MHZ, reference clock for slew rate calibrate */
> int src_coef; /* coefficient for slew rate calibrate */
> + int nphys;
> + struct xsphy_instance *phys[] __counted_by(nphys);
> };
>
> static void u2_phy_slew_rate_calibrate(struct mtk_xsphy *xsphy,
> @@ -515,18 +515,15 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
> struct resource *glb_res;
> struct mtk_xsphy *xsphy;
> struct resource res;
> + size_t nphys;
> int port;
>
> - xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL);
> + nphys = of_get_child_count(np);
> + xsphy = devm_kzalloc(dev, struct_size(xsphy, phys, nphys), GFP_KERNEL);
> if (!xsphy)
> return -ENOMEM;
>
> - xsphy->nphys = of_get_child_count(np);
> - xsphy->phys = devm_kcalloc(dev, xsphy->nphys,
> - sizeof(*xsphy->phys), GFP_KERNEL);
> - if (!xsphy->phys)
> - return -ENOMEM;
> -
> + xsphy->nphys = nphys;
> xsphy->dev = dev;
> platform_set_drvdata(pdev, xsphy);
>
next prev parent reply other threads:[~2026-03-06 19:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 4:34 Rosen Penev
2026-03-06 4:13 ` Gustavo A. R. Silva [this message]
2026-05-14 16:18 ` Vinod Koul
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=1b50b40e-6682-4156-a60a-c2725527d648@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chunfeng.yun@mediatek.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-phy@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=neil.armstrong@linaro.org \
--cc=rosenp@gmail.com \
--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®