linux_dsm_epyc7002/drivers/gpu/drm/amd/powerplay/hwmgr
Kees Cook 6396bb2215 treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

        kzalloc(a * b, gfp)

with:
        kcalloc(a * b, gfp)

as well as handling cases of:

        kzalloc(a * b * c, gfp)

with:

        kzalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kzalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kzalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kzalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kzalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kzalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kzalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kzalloc
+ kcalloc
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kzalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kzalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kzalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kzalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kzalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kzalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kzalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kzalloc(sizeof(THING) * C2, ...)
|
  kzalloc(sizeof(TYPE) * C2, ...)
|
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
hardwaremanager.c drm/amd/powerplay: add a framework for perfroming pre display 2018-05-17 08:54:23 -05:00
hwmgr_ppt.h drm/amd/powerplay: add some new structures for Vega10 2017-03-29 23:54:52 -04:00
hwmgr.c drm/amdgpu/powerplay: Add initial vega20 support v2 2018-05-17 10:13:11 -05:00
Makefile drm/amd/pp: Remove Dead functions on Vega12 2018-04-03 12:52:57 -05:00
pp_overdriver.c drm/amdgpu: add license to files where it was missing 2017-12-07 11:51:25 -05:00
pp_overdriver.h drm/amd/powerplay: Fix missing newlines at end of file 2017-12-06 12:47:59 -05:00
pp_psm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
pp_psm.h drm/amd/powerplay: Fix psm_set_user_performance_state() 2017-09-12 14:23:18 -04:00
ppatomctrl.c drm/amd/pp: Fix static checker warning 2018-05-24 00:15:13 -05:00
ppatomctrl.h drm/amd/powerplay: update ppatomctrl.c (v2) 2018-05-15 13:44:03 -05:00
ppatomfwctrl.c drm/amd/pp: Refine pp_atomfwctrl_get_vbios_bootup_values 2018-05-15 13:43:03 -05:00
ppatomfwctrl.h drm/amd/pp: Refine pp_atomfwctrl_get_vbios_bootup_values 2018-05-15 13:43:03 -05:00
ppevvmath.h drm/amd/powerplay: Delete unused functions in ppevvmath.h 2016-07-29 14:36:56 -04:00
pppcielanes.c drm/amd/powerplay: add Tonga dpm support (v3) 2015-12-21 16:42:15 -05:00
pppcielanes.h drm/amd/powerplay: add Tonga dpm support (v3) 2015-12-21 16:42:15 -05:00
pptable_v1_0.h drm/amd/powerplay: rename tonga_processpptable* to processpptable_v1_0*. 2016-09-16 15:52:49 -04:00
process_pptables_v1_0.c drm/amd/powerplay: update process pptables 2018-05-15 13:44:04 -05:00
process_pptables_v1_0.h drm/amd/powerplay: rename tonga_processpptable* to processpptable_v1_0*. 2016-09-16 15:52:49 -04:00
processpptables.c drm/amd/pp: Use atombios api directly in powerplay (v2) 2018-04-11 13:07:51 -05:00
processpptables.h drm/amd/powerplay: add pp_tables_get_response_times function in process pptables 2016-07-15 12:34:03 -04:00
smu7_clockpowergating.c drm/amdgpu: remove duplicate cg/pg wrapper functions 2018-04-11 13:07:53 -05:00
smu7_clockpowergating.h drm/amd/pp: Remove dead header file pp_asicblocks.h 2018-03-15 09:58:16 -05:00
smu7_dyn_defaults.h drm/amd/pp: Change activity_target for performance optimization on Polaris 2018-02-19 14:18:46 -05:00
smu7_hwmgr.c drm/amd/pp: Fix static checker warning 2018-05-24 00:15:13 -05:00
smu7_hwmgr.h drm/amd/pp: Refine the output of pp_power_profile_mode on VI 2018-05-15 13:44:21 -05:00
smu7_powertune.c drm/amd/pp: fix a couple locking issues 2018-05-24 00:15:37 -05:00
smu7_powertune.h drm/amd/powerplay: implement smu7 hwmgr to manager asics with smu ip version 7. 2016-09-19 13:22:10 -04:00
smu7_thermal.c drm/amd/pp: Fix set wrong temperature range on smu7 2018-03-22 14:43:01 -05:00
smu7_thermal.h drm/amd/powerplay: refine code for thermal control in powerplay 2017-09-18 23:30:31 -04:00
smu8_hwmgr.c drm/amdgpu: remove duplicate cg/pg wrapper functions 2018-04-11 13:07:53 -05:00
smu8_hwmgr.h drm/amd/pp: Rename file name cz_* to smu8_* 2018-03-15 09:58:56 -05:00
smu10_hwmgr.c drm/amd/pp: Add smu support for VCN powergating on RV 2018-05-24 00:15:52 -05:00
smu10_hwmgr.h drm/amd/pp: Use dynamic gfx_clk rather than hardcoded values 2018-05-15 13:43:47 -05:00
smu10_inc.h drm/amd/pp: Replace rv_* with smu10_* 2018-03-15 09:57:12 -05:00
smu_helper.c drm/amd/pp: Fix NULL point check error in smu_set_watermarks_for_clocks_ranges 2018-05-15 13:43:33 -05:00
smu_helper.h drm/amd/pp: Move common code to smu_helper.c 2018-05-15 13:43:19 -05:00
vega10_hwmgr.c drm/amd/powerplay: fix spelling mistake: "contruct" -> "construct" 2018-05-15 13:44:21 -05:00
vega10_hwmgr.h drm/amd/pp: Add OVERDRIVE support on Vega10 (v2) 2018-05-15 13:43:52 -05:00
vega10_inc.h drm/amd/include:cleanup vega10 nbio header files. 2017-12-06 12:48:21 -05:00
vega10_powertune.c drm/amd/pp: use soc15 common macros instead of vega10 specific 2018-05-15 13:43:04 -05:00
vega10_powertune.h drm/amd/powerplay: added didt support for vega10 2017-07-14 11:06:26 -04:00
vega10_pptable.h drm/amd/powerplay: add support for ATOM GFXCLK table v2. 2017-06-29 12:43:44 -04:00
vega10_processpptables.c drm/amd/pp: Use atombios api directly in powerplay (v2) 2018-04-11 13:07:51 -05:00
vega10_processpptables.h drm/amd/powerplay: port newest process pptable code for vega10. 2017-04-07 15:15:43 -04:00
vega10_thermal.c drm/amd/pp: use soc15 common macros instead of vega10 specific 2018-05-15 13:43:04 -05:00
vega10_thermal.h drm/amd/pp: Delete get_xclk function in powerplay (v2) 2018-03-19 13:38:31 -05:00
vega12_hwmgr.c drm/amd/pp: Remove struct pp_gpu_power 2018-05-15 13:43:18 -05:00
vega12_hwmgr.h drm/amd/powerplay: Get more than 8 level gfxclk states 2018-05-15 13:43:09 -05:00
vega12_inc.h drm/amd/powerplay: add vega12_inc.h 2018-03-21 14:36:53 -05:00
vega12_pptable.h drm/amd/powerplay: add vega12_pptable.h 2018-03-21 14:36:55 -05:00
vega12_processpptables.c drm/amd/powerplay: add registry key to disable ACG 2018-05-15 13:43:35 -05:00
vega12_processpptables.h drm/amd/powerplay: add the hw manager for vega12 (v4) 2018-03-21 14:36:56 -05:00
vega12_thermal.c drm/amd/pp: use soc15 common macros instead of vega10 specific 2018-05-15 13:43:04 -05:00
vega12_thermal.h drm/amd/powerplay: add the hw manager for vega12 (v4) 2018-03-21 14:36:56 -05:00