The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-usb@vger.kernel.org,
	Chunfeng Yun <chunfeng.yun@mediatek.com>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"moderated list:MEDIATEK USB3 DRD IP DRIVER"
	<linux-arm-kernel@lists.infradead.org>,
	"moderated list:MEDIATEK USB3 DRD IP DRIVER"
	<linux-mediatek@lists.infradead.org>,
	open list <linux-kernel@vger.kernel.org>,
	"open list:KERNEL HARDENING (not covered by other
	areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] usb: mtu3: allocate phys with ssusb
Date: Fri, 3 Jul 2026 11:45:05 +0200	[thread overview]
Message-ID: <2026070330-darkroom-taking-3687@gregkh> (raw)
In-Reply-To: <20260411035731.163580-1-rosenp@gmail.com>

On Fri, Apr 10, 2026 at 08:57:31PM -0700, Rosen Penev wrote:
> Use a flexible array member to combine allocations. Allows removal of a
> pointless branch. A size of 0 means phys are not allocated.
> 
> Add __counted_by for extra runtime analysis.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/usb/mtu3/mtu3.h      |  2 +-
>  drivers/usb/mtu3/mtu3_plat.c | 18 ++++++------------
>  2 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
> index ba5a63669e5f..d71849388602 100644
> --- a/drivers/usb/mtu3/mtu3.h
> +++ b/drivers/usb/mtu3/mtu3.h
> @@ -252,7 +252,6 @@ struct ssusb_mtk {
>  	struct mtu3 *u3d;
>  	void __iomem *mac_base;
>  	void __iomem *ippc_base;
> -	struct phy **phys;
>  	int num_phys;
>  	int wakeup_irq;
>  	/* common power & clock */
> @@ -272,6 +271,7 @@ struct ssusb_mtk {
>  	struct regmap *uwk;
>  	u32 uwk_reg_base;
>  	u32 uwk_vers;
> +	struct phy *phys[] __counted_by(num_phys);
>  };
>  
>  /**
> diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
> index cc8a864dbd63..11a919fc3d47 100644
> --- a/drivers/usb/mtu3/mtu3_plat.c
> +++ b/drivers/usb/mtu3/mtu3_plat.c
> @@ -240,17 +240,6 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb)
>  	if (ret)
>  		return ret;
>  
> -	ssusb->num_phys = of_count_phandle_with_args(node,
> -			"phys", "#phy-cells");
> -	if (ssusb->num_phys > 0) {
> -		ssusb->phys = devm_kcalloc(dev, ssusb->num_phys,
> -					sizeof(*ssusb->phys), GFP_KERNEL);
> -		if (!ssusb->phys)
> -			return -ENOMEM;
> -	} else {
> -		ssusb->num_phys = 0;
> -	}
> -
>  	for (i = 0; i < ssusb->num_phys; i++) {
>  		ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i);
>  		if (IS_ERR(ssusb->phys[i])) {
> @@ -330,12 +319,17 @@ static int mtu3_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct ssusb_mtk *ssusb;
>  	int ret = -ENOMEM;
> +	int num_phys;
>  
> +	num_phys = of_count_phandle_with_args(dev->of_node,
> +			"phys", "#phy-cells");

You just caused a bug here if this returns a negative value.

How was this tested?

And why is it even needed?

thanks,

greg k-h

      reply	other threads:[~2026-07-03  9:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-11  3:57 [PATCH] usb: mtu3: allocate phys with ssusb Rosen Penev
2026-07-03  9:45 ` Greg Kroah-Hartman [this message]

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=2026070330-darkroom-taking-3687@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=chunfeng.yun@mediatek.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-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rosenp@gmail.com \
    /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