1
0
Fork 0
alistair23-linux/drivers/pinctrl
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
..
actions pinctrl: actions: Add gpio support for Actions S900 SoC 2018-05-23 10:35:24 +02:00
aspeed pinctrl: aspeed: Rework strap register write logic for the AST2500 2017-08-31 13:39:38 +02:00
bcm pinctrl: bcm2835: Add support for output-low output-high properties 2018-05-16 14:01:37 +02:00
berlin pinctrl: berlin: switch to SPDX license identifier 2018-05-23 11:45:23 +02:00
freescale treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
intel This is the bulk of pin control changes for v4.18. 2018-06-07 13:56:45 -07:00
mediatek pinctrl: mediatek: remove unused fields in struct mtk_eint_hw 2018-05-24 09:40:10 +02:00
meson This is the bulk of pin control changes for v4.18. 2018-06-07 13:56:45 -07:00
mvebu pinctrl: armada-37xx: Fix spurious irq management 2018-05-24 10:16:43 +02:00
nomadik pinctrl: nomadik: Drop U8540/9540 support 2018-03-23 03:38:14 +01:00
pxa pinctrl: pxa: pxa2xx: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE 2017-11-30 14:42:04 +01:00
qcom pinctrl: msm: fix gpio-hog related boot issues 2018-05-24 10:03:51 +02:00
samsung This is the bulk of pin control changes for v4.18. 2018-06-07 13:56:45 -07:00
sh-pfc pinctrl: sh-pfc: rcar-gen3: Fix grammar in static pin comments 2018-05-23 14:43:49 +02:00
sirf Merge branch 'gpio-irqchip-rework' of /home/linus/linux-gpio into devel 2017-11-09 09:38:42 +01:00
spear pinctrl: spear: Delete an error message for a failed memory allocation in spear_pinctrl_probe() 2018-01-03 08:46:55 +01:00
sprd pinctrl: sprd: Use seq_putc() in sprd_pinconf_group_dbg_show() 2018-01-16 11:08:24 +01:00
stm32 pinctrl/stm32: Add irq_eoi for stm32gpio irqchip 2018-05-24 12:38:22 +01:00
sunxi treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
tegra pinctrl: tegra20: Provide CDEV1/2 clock muxes 2018-05-16 14:21:32 +02:00
ti pinctrl: ti-iodelay: remove redundant unused variable dev 2017-11-08 13:49:57 +01:00
uniphier This is the bulk of pin control changes for v4.18. 2018-06-07 13:56:45 -07:00
vt8500 pinctrl: vt8500: Delete an error message for a failed memory allocation in five functions 2018-01-08 08:15:46 +01:00
zte pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() 2017-08-14 15:01:01 +02:00
Kconfig pinctrl: actions: Add Actions S900 pinctrl driver 2018-05-02 14:36:08 +02:00
Makefile pinctrl: actions: Add Actions S900 pinctrl driver 2018-05-02 14:36:08 +02:00
core.c pinctrl: core: Add missing EXPORT on pinctrl_register_mappings 2018-03-02 11:05:35 +01:00
core.h pinctrl/gpio: Unify namespace for cross-calls 2017-09-22 11:02:10 +02:00
devicetree.c pinctrl: devicetree: Fix dt_to_map_one_config handling of hogs 2018-03-02 09:41:21 +01:00
devicetree.h pinctrl: core: Use delayed work for hogs 2017-01-03 09:26:16 +01:00
pinconf-generic.c pinctrl: Add skew-delay pin config and bindings 2017-11-08 13:49:45 +01:00
pinconf.c pinctrl: check ops->pin_config_set in pinconf_set_config() 2017-08-14 15:01:59 +02:00
pinconf.h pinctrl: move const qualifier before struct 2017-08-14 15:01:02 +02:00
pinctrl-amd.c pinctrl/amd: poll InterruptEnable bits in enable_irq 2018-03-26 11:09:49 +02:00
pinctrl-amd.h pinctrl/amd: save pin registers over suspend/resume 2017-09-12 15:58:45 +02:00
pinctrl-artpec6.c pinctrl: artpec-6: Add smaller groups for uarts 2018-03-01 17:04:09 +01:00
pinctrl-as3722.c pinctrl: as3722: Use devm_pinctrl_register() for pinctrl registration 2016-04-21 09:23:21 +02:00
pinctrl-at91-pio4.c pinctrl: at91-pio4: add missing of_node_put 2018-05-24 10:30:00 +02:00
pinctrl-at91.c pinctrl: at91: Delete an error message for a failed memory allocation in at91_pinctrl_mux_mask() 2018-01-03 08:46:49 +01:00
pinctrl-at91.h pinctrl: at91: use own header 2014-10-29 09:28:35 +01:00
pinctrl-axp209.c pinctrl: axp209: account for const type of of_device_id.data 2018-01-08 08:15:47 +01:00
pinctrl-coh901.c gpio: Move irqdomain into struct gpio_irq_chip 2017-11-08 14:06:21 +01:00
pinctrl-coh901.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pinctrl-da850-pupd.c Merge branch 'ib-pinctrl-genprops' into devel 2017-01-26 15:27:54 +01:00
pinctrl-digicolor.c pinctrl: digicolor: constify pinconf_ops, pinctrl_ops, and pinmux_ops structures 2017-08-22 14:39:36 +02:00
pinctrl-falcon.c pinctrl: update my email address 2016-12-30 09:17:02 +01:00
pinctrl-gemini.c This is the bulk of pin control changes for the v4.16 kernel cycle: 2018-02-02 14:22:53 -08:00
pinctrl-ingenic.c pinctrl: ingenic: Remove redundant dev_err call in ingenic_pinctrl_probe() 2018-01-18 08:51:32 +01:00
pinctrl-lantiq.c pinctrl: update my email address 2016-12-30 09:17:02 +01:00
pinctrl-lantiq.h pinctrl: update my email address 2016-12-30 09:17:02 +01:00
pinctrl-lpc18xx.c pinctrl: Widen the generic pinconf argument from 16 to 24 bits 2017-01-26 15:22:32 +01:00
pinctrl-max77620.c pinctrl: max77620: Use common error handling code in max77620_pinconf_set() 2017-11-08 13:49:57 +01:00
pinctrl-mcp23s08.c pinctrl: mcp23s08: add open drain configuration for irq output 2018-02-22 16:08:59 +01:00
pinctrl-ocelot.c pinctrl: ocelot: fix gpio direction 2018-03-26 11:04:48 +02:00
pinctrl-oxnas.c gpio: Move irqdomain into struct gpio_irq_chip 2017-11-08 14:06:21 +01:00
pinctrl-palmas.c pinctrl: palmas: Delete an error message for a failed memory allocation in palmas_pinctrl_probe() 2018-01-03 08:46:49 +01:00
pinctrl-pic32.c gpio: Move irqdomain into struct gpio_irq_chip 2017-11-08 14:06:21 +01:00
pinctrl-pic32.h pinctrl: pinctrl-pic32: Add PIC32 pin control driver 2016-02-05 23:54:47 +01:00
pinctrl-pistachio.c gpio: Move irqdomain into struct gpio_irq_chip 2017-11-08 14:06:21 +01:00
pinctrl-rk805.c pinctrl: Add pinctrl driver for the RK805 PMIC 2017-08-21 08:54:46 +01:00
pinctrl-rockchip.c pinctrl: rockchip: Add set_config callback support for gpiolib 2018-05-23 11:33:49 +02:00
pinctrl-rza1.c pinctrl: rza1: Add support for RZ/A1L 2017-10-09 09:16:21 +02:00
pinctrl-single.c pinctrl: pinctrl-single: Add functions to save and restore pinctrl context 2018-05-23 10:30:03 +02:00
pinctrl-st.c gpio: Move irqdomain into struct gpio_irq_chip 2017-11-08 14:06:21 +01:00
pinctrl-sx150x.c pinctrl: sx150x: Add a static gpio/pinctrl pin range mapping 2018-01-18 11:04:47 +01:00
pinctrl-tb10x.c pinctrl: tb10x: constify pinconf_ops, pinctrl_ops, and pinmux_ops structures 2017-08-22 14:41:40 +02:00
pinctrl-u300.c pinctrl: u300: make u300_pmx_registers static 2016-06-13 09:27:43 +02:00
pinctrl-utils.c pinctrl: utils: Delete an error message for a failed memory allocation in pinctrl_utils_add_map_configs() 2018-01-03 08:46:53 +01:00
pinctrl-utils.h pinctrl: Rename pinctrl_utils_dt_free_map to pinctrl_utils_free_map 2016-04-01 15:06:36 +02:00
pinctrl-xway.c pinctrl: xway: Delete two error messages for a failed memory allocation in pinmux_xway_probe() 2018-01-03 08:46:53 +01:00
pinctrl-zynq.c pinctrl: zynq: Fix warnings in the driver 2017-08-14 15:01:01 +02:00
pinmux.c pinctrl: pinmux: Use seq_putc() in pinmux_pins_show() 2018-01-16 11:07:18 +01:00
pinmux.h pinctrl: move const qualifier before struct 2017-08-14 15:01:02 +02:00