* [PATCH] usb: dwc3: qcom: allocate clks with main struct
@ 2026-04-11 3:47 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-04-11 3:47 UTC (permalink / raw)
To: linux-usb
Cc: Thinh Nguyen, Greg Kroah-Hartman, Kees Cook, Gustavo A. R. Silva,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
Use a flexible array member to combine allocations.
Add __counted_by for extra runtime analysis.
Change dwc3_qcom_clk_init to a single parameter. No need to pass count
separately now.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/usb/dwc3/dwc3-qcom-legacy.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-qcom-legacy.c b/drivers/usb/dwc3/dwc3-qcom-legacy.c
index d3fad0fcfdac..565d03eb01b8 100644
--- a/drivers/usb/dwc3/dwc3-qcom-legacy.c
+++ b/drivers/usb/dwc3/dwc3-qcom-legacy.c
@@ -74,7 +74,6 @@ struct dwc3_qcom {
struct device *dev;
void __iomem *qscratch_base;
struct platform_device *dwc3;
- struct clk **clks;
int num_clocks;
struct reset_control *resets;
struct dwc3_qcom_port ports[DWC3_QCOM_MAX_PORTS];
@@ -90,6 +89,7 @@ struct dwc3_qcom {
bool pm_suspended;
struct icc_path *icc_path_ddr;
struct icc_path *icc_path_apps;
+ struct clk *clks[] __counted_by(num_clocks);
};
static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
@@ -653,10 +653,11 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev)
return 0;
}
-static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
+static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom)
{
struct device *dev = qcom->dev;
struct device_node *np = dev->of_node;
+ int count = qcom->num_clocks;
int i;
if (!np || !count)
@@ -665,13 +666,6 @@ static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
if (count < 0)
return count;
- qcom->num_clocks = count;
-
- qcom->clks = devm_kcalloc(dev, qcom->num_clocks,
- sizeof(struct clk *), GFP_KERNEL);
- if (!qcom->clks)
- return -ENOMEM;
-
for (i = 0; i < qcom->num_clocks; i++) {
struct clk *clk;
int ret;
@@ -736,13 +730,18 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct dwc3_qcom *qcom;
int ret, i;
+ int num_clocks;
bool ignore_pipe_clk;
bool wakeup_source;
- qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
+ num_clocks = of_clk_get_parent_count(np);
+ qcom = devm_kzalloc(&pdev->dev, struct_size(qcom, clks, num_clocks),
+ GFP_KERNEL);
if (!qcom)
return -ENOMEM;
+ qcom->num_clocks = num_clocks;
+
platform_set_drvdata(pdev, qcom);
qcom->dev = &pdev->dev;
@@ -766,7 +765,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
goto reset_assert;
}
- ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
+ ret = dwc3_qcom_clk_init(qcom);
if (ret) {
dev_err_probe(dev, ret, "failed to get clocks\n");
goto reset_assert;
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-11 3:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-11 3:47 [PATCH] usb: dwc3: qcom: allocate clks with main struct Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox