linux_dsm_epyc7002/drivers/gpu/drm/radeon
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
..
reg_srcs
.gitignore
atom-bits.h
atom-names.h
atom-types.h
atom.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
atom.h
atombios_crtc.c drm/radeon: radeon_framebuffer -> drm_framebuffer 2018-04-11 13:07:56 -05:00
atombios_dp.c drm/radeon: fix atombios on big endian 2017-10-31 18:24:59 -04:00
atombios_encoders.c drm/radeon: Fix eDP for single-display iMac10,1 (v2) 2017-07-07 11:11:28 -04:00
atombios_i2c.c
atombios.h scripts/spelling.txt: add "aligment" pattern and fix typo instances 2017-02-27 18:43:46 -08:00
avivod.h
btc_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
btc_dpm.h
btcd.h
cayman_blit_shaders.c
cayman_blit_shaders.h
ci_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
ci_dpm.h drm/radeon: move ci_send_msg_to_smc to where it's used 2017-10-08 20:16:28 -04:00
ci_smc.c drm/radeon: move ci_send_msg_to_smc to where it's used 2017-10-08 20:16:28 -04:00
cik_blit_shaders.c
cik_blit_shaders.h
cik_reg.h drm/radeon: Remove KFD_CIK_SDMA_QUEUE_OFFSET 2017-12-20 12:00:22 -05:00
cik_sdma.c
cik.c drm/radeon: fix KV harvesting 2018-03-07 16:27:00 -05:00
cikd.h drm/radeon: deprecate and remove KFD interface 2017-10-30 14:16:21 +01:00
clearstate_cayman.h
clearstate_ci.h
clearstate_defs.h
clearstate_evergreen.h
clearstate_si.h
cypress_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
cypress_dpm.h
dce3_1_afmt.c
dce6_afmt.c
evergreen_blit_shaders.c
evergreen_blit_shaders.h
evergreen_cs.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
evergreen_dma.c
evergreen_hdmi.c
evergreen_reg.h
evergreen_smc.h
evergreen.c drm/radeon: fill in rb backend map on evergreen/ni. 2018-01-16 15:35:28 -05:00
evergreend.h
Kconfig
kv_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
kv_dpm.h
kv_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
Makefile main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
mkregtable.c drm/radeon/mkregtable: Delete unused list functions and macros 2018-03-05 13:31:11 -05:00
ni_dma.c
ni_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
ni_dpm.h
ni_reg.h
ni.c drm/radeon: fill in rb backend map on evergreen/ni. 2018-01-16 15:35:28 -05:00
nid.h
nislands_smc.h
ObjectID.h
ppsmc.h
pptable.h
r100_track.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
r100.c drm: Pass struct drm_file * to __drm_mode_object_find [v2] 2017-10-12 10:03:04 +10:00
r100d.h
r200.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r300_reg.h
r300.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r300d.h
r420.c drm/radeon: check return value of radeon_ring_lock 2017-04-28 17:33:02 -04:00
r420d.h
r500_reg.h
r520.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
r520d.h
r600_blit_shaders.c
r600_blit_shaders.h
r600_cs.c drm: Pass struct drm_file * to __drm_mode_object_find [v2] 2017-10-12 10:03:04 +10:00
r600_dma.c
r600_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
r600_dpm.h
r600_hdmi.c drm/radeon: properly initialize r600_audio_status() data 2017-09-18 23:30:30 -04:00
r600_reg.h
r600.c drm/radeon: Unbreak HPD handling for r600+ 2017-05-24 17:39:33 -04:00
r600d.h
radeon_acpi.c drm/radeon: Make radeon_atif_handler static 2017-08-15 14:46:07 -04:00
radeon_acpi.h drm/radeon: Make radeon_atif_handler static 2017-08-15 14:46:07 -04:00
radeon_agp.c
radeon_asic.c
radeon_asic.h
radeon_atombios.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
radeon_atpx_handler.c drm/radeon: fix radeon_atpx_get_client_id()'s return type 2018-05-15 13:43:51 -05:00
radeon_audio.c drm: handle HDMI 2.0 VICs in AVI info-frames 2017-07-14 21:23:54 +03:00
radeon_audio.h
radeon_benchmark.c
radeon_bios.c drm/radeon: remove some dead code 2017-02-08 21:04:29 -05:00
radeon_clocks.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
radeon_combios.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
radeon_connectors.c drm/radeon: fix mode_valid's return type 2018-05-15 13:43:51 -05:00
radeon_cs.c drm/radeon: Fix preferred typo 2017-08-15 14:46:16 -04:00
radeon_cursor.c drm/radeon: switch to drm_*{get,put} helpers 2017-08-15 14:46:12 -04:00
radeon_device.c drm/radeon: add PX quirk for Asus K73TK 2018-05-15 13:43:02 -05:00
radeon_display.c drm/radeon: radeon_framebuffer -> drm_framebuffer 2018-04-11 13:07:56 -05:00
radeon_dp_auxch.c drm/radeon/dp_auxch: Ratelimit aux transfer debug messages 2017-03-29 23:53:21 -04:00
radeon_dp_mst.c drm/radeon: use raw buffer printk specifier 2018-02-19 14:17:04 -05:00
radeon_drv.c drm/radeon: Change the default to PCI on PowerPC 2018-05-15 13:43:52 -05:00
radeon_drv.h
radeon_encoders.c
radeon_family.h
radeon_fb.c drm/radeon: radeon_framebuffer -> drm_framebuffer 2018-04-11 13:07:56 -05:00
radeon_fence.c sched/wait: Rename wait_queue_t => wait_queue_entry_t 2017-06-20 12:18:27 +02:00
radeon_gart.c drm: use set_memory.h header 2017-05-08 17:15:14 -07:00
radeon_gem.c drm/radeon: fix prime teardown order 2018-03-14 15:39:42 -05:00
radeon_i2c.c
radeon_ib.c
radeon_irq_kms.c Merge branch 'drm-next-4.14' of git://people.freedesktop.org/~agd5f/linux into drm-next 2017-08-02 12:43:12 +10:00
radeon_kms.c drm/radeon: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-06 12:48:34 -05:00
radeon_legacy_crtc.c drm/radeon: radeon_framebuffer -> drm_framebuffer 2018-04-11 13:07:56 -05:00
radeon_legacy_encoders.c
radeon_legacy_tv.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
radeon_mn.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon_mode.h drm/radeon: radeon_framebuffer -> drm_framebuffer 2018-04-11 13:07:56 -05:00
radeon_object.c drm/radeon: fix prime teardown order 2018-03-14 15:39:42 -05:00
radeon_object.h drm/ttm: add evict parameter to ttm_bo_driver::move_notify 2017-01-27 11:13:15 -05:00
radeon_pm.c Revert "drm/radeon/pm: autoswitch power state when in balanced mode" 2018-02-20 16:27:16 -05:00
radeon_prime.c drm/radeon: Maintain prime import/export refcount for BOs 2017-04-07 12:20:40 -04:00
radeon_reg.h
radeon_ring.c drm: drop drm_[cm]alloc* helpers 2017-05-18 17:22:39 +02:00
radeon_sa.c
radeon_semaphore.c
radeon_sync.c
radeon_test.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
radeon_trace_points.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
radeon_trace.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
radeon_ttm.c drm/ttm: add bo as parameter to the ttm_tt_create callback 2018-03-14 14:38:27 -05:00
radeon_ucode.c
radeon_ucode.h
radeon_uvd.c drm/radeon: adjust tested variable 2018-01-29 23:18:17 -05:00
radeon_vce.c
radeon_vm.c drm/ttm: add operation ctx to ttm_bo_validate v2 2017-12-06 12:48:01 -05:00
radeon.h drm/radeon: only enable swiotlb path when need v2 2018-02-13 13:35:14 -05:00
rs100d.h
rs400.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rs400d.h
rs600.c
rs600d.h
rs690.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rs690d.h
rs780_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
rs780_dpm.h
rs780d.h
rv6xx_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
rv6xx_dpm.h
rv6xxd.h
rv200d.h
rv250d.h
rv350d.h
rv515.c gpu: drm: amd/radeon: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-29 23:53:24 -04:00
rv515d.h
rv730_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv730d.h
rv740_dpm.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv740d.h
rv770_dma.c
rv770_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
rv770_dpm.h
rv770_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
rv770_smc.h
rv770.c
rv770d.h
si_blit_shaders.c
si_blit_shaders.h
si_dma.c
si_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
si_dpm.h
si_reg.h
si_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
si.c Linux 4.12-rc7 2017-06-27 08:28:30 +10:00
sid.h
sislands_smc.h
smu7_discrete.h
smu7_fusion.h
smu7.h
sumo_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
sumo_dpm.h
sumo_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
sumod.h
trinity_dpm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
trinity_dpm.h
trinity_smc.c drm/radeon: fix include notation and remove -Iinclude/drm flag 2017-05-17 14:36:40 +02:00
trinityd.h
uvd_v1_0.c
uvd_v2_2.c
uvd_v3_1.c
uvd_v4_2.c
vce_v1_0.c drm/radeon: avoid kernel segfault in vce when gpu fails to resume 2017-02-08 20:59:16 -05:00
vce_v2_0.c drm/radeon: add header comment for clarification to vce_v2_0_enable_mgcg() 2017-07-14 11:05:55 -04:00