phy: miphy28lp: build and simplify allocation
Subsystems (2)
v2 cover phy: miphy28lp: build and simplify allocation
First patch allows compilation on at least x86.
Second uses a flexible array member to simplify allocation.
v2: add first patch and fix second.
Rosen Penev (2):
phy: miphy28lp: add COMPILE_TEST
phy: miphy28lp: kzalloc + kcalloc to single kzalloc
drivers/phy/st/Kconfig | 2 +- drivers/phy/st/phy-miphy28lp.c | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-)
--
2.53.0
PATCH v2 1/2 phy: miphy28lp: add COMPILE_TEST
There's nothing special here to prevent compilation on non ARM hosts.
Matches every other st phy driver.
--- drivers/phy/st/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/st/Kconfig +1 -1
@@ -4,7 +4,7 @@ # config PHY_MIPHY28LP tristate "STMicroelectronics MIPHY28LP PHY driver for STiH407" - depends on ARCH_STI + depends on ARCH_STI || COMPILE_TEST select GENERIC_PHY help Enable this to support the miphy transceiver (for SATA/PCIE/USB3)
--
2.53.0
PATCH v2 2/2 phy: miphy28lp: kzalloc + kcalloc to single kzalloc
In reply to Rosen PenevUse flex array to simplify allocation.
Allows using __counted_by for extra runtime analysis.
--- drivers/phy/st/phy-miphy28lp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/phy/st/phy-miphy28lp.c +5 -7
@@ -224,8 +224,8 @@ struct miphy28lp_dev {struct device *dev;struct regmap *regmap;struct mutex miphy_mutex; -struct miphy28lp_phy **phys;int nphys; + struct miphy28lp_phy *phys[] __counted_by(nphys); };enum miphy_sata_gen {SATA_GEN1 ,SATA_GEN2 ,SATA_GEN3 };
@@ -1168,16 +1168,14 @@ static int miphy28lp_probe(struct platform_device *pdev)struct phy_provider *provider;struct phy *phy;int ret, port =0 ; +size_t nphys; - miphy_dev =devm_kzalloc (&pdev->dev,sizeof (*miphy_dev),GFP_KERNEL ); + nphys =of_get_child_count (np); + miphy_dev =devm_kzalloc (&pdev->dev,struct_size (miphy_dev, phys, nphys),GFP_KERNEL );if (!miphy_dev)return -ENOMEM ; - miphy_dev->nphys =of_get_child_count (np); - miphy_dev->phys =devm_kcalloc (&pdev->dev, miphy_dev->nphys, -sizeof (*miphy_dev->phys),GFP_KERNEL ); -if (!miphy_dev->phys) -return -ENOMEM ; + miphy_dev->nphys = nphys; miphy_dev->regmap =syscon_regmap_lookup_by_phandle (np,"st,syscfg" );if (IS_ERR (miphy_dev->regmap)) {
--
2.53.0
Re: [PATCHv2 1/2] phy: miphy28lp: add COMPILE_TEST
In reply to Rosen PenevQuoted 23 lines · Rosen Penev
There's nothing special here to prevent compilation on non ARM hosts.
Matches every other st phy driver.
Signed-off-by Rosen Penev <[email protected]>--- drivers/phy/st/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/phy/st/Kconfig +1
-2@@ -4,7 +4,7 @@ # config PHY_MIPHY28LP tristate "STMicroelectronics MIPHY28LP PHY driver for STiH407" - depends on ARCH_STI + depends on ARCH_STI || COMPILE_TEST select GENERIC_PHY help Enable this to support the miphy transceiver (for SATA/PCIE/USB3) --
Quoted 2 lines
2.53.0
Thanks
Patrice
Re: [PATCHv2 2/2] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
In reply to Rosen PenevQuoted 45 lines · Rosen Penev
Use flex array to simplify allocation.
Allows using
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>--- drivers/phy/st/phy-miphy28lp.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)drivers/phy/st/phy-miphy28lp.c +5
-8@@ -224,8 +224,8 @@ struct miphy28lp_dev {struct device *dev;struct regmap *regmap;struct mutex miphy_mutex; -struct miphy28lp_phy **phys;int nphys; + struct miphy28lp_phy *phys[] __counted_by(nphys); };enum miphy_sata_gen {SATA_GEN1 ,SATA_GEN2 ,SATA_GEN3 };@@ -1168,16 +1168,14 @@ static int miphy28lp_probe(struct platform_device *pdev)struct phy_provider *provider;struct phy *phy;int ret, port =0 ; +size_t nphys; - miphy_dev =devm_kzalloc (&pdev->dev,sizeof (*miphy_dev),GFP_KERNEL ); + nphys =of_get_child_count (np); + miphy_dev =devm_kzalloc (&pdev->dev,struct_size (miphy_dev, phys, nphys),GFP_KERNEL );if (!miphy_dev)return -ENOMEM ; - miphy_dev->nphys =of_get_child_count (np); - miphy_dev->phys =devm_kcalloc (&pdev->dev, miphy_dev->nphys, -sizeof (*miphy_dev->phys),GFP_KERNEL ); -if (!miphy_dev->phys) -return -ENOMEM ; + miphy_dev->nphys = nphys; miphy_dev->regmap =syscon_regmap_lookup_by_phandle (np,"st,syscfg" );if (IS_ERR (miphy_dev->regmap)) { --
Quoted 2 lines
2.53.0
Thanks
Patrice
Quoted 11 lines · Rosen Penev
First patch allows compilation on at least x86.
Second uses a flexible array member to simplify allocation.
v2: add first patch and fix second.
Rosen Penev (2):
phy: miphy28lp: addCOMPILE_TEST
phy: miphy28lp: kzalloc + kcalloc to single kzalloc[...]
Applied, thanks!
[1/2] phy: miphy28lp: add COMPILE_TEST
commit: cc68a1728abfcbde12d36015f244046ae74ddd44
[2/2] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
commit: f3508a61c892c592e4e893a3681e568a5c671027Best regards,
Signature · 1 line
~Vinod