linux_dsm_epyc7002/drivers/gpu/drm/nouveau/nvkm/subdev/fb
Kees Cook 6da2ec5605 treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:

        kmalloc(a * b, gfp)

with:
        kmalloc_array(a * b, gfp)

as well as handling cases of:

        kmalloc(a * b * c, gfp)

with:

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

as it's slightly less ugly than:

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

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

        kmalloc(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 tools/ directory was manually excluded, since it has its own
implementation of kmalloc().

The Coccinelle script used for this was:

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

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

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

(
  kmalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	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;
@@

(
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- kmalloc
+ kmalloc_array
  (
-	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;
@@

(
  kmalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	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;
@@

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
base.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
g84.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
gddr3.c drm/nouveau/fb/ramnv50: Deal with cards without timing entries 2015-11-03 15:02:18 +10:00
gddr5.c drm/nouveau/bios/rammap: Identify DLLoff for >= GF100 2015-11-03 15:02:18 +10:00
gf100.c drm/nouveau/fb/gf100-: bump size of mmu debug buffers to match big page size 2018-05-18 15:01:20 +10:00
gf100.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
gf108.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gk20a.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gk104.c drm/nouveau: Add support for BLCG on Kepler1 2018-02-02 15:24:08 +10:00
gk104.h drm/nouveau: Add support for BLCG on Kepler1 2018-02-02 15:24:08 +10:00
gk110.c drm/nouveau: Add support for BLCG on Kepler2 2018-02-02 15:24:09 +10:00
gm20b.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gm107.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gm200.c drm/nouveau/fb/gm200-: fix overwriting of big page setting 2018-05-18 15:01:20 +10:00
gp10b.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gp100.c drm/nouveau/fb/gv100: initial support 2018-05-18 15:01:34 +10:00
gp102.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
gt215.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
gv100.c drm/nouveau/fb/gv100: initial support 2018-05-18 15:01:34 +10:00
Kbuild drm/nouveau/fb/gv100: initial support 2018-05-18 15:01:34 +10:00
mcp77.c drm/nouveau/fb: convert to new-style nvkm_subdev 2015-08-28 12:40:43 +10:00
mcp89.c drm/nouveau/fb: convert to new-style nvkm_subdev 2015-08-28 12:40:43 +10:00
nv1a.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv4e.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv04.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv10.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv20.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv25.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv30.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv35.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv36.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv40.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv41.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv44.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv46.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv47.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv49.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv50.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
nv50.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
priv.h drm/nouveau/fb/gv100: initial support 2018-05-18 15:01:34 +10:00
ram.c drm/nouveau/mmu: remove old vmm frontend 2017-11-02 13:32:33 +10:00
ram.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
ramfuc.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ramgf100.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgf108.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgk104.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgm107.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgm200.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgp100.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramgt215.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
rammcp77.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramnv1a.c drm/nouveau: deprecate pci_get_bus_and_slot() 2018-01-11 17:28:14 -06:00
ramnv4e.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv04.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv10.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv20.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv40.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv40.h main drm pull request for v4.15 2017-11-15 20:42:10 -08:00
ramnv41.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv44.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv49.c drm/nouveau/fb: move comptag init out of ram submodule 2017-11-02 13:32:22 +10:00
ramnv50.c drm/nouveau/fb/ram: remove old allocators 2017-11-02 13:32:23 +10:00
ramseq.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
regsnv04.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sddr2.c drm/nouveau: add missing header dependencies 2016-11-07 14:04:35 +10:00
sddr3.c drm/nouveau: add missing header dependencies 2016-11-07 14:04:35 +10:00