]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
phy: mediatek: xsphy: reduce main allocation
authorRosen Penev <rosenp@gmail.com>
Wed, 4 Mar 2026 04:34:20 +0000 (20:34 -0800)
committerVinod Koul <vkoul@kernel.org>
Thu, 14 May 2026 15:57:02 +0000 (21:27 +0530)
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>
Link: https://patch.msgid.link/20260304043420.14151-1-rosenp@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/phy/mediatek/phy-mtk-xsphy.c

index c0ddb9273cc3f51e320a2698fdd62629b5b58949..cc1d66954212a3c330e22b5be4f59993b8f5e49a 100644 (file)
@@ -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);