public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
@ 2026-03-04 23:20 Rosen Penev
  2026-03-05 17:13 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Rosen Penev @ 2026-03-04 23:20 UTC (permalink / raw)
  To: linux-mediatek
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Kees Cook,
	Gustavo A. R. Silva, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

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);
 	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;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
  2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
@ 2026-03-05 17:13 ` kernel test robot
  2026-03-05 17:57 ` kernel test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-03-05 17:13 UTC (permalink / raw)
  To: Rosen Penev, linux-mediatek

Hi Rosen,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kees/for-next/kspp]
[also build test WARNING on linus/master v7.0-rc2 next-20260305]
[cannot apply to kees/for-next/pstore]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/soc-mediatek-mtk-dvfsrc-use-flex-array/20260305-072355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/kspp
patch link:    https://lore.kernel.org/r/20260304232014.164408-1-rosenp%40gmail.com
patch subject: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20260306/202603060154.IZyLqpzw-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260306/202603060154.IZyLqpzw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603060154.IZyLqpzw-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/build_bug.h:5,
                    from include/linux/init.h:5,
                    from include/linux/arm-smccc.h:9,
                    from drivers/soc/mediatek/mtk-dvfsrc.c:8:
   drivers/soc/mediatek/mtk-dvfsrc.c: In function 'dvfsrc_get_hw_opps_v4':
   drivers/soc/mediatek/mtk-dvfsrc.c:522:66: error: 'num_ops' undeclared (first use in this function); did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
   include/linux/compiler.h:326:55: note: in definition of macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:66: note: each undeclared identifier is reported only once for each function it appears in
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
   include/linux/compiler.h:326:55: note: in definition of macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   In file included from include/linux/string.h:13,
                    from include/linux/uuid.h:11,
                    from include/linux/arm-smccc.h:12:
   include/linux/overflow.h:419:9: error: first argument to '__builtin_choose_expr' not a constant
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:436:32: note: in expansion of macro 'flex_array_size'
     436 |                 sizeof(*(p)) + flex_array_size(p, member, count),       \
         |                                ^~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   include/linux/overflow.h:419:9: error: first argument to '__builtin_choose_expr' not a constant
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:437:40: note: in expansion of macro 'flex_array_size'
     437 |                 size_add(sizeof(*(p)), flex_array_size(p, member, count)))
         |                                        ^~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   include/linux/overflow.h:435:9: error: first argument to '__builtin_choose_expr' not a constant
     435 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c: At top level:
   drivers/soc/mediatek/mtk-dvfsrc.c:726:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:726:25: note: (near initialization for 'dvfsrc_opp_mt6893_desc[0].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:727:17: error: initialization of flexible array member in a nested context
     727 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt6893_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:727:17: note: (near initialization for 'dvfsrc_opp_mt6893_desc[0].opps')
>> drivers/soc/mediatek/mtk-dvfsrc.c:724:64: warning: missing braces around initializer [-Wmissing-braces]
     724 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt6893_desc[] = {
         |                                                                ^
     725 |         [0] = {
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         {{                   }}
>> drivers/soc/mediatek/mtk-dvfsrc.c:724:64: warning: missing braces around initializer [-Wmissing-braces]
     724 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt6893_desc[] = {
         |                                                                ^
     725 |         [0] = {
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:759:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:759:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[0].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:760:17: error: initialization of flexible array member in a nested context
     760 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:760:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[0].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:763:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:763:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[1].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:764:17: error: initialization of flexible array member in a nested context
     764 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp3),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:764:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[1].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:767:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:767:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[2].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:768:17: error: initialization of flexible array member in a nested context
     768 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp3),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:768:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[2].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   ......
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   ......
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:799:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:799:25: note: (near initialization for 'dvfsrc_opp_mt8195_desc[0].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:800:17: error: initialization of flexible array member in a nested context
     800 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8195_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:800:17: note: (near initialization for 'dvfsrc_opp_mt8195_desc[0].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:797:64: warning: missing braces around initializer [-Wmissing-braces]
     797 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8195_desc[] = {
         |                                                                ^
     798 |         [0] = {
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:797:64: warning: missing braces around initializer [-Wmissing-braces]
     797 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8195_desc[] = {
         |                                                                ^
     798 |         [0] = {
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         {{                   }}


vim +724 drivers/soc/mediatek/mtk-dvfsrc.c

e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  723  
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10 @724  static const struct dvfsrc_opp_desc dvfsrc_opp_mt6893_desc[] = {
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  725  	[0] = {
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  726  		.opps = dvfsrc_opp_mt6893_lp4,
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  727  		.num_opp = ARRAY_SIZE(dvfsrc_opp_mt6893_lp4),
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  728  	}
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  729  };
e5ea18102c9d3b AngeloGioacchino Del Regno 2025-04-10  730  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
  2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
  2026-03-05 17:13 ` kernel test robot
@ 2026-03-05 17:57 ` kernel test robot
  2026-03-06  4:20 ` Gustavo A. R. Silva
  2026-03-06  4:45 ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-03-05 17:57 UTC (permalink / raw)
  To: Rosen Penev, linux-mediatek

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on kees/for-next/kspp]
[also build test ERROR on linus/master v7.0-rc2 next-20260305]
[cannot apply to kees/for-next/pstore]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/soc-mediatek-mtk-dvfsrc-use-flex-array/20260305-072355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/kspp
patch link:    https://lore.kernel.org/r/20260304232014.164408-1-rosenp%40gmail.com
patch subject: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20260306/202603060141.sYb2R56a-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260306/202603060141.sYb2R56a-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603060141.sYb2R56a-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:435:39: note: expanded from macro 'struct_size'
     435 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |                                              ^
   include/linux/compiler.h:326:48: note: expanded from macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:436:45: note: expanded from macro 'struct_size'
     436 |                 sizeof(*(p)) + flex_array_size(p, member, count),       \
         |                                                           ^
   include/linux/overflow.h:419:39: note: expanded from macro 'flex_array_size'
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |                                              ^
   include/linux/compiler.h:326:48: note: expanded from macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:436:45: note: expanded from macro 'struct_size'
     436 |                 sizeof(*(p)) + flex_array_size(p, member, count),       \
         |                                                           ^
   include/linux/overflow.h:420:4: note: expanded from macro 'flex_array_size'
     420 |                 (count) * sizeof(*(p)->member) + __must_be_array((p)->member),  \
         |                  ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:437:53: note: expanded from macro 'struct_size'
     437 |                 size_add(sizeof(*(p)), flex_array_size(p, member, count)))
         |                                                                   ^
   include/linux/overflow.h:419:39: note: expanded from macro 'flex_array_size'
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |                                              ^
   include/linux/compiler.h:326:48: note: expanded from macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:437:53: note: expanded from macro 'struct_size'
     437 |                 size_add(sizeof(*(p)), flex_array_size(p, member, count)))
         |                                                                   ^
   include/linux/overflow.h:420:4: note: expanded from macro 'flex_array_size'
     420 |                 (count) * sizeof(*(p)->member) + __must_be_array((p)->member),  \
         |                  ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:436:45: note: expanded from macro 'struct_size'
     436 |                 sizeof(*(p)) + flex_array_size(p, member, count),       \
         |                                                           ^
   include/linux/overflow.h:421:12: note: expanded from macro 'flex_array_size'
     421 |                 size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member)))
         |                          ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:59: error: use of undeclared identifier 'num_ops'; did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
         |                                                                  num_opps
   include/linux/overflow.h:437:53: note: expanded from macro 'struct_size'
     437 |                 size_add(sizeof(*(p)), flex_array_size(p, member, count)))
         |                                                                   ^
   include/linux/overflow.h:421:12: note: expanded from macro 'flex_array_size'
     421 |                 size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member)))
         |                          ^
   drivers/soc/mediatek/mtk-dvfsrc.c:493:6: note: 'num_opps' declared here
     493 |         u32 num_opps, gear_info;
         |             ^
>> drivers/soc/mediatek/mtk-dvfsrc.c:726:11: error: flexible array requires brace-enclosed initializer
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:75:20: note: initialized flexible array member 'opps' is here
      75 |         struct dvfsrc_opp opps[] __counted_by(num_opp);
         |                           ^
   drivers/soc/mediatek/mtk-dvfsrc.c:759:11: error: flexible array requires brace-enclosed initializer
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:75:20: note: initialized flexible array member 'opps' is here
      75 |         struct dvfsrc_opp opps[] __counted_by(num_opp);
         |                           ^
   drivers/soc/mediatek/mtk-dvfsrc.c:763:11: error: flexible array requires brace-enclosed initializer
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:75:20: note: initialized flexible array member 'opps' is here
      75 |         struct dvfsrc_opp opps[] __counted_by(num_opp);
         |                           ^
   drivers/soc/mediatek/mtk-dvfsrc.c:767:11: error: flexible array requires brace-enclosed initializer
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:75:20: note: initialized flexible array member 'opps' is here
      75 |         struct dvfsrc_opp opps[] __counted_by(num_opp);
         |                           ^
   drivers/soc/mediatek/mtk-dvfsrc.c:799:11: error: flexible array requires brace-enclosed initializer
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:75:20: note: initialized flexible array member 'opps' is here
      75 |         struct dvfsrc_opp opps[] __counted_by(num_opp);
         |                           ^
   12 errors generated.


vim +522 drivers/soc/mediatek/mtk-dvfsrc.c

   489	
   490	static int dvfsrc_get_hw_opps_v4(struct mtk_dvfsrc *dvfsrc)
   491	{
   492		struct dvfsrc_opp_desc *desc;
   493		u32 num_opps, gear_info;
   494		u8 num_vcore, num_dram;
   495		u8 num_emi;
   496		int i;
   497	
   498		num_opps = dvfsrc_get_opp_count_v4(dvfsrc);
   499		if (num_opps == 0) {
   500			dev_err(dvfsrc->dev, "No OPPs programmed in DVFSRC MCU.\n");
   501			return -EINVAL;
   502		}
   503	
   504		/*
   505		 * The first 16 bits set in the gear info table says how many OPPs
   506		 * and how many vcore, dram and emi table entries are available.
   507		 */
   508		gear_info = dvfsrc_readl(dvfsrc, DVFSRC_GEAR_INFO_L);
   509		if (gear_info == 0) {
   510			dev_err(dvfsrc->dev, "No gear info in DVFSRC MCU.\n");
   511			return -EINVAL;
   512		}
   513	
   514		num_vcore = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info) + 1;
   515		num_dram = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info) + 1;
   516		num_emi = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info) + 1;
   517		dev_info(dvfsrc->dev,
   518			 "Discovered %u gears and %u vcore, %u dram, %u emi table entries.\n",
   519			 num_opps, num_vcore, num_dram, num_emi);
   520	
   521		/* Allocate everything now as anything else after that cannot fail */
 > 522		desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
   523		if (!desc)
   524			return -ENOMEM;
   525	
   526		desc->num_opp = num_opps + 1;
   527	
   528		/* Read the OPP table gear indices */
   529		for (i = 0; i <= num_opps; i++) {
   530			gear_info = dvfsrc_get_opp_gear(dvfsrc, num_opps - i);
   531			desc->opps[i].vcore_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info);
   532			desc->opps[i].dram_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info);
   533			desc->opps[i].emi_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info);
   534		};
   535	
   536		/* Assign to main structure now that everything is done! */
   537		dvfsrc->curr_opps = desc;
   538	
   539		return 0;
   540	}
   541	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
  2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
  2026-03-05 17:13 ` kernel test robot
  2026-03-05 17:57 ` kernel test robot
@ 2026-03-06  4:20 ` Gustavo A. R. Silva
  2026-03-06 19:25   ` Rosen Penev
  2026-03-06  4:45 ` kernel test robot
  3 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-06  4:20 UTC (permalink / raw)
  To: Rosen Penev, linux-mediatek
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Kees Cook,
	Gustavo A. R. Silva, open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b



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;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
  2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
                   ` (2 preceding siblings ...)
  2026-03-06  4:20 ` Gustavo A. R. Silva
@ 2026-03-06  4:45 ` kernel test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-03-06  4:45 UTC (permalink / raw)
  To: Rosen Penev, linux-mediatek

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on kees/for-next/kspp]
[also build test ERROR on linus/master v7.0-rc2 next-20260305]
[cannot apply to kees/for-next/pstore]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/soc-mediatek-mtk-dvfsrc-use-flex-array/20260305-072355
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/kspp
patch link:    https://lore.kernel.org/r/20260304232014.164408-1-rosenp%40gmail.com
patch subject: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20260306/202603061220.aCSWpwU6-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260306/202603061220.aCSWpwU6-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603061220.aCSWpwU6-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/build_bug.h:5,
                    from include/linux/init.h:5,
                    from include/linux/arm-smccc.h:9,
                    from drivers/soc/mediatek/mtk-dvfsrc.c:8:
   drivers/soc/mediatek/mtk-dvfsrc.c: In function 'dvfsrc_get_hw_opps_v4':
>> drivers/soc/mediatek/mtk-dvfsrc.c:522:66: error: 'num_ops' undeclared (first use in this function); did you mean 'num_opps'?
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
   include/linux/compiler.h:326:55: note: in definition of macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:66: note: each undeclared identifier is reported only once for each function it appears in
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                                                  ^~~~~~~
   include/linux/compiler.h:326:55: note: in definition of macro '__is_constexpr'
     326 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   In file included from include/linux/string.h:13,
                    from include/linux/uuid.h:11,
                    from include/linux/arm-smccc.h:12:
>> include/linux/overflow.h:419:9: error: first argument to '__builtin_choose_expr' not a constant
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:436:32: note: in expansion of macro 'flex_array_size'
     436 |                 sizeof(*(p)) + flex_array_size(p, member, count),       \
         |                                ^~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
>> include/linux/overflow.h:419:9: error: first argument to '__builtin_choose_expr' not a constant
     419 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/linux/overflow.h:437:40: note: in expansion of macro 'flex_array_size'
     437 |                 size_add(sizeof(*(p)), flex_array_size(p, member, count)))
         |                                        ^~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   include/linux/overflow.h:435:9: error: first argument to '__builtin_choose_expr' not a constant
     435 |         __builtin_choose_expr(__is_constexpr(count),                    \
         |         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:522:42: note: in expansion of macro 'struct_size'
     522 |         desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
         |                                          ^~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c: At top level:
>> drivers/soc/mediatek/mtk-dvfsrc.c:726:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:726:25: note: (near initialization for 'dvfsrc_opp_mt6893_desc[0].opps[0].vcore_opp')
>> drivers/soc/mediatek/mtk-dvfsrc.c:727:17: error: initialization of flexible array member in a nested context
     727 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt6893_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:727:17: note: (near initialization for 'dvfsrc_opp_mt6893_desc[0].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:724:64: warning: missing braces around initializer [-Wmissing-braces]
     724 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt6893_desc[] = {
         |                                                                ^
     725 |         [0] = {
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:724:64: warning: missing braces around initializer [-Wmissing-braces]
     724 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt6893_desc[] = {
         |                                                                ^
     725 |         [0] = {
     726 |                 .opps = dvfsrc_opp_mt6893_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:759:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:759:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[0].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:760:17: error: initialization of flexible array member in a nested context
     760 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:760:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[0].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:763:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:763:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[1].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:764:17: error: initialization of flexible array member in a nested context
     764 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp3),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:764:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[1].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:767:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:767:25: note: (near initialization for 'dvfsrc_opp_mt8183_desc[2].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:768:17: error: initialization of flexible array member in a nested context
     768 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8183_lp3),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:768:17: note: (near initialization for 'dvfsrc_opp_mt8183_desc[2].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   ......
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:757:64: warning: missing braces around initializer [-Wmissing-braces]
     757 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8183_desc[] = {
         |                                                                ^
     758 |         [0] = {
     759 |                 .opps = dvfsrc_opp_mt8183_lp4,
         |                         {{                   }}
   ......
     763 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   ......
     767 |                 .opps = dvfsrc_opp_mt8183_lp3,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:799:25: error: initialization of 'unsigned int' from 'const struct dvfsrc_opp *' makes integer from pointer without a cast [-Wint-conversion]
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         ^~~~~~~~~~~~~~~~~~~~~
   drivers/soc/mediatek/mtk-dvfsrc.c:799:25: note: (near initialization for 'dvfsrc_opp_mt8195_desc[0].opps[0].vcore_opp')
   drivers/soc/mediatek/mtk-dvfsrc.c:800:17: error: initialization of flexible array member in a nested context
     800 |                 .num_opp = ARRAY_SIZE(dvfsrc_opp_mt8195_lp4),
         |                 ^
   drivers/soc/mediatek/mtk-dvfsrc.c:800:17: note: (near initialization for 'dvfsrc_opp_mt8195_desc[0].opps')
   drivers/soc/mediatek/mtk-dvfsrc.c:797:64: warning: missing braces around initializer [-Wmissing-braces]
     797 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8195_desc[] = {
         |                                                                ^
     798 |         [0] = {
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         {{                   }}
   drivers/soc/mediatek/mtk-dvfsrc.c:797:64: warning: missing braces around initializer [-Wmissing-braces]
     797 | static const struct dvfsrc_opp_desc dvfsrc_opp_mt8195_desc[] = {
         |                                                                ^
     798 |         [0] = {
     799 |                 .opps = dvfsrc_opp_mt8195_lp4,
         |                         {{                   }}


vim +522 drivers/soc/mediatek/mtk-dvfsrc.c

   489	
   490	static int dvfsrc_get_hw_opps_v4(struct mtk_dvfsrc *dvfsrc)
   491	{
   492		struct dvfsrc_opp_desc *desc;
   493		u32 num_opps, gear_info;
   494		u8 num_vcore, num_dram;
   495		u8 num_emi;
   496		int i;
   497	
   498		num_opps = dvfsrc_get_opp_count_v4(dvfsrc);
   499		if (num_opps == 0) {
   500			dev_err(dvfsrc->dev, "No OPPs programmed in DVFSRC MCU.\n");
   501			return -EINVAL;
   502		}
   503	
   504		/*
   505		 * The first 16 bits set in the gear info table says how many OPPs
   506		 * and how many vcore, dram and emi table entries are available.
   507		 */
   508		gear_info = dvfsrc_readl(dvfsrc, DVFSRC_GEAR_INFO_L);
   509		if (gear_info == 0) {
   510			dev_err(dvfsrc->dev, "No gear info in DVFSRC MCU.\n");
   511			return -EINVAL;
   512		}
   513	
   514		num_vcore = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info) + 1;
   515		num_dram = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info) + 1;
   516		num_emi = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info) + 1;
   517		dev_info(dvfsrc->dev,
   518			 "Discovered %u gears and %u vcore, %u dram, %u emi table entries.\n",
   519			 num_opps, num_vcore, num_dram, num_emi);
   520	
   521		/* Allocate everything now as anything else after that cannot fail */
 > 522		desc = devm_kzalloc(dvfsrc->dev, struct_size(desc, opps, num_ops + 1), GFP_KERNEL);
   523		if (!desc)
   524			return -ENOMEM;
   525	
   526		desc->num_opp = num_opps + 1;
   527	
   528		/* Read the OPP table gear indices */
   529		for (i = 0; i <= num_opps; i++) {
   530			gear_info = dvfsrc_get_opp_gear(dvfsrc, num_opps - i);
   531			desc->opps[i].vcore_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_VCORE, gear_info);
   532			desc->opps[i].dram_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_DRAM, gear_info);
   533			desc->opps[i].emi_opp = FIELD_GET(DVFSRC_V4_GEAR_INFO_EMI, gear_info);
   534		};
   535	
   536		/* Assign to main structure now that everything is done! */
   537		dvfsrc->curr_opps = desc;
   538	
   539		return 0;
   540	}
   541	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: mediatek: mtk-dvfsrc: use flex array
  2026-03-06  4:20 ` Gustavo A. R. Silva
@ 2026-03-06 19:25   ` Rosen Penev
  0 siblings, 0 replies; 6+ messages in thread
From: Rosen Penev @ 2026-03-06 19:25 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: linux-mediatek, Matthias Brugger, AngeloGioacchino Del Regno,
	Kees Cook, Gustavo A. R. Silva,
	open list:ARM/Mediatek SoC support,
	moderated list:ARM/Mediatek SoC support,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

On Fri, Mar 6, 2026 at 11:21 AM Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
>
>
>
> 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.
This one specifically I failed at the make parameters.

This patch should be rescinded. Not correct.
>
> -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;
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-06 19:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 23:20 [PATCH] soc: mediatek: mtk-dvfsrc: use flex array Rosen Penev
2026-03-05 17:13 ` kernel test robot
2026-03-05 17:57 ` kernel test robot
2026-03-06  4:20 ` Gustavo A. R. Silva
2026-03-06 19:25   ` Rosen Penev
2026-03-06  4:45 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox