Skip to contentSkip to conversation

phy: miphy28lp: build and simplify allocation

PATCH Applied Rosen Penev 3 participants 6 messages Mar 6 – May 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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
index 304614b6dabf..49206185e563 100644
@@ -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

maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCHv2 1/2] phy: miphy28lp: add COMPILE_TEST

Quoted 23 lines · Rosen Penev

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 -2
index 304614b6dabf..49206185e563 100644
@@ -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

#3 lore raw

PATCH v2 2/2 phy: miphy28lp: kzalloc + kcalloc to single kzalloc

In reply to Rosen Penev

Use 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
index 43cef89af55e..c576fc5569fe 100644
@@ -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

maintainer Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCHv2 2/2] phy: miphy28lp: kzalloc + kcalloc to single kzalloc

Quoted 45 lines · Rosen Penev

Use 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 -8
index 43cef89af55e..c576fc5569fe 100644
@@ -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

maintainer Applied
#5 lore raw
In reply to Rosen Penev
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: add COMPILE_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: f3508a61c892c592e4e893a3681e568a5c671027

Best regards,

Signature · 1 line
~Vinod