public inbox for linux-phy@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
@ 2026-03-04 23:28 Rosen Penev
  2026-03-06  4:27 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-03-04 23:28 UTC (permalink / raw)
  To: linux-phy
  Cc: Patrice Chotard, Vinod Koul, Neil Armstrong, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/STI ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Use flex array to simplify allocation.

Allows using __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/phy/st/phy-miphy28lp.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
index 43cef89af55e..fd931ede7162 100644
--- a/drivers/phy/st/phy-miphy28lp.c
+++ b/drivers/phy/st/phy-miphy28lp.c
@@ -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(wiphy_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


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
  2026-03-04 23:28 [PATCH] phy: miphy28lp: kzalloc + kcalloc to single kzalloc Rosen Penev
@ 2026-03-06  4:27 ` Gustavo A. R. Silva
  2026-03-06 19:36   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-06  4:27 UTC (permalink / raw)
  To: Rosen Penev, linux-phy
  Cc: Patrice Chotard, Vinod Koul, Neil Armstrong, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/STI ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b



On 3/5/26 08:28, Rosen Penev wrote:
> Use flex array to simplify allocation.
> 
> Allows using __counted_by for extra runtime analysis.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   drivers/phy/st/phy-miphy28lp.c | 12 +++++-------
>   1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
> index 43cef89af55e..fd931ede7162 100644
> --- a/drivers/phy/st/phy-miphy28lp.c
> +++ b/drivers/phy/st/phy-miphy28lp.c
> @@ -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(wiphy_dev, phys, nphys) ,TGFP_KERNEL);

This is bad... it looks like you didn't build any of these patches.

-Gustavo

>   	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)) {


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
  2026-03-06  4:27 ` Gustavo A. R. Silva
@ 2026-03-06 19:36   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2026-03-06 19:36 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: linux-phy, Patrice Chotard, Vinod Koul, Neil Armstrong, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/STI ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

On Fri, Mar 6, 2026 at 11:28 AM Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
>
>
>
> On 3/5/26 08:28, Rosen Penev wrote:
> > Use flex array to simplify allocation.
> >
> > Allows using __counted_by for extra runtime analysis.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >   drivers/phy/st/phy-miphy28lp.c | 12 +++++-------
> >   1 file changed, 5 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/phy/st/phy-miphy28lp.c b/drivers/phy/st/phy-miphy28lp.c
> > index 43cef89af55e..fd931ede7162 100644
> > --- a/drivers/phy/st/phy-miphy28lp.c
> > +++ b/drivers/phy/st/phy-miphy28lp.c
> > @@ -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(wiphy_dev, phys, nphys) ,TGFP_KERNEL);
>
> This is bad... it looks like you didn't build any of these patches.
Missing COMPILE_TEST on this driver. Will fix.
>
> -Gustavo
>
> >       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)) {
>

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-06 19:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 23:28 [PATCH] phy: miphy28lp: kzalloc + kcalloc to single kzalloc Rosen Penev
2026-03-06  4:27 ` Gustavo A. R. Silva
2026-03-06 19:36   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox