From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
Thinh Nguyen <Thinh.Nguyen@synopsys.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: dwc3: qcom: allocate clks with main struct
Date: Thu, 16 Apr 2026 22:55:50 +0000 [thread overview]
Message-ID: <20260416225537.wrajd7riin6ynut5@synopsys.com> (raw)
In-Reply-To: <20260411034719.161736-1-rosenp@gmail.com>
On Fri, Apr 10, 2026, Rosen Penev wrote:
> 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
>
I don't see how this is better than before, especially when it's
deviating from the new dwc3-qcom logic. Please review the dwc3-qcom
instead before making changes to the legacy driver. I prefer new
development to be done in the new dwc3-qcom driver.
Thanks,
Thinh
prev parent reply other threads:[~2026-04-16 22:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-11 3:47 [PATCH] usb: dwc3: qcom: allocate clks with main struct Rosen Penev
2026-04-16 22:55 ` Thinh Nguyen [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=20260416225537.wrajd7riin6ynut5@synopsys.com \
--to=thinh.nguyen@synopsys.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