From: Rosen Penev <rosenp@gmail.com>
To: 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>,
linux-arm-kernel@lists.infradead.org (moderated
list:ARM/Mediatek USB3 PHY DRIVER),
linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek
USB3 PHY DRIVER),
linux-kernel@vger.kernel.org (open list:ARM/Mediatek SoC support),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] phy: mediatek: xsphy: reduce main allocation
Date: Tue, 3 Mar 2026 20:34:20 -0800 [thread overview]
Message-ID: <20260304043420.14151-1-rosenp@gmail.com> (raw)
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>
---
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);
--
2.53.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next reply other threads:[~2026-03-04 4:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 4:34 Rosen Penev [this message]
2026-03-06 4:13 ` [PATCH] phy: mediatek: xsphy: reduce main allocation Gustavo A. R. Silva
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=20260304043420.14151-1-rosenp@gmail.com \
--to=rosenp@gmail.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=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