mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@foss.st.com>
To: Rosen Penev <rosenp@gmail.com>, <linux-phy@lists.infradead.org>
Cc: Vinod Koul <vkoul@kernel.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"moderated list:ARM/STI ARCHITECTURE"
	<linux-arm-kernel@lists.infradead.org>,
	"open list:KERNEL HARDENING (not covered by other
	areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCHv2 2/2] phy: miphy28lp: kzalloc + kcalloc to single kzalloc
Date: Mon, 9 Mar 2026 08:00:01 +0100	[thread overview]
Message-ID: <bd4c6cab-bc1f-4275-87aa-2e0daf0e5620@foss.st.com> (raw)
In-Reply-To: <20260306222457.8400-3-rosenp@gmail.com>



On 3/6/26 23:24, 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..c576fc5569fe 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(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
> 
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

  reply	other threads:[~2026-03-09  7:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06 22:24 [PATCHv2 0/2] phy: miphy28lp: build and simplify allocation Rosen Penev
2026-03-06 22:24 ` [PATCHv2 1/2] phy: miphy28lp: add COMPILE_TEST Rosen Penev
2026-03-09  6:49   ` Patrice CHOTARD
2026-03-06 22:24 ` [PATCHv2 2/2] phy: miphy28lp: kzalloc + kcalloc to single kzalloc Rosen Penev
2026-03-09  7:00   ` Patrice CHOTARD [this message]
2026-05-10 12:32 ` [PATCHv2 0/2] phy: miphy28lp: build and simplify allocation Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd4c6cab-bc1f-4275-87aa-2e0daf0e5620@foss.st.com \
    --to=patrice.chotard@foss.st.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rosenp@gmail.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®