From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Rosen Penev <rosenp@gmail.com>, linux-mediatek@lists.infradead.org
Cc: Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"open list:ARM/Mediatek SoC support"
<linux-kernel@vger.kernel.org>,
"moderated list:ARM/Mediatek SoC support"
<linux-arm-kernel@lists.infradead.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] soc: mediatek: mtk-dvfsrc: use flex array
Date: Fri, 6 Mar 2026 13:20:27 +0900 [thread overview]
Message-ID: <9dbf5b85-66ec-4d3f-99d6-17cc74a8f912@embeddedor.com> (raw)
In-Reply-To: <20260304232014.164408-1-rosenp@gmail.com>
On 3/5/26 08:20, Rosen Penev wrote:
> Simplifies allocation from kzalloc + kcaloc to one allocation.
>
> Allows extra runtime analysis with __counted_by.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/soc/mediatek/mtk-dvfsrc.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/soc/mediatek/mtk-dvfsrc.c b/drivers/soc/mediatek/mtk-dvfsrc.c
> index 548a28f50242..48b1fcf3e101 100644
> --- a/drivers/soc/mediatek/mtk-dvfsrc.c
> +++ b/drivers/soc/mediatek/mtk-dvfsrc.c
> @@ -71,8 +71,8 @@ struct dvfsrc_opp {
> };
>
> struct dvfsrc_opp_desc {
> - const struct dvfsrc_opp *opps;
> u32 num_opp;
> + struct dvfsrc_opp opps[] __counted_by(num_opp);
> };
>
> struct dvfsrc_soc_data;
> @@ -489,7 +489,6 @@ static u32 dvfsrc_get_opp_gear(struct mtk_dvfsrc *dvfsrc, u8 level)
>
> static int dvfsrc_get_hw_opps_v4(struct mtk_dvfsrc *dvfsrc)
> {
> - struct dvfsrc_opp *dvfsrc_opps;
> struct dvfsrc_opp_desc *desc;
> u32 num_opps, gear_info;
> u8 num_vcore, num_dram;
> @@ -520,24 +519,19 @@ static int dvfsrc_get_hw_opps_v4(struct mtk_dvfsrc *dvfsrc)
> num_opps, num_vcore, num_dram, num_emi);
>
> /* Allocate everything now as anything else after that cannot fail */
> - desc = devm_kzalloc(dvfsrc->dev, sizeof(*desc), GFP_KERNEL);
> + desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
Mmhh... You should really consider building your code before submitting any patches.
-Gustavo
> if (!desc)
> return -ENOMEM;
>
> - dvfsrc_opps = devm_kcalloc(dvfsrc->dev, num_opps + 1,
> - sizeof(*dvfsrc_opps), GFP_KERNEL);
> - if (!dvfsrc_opps)
> - return -ENOMEM;
> + desc->num_opp = num_opps + 1;
>
> /* Read the OPP table gear indices */
> for (i = 0; i <= num_opps; i++) {
> gear_info = dvfsrc_get_opp_gear(dvfsrc, num_opps - i);
> - dvfsrc_opps[i].vcore_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info);
> - dvfsrc_opps[i].dram_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info);
> - dvfsrc_opps[i].emi_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info);
> + desc->opps[i].vcore_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info);
> + desc->opps[i].dram_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info);
> + desc->opps[i].emi_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info);
> };
> - desc->num_opp = num_opps + 1;
> - desc->opps = dvfsrc_opps;
>
> /* Assign to main structure now that everything is done! */
> dvfsrc->curr_opps = desc;
next prev parent reply other threads:[~2026-03-06 19:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
2026-03-06 4:20 ` Gustavo A. R. Silva [this message]
2026-03-06 19:25 ` 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=9dbf5b85-66ec-4d3f-99d6-17cc74a8f912@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=angelogioacchino.delregno@collabora.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=matthias.bgg@gmail.com \
--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