* [PATCH] phy: mediatek: xsphy: reduce main allocation
@ 2026-03-04 4:34 Rosen Penev
2026-03-06 4:13 ` Gustavo A. R. Silva
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-04 4:34 UTC (permalink / raw)
To: linux-phy
Cc: Chunfeng Yun, Vinod Koul, Neil Armstrong, Matthias Brugger,
AngeloGioacchino Del Regno, Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] phy: mediatek: xsphy: reduce main allocation
2026-03-04 4:34 [PATCH] phy: mediatek: xsphy: reduce main allocation Rosen Penev
@ 2026-03-06 4:13 ` Gustavo A. R. Silva
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-06 4:13 UTC (permalink / raw)
To: Rosen Penev, linux-phy
Cc: Chunfeng Yun, Vinod Koul, Neil Armstrong, Matthias Brugger,
AngeloGioacchino Del Regno, Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
moderated list:ARM/Mediatek USB3 PHY DRIVER,
open list:ARM/Mediatek SoC support,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
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);
>
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-06 19:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 4:34 [PATCH] phy: mediatek: xsphy: reduce main allocation Rosen Penev
2026-03-06 4:13 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox