phy: mediatek: xsphy: reduce main allocation
Subsystems (3)
PATCH 1/1 phy: mediatek: xsphy: reduce main allocation
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 <[email protected]>
--- drivers/phy/mediatek/phy-mtk-xsphy.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/phy/mediatek/phy-mtk-xsphy.c +6 -9
@@ -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);
Signature · 1 line
2.53.0
Quoted 6 lines · Rosen Penev
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 <[email protected]>
Reviewed-by Gustavo A. R. Silva <[email protected]>
Thanks
-Gustavo
Quoted 44 lines
--- drivers/phy/mediatek/phy-mtk-xsphy.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)drivers/phy/mediatek/phy-mtk-xsphy.c +6
-9@@ -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);
Quoted 6 lines · Rosen Penev
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.
Applied, thanks!
[1/1] phy: mediatek: xsphy: reduce main allocation
commit: fd6cd05ceabdf67635a4cef5145f79d1217bf11b
Best regards,
Signature · 1 line
~Vinod