2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 04:34:11 +08:00
linux-next/drivers/gpu/drm/gma500
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
..
accel_2d.c drm: Nuke fb->depth 2016-12-15 14:55:33 +02:00
backlight.c
blitter.c
blitter.h
cdv_device.c drm: Don't pass the index to drm_property_add_enum() 2018-04-27 16:46:50 +03:00
cdv_device.h
cdv_intel_crt.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
cdv_intel_display.c drm/gma: removed optional dummy crtc mode_fixup function. 2016-03-04 17:58:34 +01:00
cdv_intel_dp.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
cdv_intel_hdmi.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
cdv_intel_lvds.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
framebuffer.c drm/gma500: Use drm_fb_helper_lastclose() and _poll_changed() 2017-12-08 13:05:22 +01:00
framebuffer.h
gem.c drm/gma500: Use .dumb_map_offset and .dumb_destroy defaults 2017-08-16 20:13:11 +02:00
gem.h
gma_device.c drm/gma500: Deprecate pci_get_bus_and_slot() 2018-01-11 17:27:40 -06:00
gma_device.h
gma_display.c drm: gma500: remove dead code and pointless local lut storage 2017-08-04 11:35:51 +02:00
gma_display.h drm: Add acquire ctx to ->gamma_set hook 2017-04-06 10:21:55 +02:00
gtt.c drm: use set_memory.h header 2017-05-08 17:15:14 -07:00
gtt.h
intel_bios.c
intel_bios.h
intel_gmbus.c drm/gma500: fix error path in gma_intel_setup_gmbus() 2016-02-10 08:25:42 +01:00
intel_i2c.c
Kconfig drm: fix compilations issues introduced by "drm: allow to use mmuless SoC" 2017-01-09 11:30:30 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdfld_device.c
mdfld_dsi_dpi.c drm/gma500/mdfld_dsi: remove bogus if check 2016-04-08 13:42:31 +02:00
mdfld_dsi_dpi.h
mdfld_dsi_output.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
mdfld_dsi_output.h
mdfld_dsi_pkg_sender.c drm/gma500: fix potential NULL pointer dereference dereference 2017-08-18 09:10:46 +02:00
mdfld_dsi_pkg_sender.h
mdfld_intel_display.c drm: gma500: fix logic error 2017-09-06 08:39:55 +02:00
mdfld_output.c
mdfld_output.h
mdfld_tmd_vid.c
mdfld_tpo_vid.c gpu: drm: gma500: remove two more dead variable 2017-05-23 17:38:33 +02:00
mid_bios.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
mid_bios.h
mmu.c gma500: mmu: unmap the correct address 2017-10-30 11:21:55 +01:00
mmu.h
oaktrail_crtc.c drm: Nuke fb->bits_per_pixel 2016-12-15 14:55:34 +02:00
oaktrail_device.c
oaktrail_hdmi_i2c.c
oaktrail_hdmi.c drm/gma500: fix mode_valid's return type 2018-04-25 09:38:28 +02:00
oaktrail_lvds_i2c.c
oaktrail_lvds.c gpu: drm: drivers: Convert printk(KERN_<LEVEL> to pr_<level> 2017-03-01 09:44:11 +01:00
oaktrail.h
opregion.c drm/gma500: remove unnecessary config_enabled() guard 2016-08-24 07:43:42 +02:00
opregion.h
power.c drm/gma500: use to_pci_dev() 2016-01-04 07:57:38 +01:00
power.h
psb_device.c
psb_device.h
psb_drv.c pci-v4.16-changes 2018-02-06 09:59:40 -08:00
psb_drv.h pci-v4.16-changes 2018-02-06 09:59:40 -08:00
psb_intel_display.c drm: gma500: remove dead code and pointless local lut storage 2017-08-04 11:35:51 +02:00
psb_intel_drv.h drm/gma500: fix psb_intel_lvds_mode_valid()'s return type 2018-04-25 09:38:37 +02:00
psb_intel_lvds.c drm/gma500: fix psb_intel_lvds_mode_valid()'s return type 2018-04-25 09:38:37 +02:00
psb_intel_modes.c drm: Remove superflous linux/fb.h includes 2016-08-12 10:41:39 +02:00
psb_intel_reg.h
psb_intel_sdvo_regs.h
psb_intel_sdvo.c drm: Don't pass the index to drm_property_add_enum() 2018-04-27 16:46:50 +03:00
psb_irq.c
psb_irq.h
psb_lid.c drm: gma500: Convert timers to use timer_setup() 2017-11-01 11:44:52 -07:00
psb_reg.h
tc35876x-dsi-lvds.c gpu: drm: tc35876x: move header file out of I2C realm 2017-08-13 16:07:17 +02:00
tc35876x-dsi-lvds.h