From: Justin Chen <justin.chen@broadcom.com>
To: Rosen Penev <rosenp@gmail.com>, linux-usb@vger.kernel.org
Cc: Al Cooper <alcooperx@gmail.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.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: bdc: allocate phys with main struct
Date: Mon, 13 Apr 2026 10:51:14 -0700 [thread overview]
Message-ID: <f8ea0484-6f6f-4426-aea6-fc45f566f692@broadcom.com> (raw)
In-Reply-To: <20260411041252.166816-1-rosenp@gmail.com>
On 4/10/26 9:12 PM, Rosen Penev wrote:
> Use a flexible array member to combine allocations and simplify code
> slightly. No need for a branch deciding whether to allocate or not.
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/usb/gadget/udc/bdc/bdc.h | 2 +-
> drivers/usb/gadget/udc/bdc/bdc_core.c | 20 +++++++-------------
> 2 files changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/bdc/bdc.h b/drivers/usb/gadget/udc/bdc/bdc.h
> index 2f4abf6f8f77..cc961161eb46 100644
> --- a/drivers/usb/gadget/udc/bdc/bdc.h
> +++ b/drivers/usb/gadget/udc/bdc/bdc.h
> @@ -409,7 +409,6 @@ struct bdc {
> spinlock_t lock;
>
> /* generic phy */
> - struct phy **phys;
> int num_phys;
> /* num of endpoints for a particular instantiation of IP */
> unsigned int num_eps;
> @@ -453,6 +452,7 @@ struct bdc {
> */
> struct delayed_work func_wake_notify;
> struct clk *clk;
> + struct phy *phys[] __counted_by(num_phys);
> };
>
> static inline u32 bdc_readl(void __iomem *base, u32 offset)
> diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c
> index 438201dc96ca..4b16b85da450 100644
> --- a/drivers/usb/gadget/udc/bdc/bdc_core.c
> +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c
> @@ -487,14 +487,20 @@ static int bdc_probe(struct platform_device *pdev)
> int irq;
> u32 temp;
> struct device *dev = &pdev->dev;
> + int num_phys;
> int phy_num;
>
> dev_dbg(dev, "%s()\n", __func__);
>
> - bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL);
> + num_phys = of_count_phandle_with_args(dev->of_node,
> + "phys", "#phy-cells");
> + bdc = devm_kzalloc(dev, struct_size(bdc, phys, num_phys), GFP_KERNEL);
> if (!bdc)
> return -ENOMEM;
>
> + bdc->num_phys = num_phys;
> + dev_info(dev, "Using %d phy(s)\n", bdc->num_phys);
> +
This feels like a step sideways instead of an improvement IMHO. And we
are also moving the allocation and dev_info() print. Is there a reason
to change the ordering?
Justin
> bdc->regs = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(bdc->regs))
> return PTR_ERR(bdc->regs);
> @@ -508,18 +514,6 @@ static int bdc_probe(struct platform_device *pdev)
> bdc->dev = dev;
> dev_dbg(dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq);
>
> - bdc->num_phys = of_count_phandle_with_args(dev->of_node,
> - "phys", "#phy-cells");
> - if (bdc->num_phys > 0) {
> - bdc->phys = devm_kcalloc(dev, bdc->num_phys,
> - sizeof(struct phy *), GFP_KERNEL);
> - if (!bdc->phys)
> - return -ENOMEM;
> - } else {
> - bdc->num_phys = 0;
> - }
> - dev_info(dev, "Using %d phy(s)\n", bdc->num_phys);
> -
> for (phy_num = 0; phy_num < bdc->num_phys; phy_num++) {
> bdc->phys[phy_num] = devm_of_phy_get_by_index(
> dev, dev->of_node, phy_num);
next prev parent reply other threads:[~2026-04-13 17:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 4:12 Rosen Penev
2026-04-13 17:51 ` Justin Chen [this message]
2026-04-13 19:20 ` Rosen Penev
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=f8ea0484-6f6f-4426-aea6-fc45f566f692@broadcom.com \
--to=justin.chen@broadcom.com \
--cc=alcooperx@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®