phy: mediatek: tphy: simplify main allocation
Subsystems (3)
PATCH v3 1/1 phy: mediatek: tphy: simplify main allocation
Use a flexible array member to replace kzalloc + kcalloc with a single kzalloc.
Shuffled some code around as __counted_by requires the counting variable to be assigned before any array access.
---
v3: remove of_device_get_match_data message as it's now stale
v2: add back NULL check
drivers/phy/mediatek/phy-mtk-tphy.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/phy/mediatek/phy-mtk-tphy.c +7 -10
@@ -340,10 +340,10 @@ struct mtk_tphy {struct device *dev;void __iomem *sif_base;/* only shared sif */ const struct mtk_phy_pdata *pdata; -struct mtk_phy_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 mtk_phy_instance *phys[] __counted_by(nphys); };#if IS_ENABLED (CONFIG_DEBUG_FS )
@@ -1572,22 +1572,19 @@ static int mtk_tphy_probe(struct platform_device *pdev)struct mtk_tphy *tphy;struct resource res;int port, ret; +size_t nphys; - tphy =devm_kzalloc (dev,sizeof (*tphy),GFP_KERNEL ); + nphys =of_get_child_count (np); + tphy =devm_kzalloc (dev,struct_size (tphy, phys, nphys),GFP_KERNEL );if (!tphy)return -ENOMEM ; + tphy->nphys = nphys; + tphy->dev = dev; tphy->pdata =of_device_get_match_data (dev);if (!tphy->pdata)return -EINVAL ; - tphy->nphys =of_get_child_count (np); - tphy->phys =devm_kcalloc (dev, tphy->nphys, -sizeof (*tphy->phys),GFP_KERNEL ); -if (!tphy->phys) -return -ENOMEM ; - - tphy->dev = dev;platform_set_drvdata (pdev, tphy); sif_res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
Signature · 1 line
2.56.0
Quoted 7 lines · Rosen Penev
Use a flexible array member to replace kzalloc + kcalloc with a single kzalloc.
Shuffled some code around as
__counted_byrequires the counting variable to be assigned before any array access.Signed-off-by Rosen Penev <[email protected]>
- Mani
Quoted 8 lines · Rosen Penev
Use a flexible array member to replace kzalloc + kcalloc with a single kzalloc.
Shuffled some code around as
__counted_byrequires the counting variable to be assigned before any array access.[...]
Applied, thanks!
[1/1] phy: mediatek: tphy: simplify main allocation
commit: 90ebdb0cbfa1cc1d23fa275ef96897d42b29503b
Best regards,
Signature · 1 line
~Vinod