From: Rosen Penev <rosenp@gmail.com>
To: linux-usb@vger.kernel.org
Cc: Justin Chen <justin.chen@broadcom.com>,
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>,
linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] usb: bdc: allocate phys with main struct
Date: Fri, 10 Apr 2026 21:12:52 -0700 [thread overview]
Message-ID: <20260411041252.166816-1-rosenp@gmail.com> (raw)
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);
+
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);
--
2.53.0
reply other threads:[~2026-04-11 4:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260411041252.166816-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=alcooperx@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=justin.chen@broadcom.com \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.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