linux/drivers/net/wireless/intel/iwlwifi/mvm
Kees Cook acafe7e302 treewide: Use struct_size() for kmalloc()-family
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:

// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
//                      sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-06 11:15:43 -07:00
..
binding.c iwlwifi: mvm: memset binding before setting values 2017-04-25 23:06:51 +03:00
coex.c iwlwifi: mvm: revert support new Coex firmware API 2017-11-25 17:47:44 +02:00
constants.h iwlwifi: mvm: add adaptive dwell support 2018-03-28 22:34:51 +03:00
d3.c iwlwifi: Cancel and set MARKER_CMD timer during suspend-resume 2018-03-02 10:19:59 +02:00
debugfs-vif.c iwlwifi: mvm: save low latency causes in an enum 2018-03-28 22:43:40 +03:00
debugfs.c wireless: Use octal not symbolic permissions 2018-03-27 11:01:13 +03:00
debugfs.h
fw-api.h iwlwifi: mvm: use firmware LED command where applicable 2017-08-09 09:15:32 +03:00
fw.c iwlwifi: add shared clock PHY config flag for some devices 2018-03-16 12:34:54 +02:00
led.c iwlwifi: mvm: only send LEDS_CMD when the FW supports it 2017-09-07 19:40:09 +03:00
mac80211.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
mac-ctxt.c iwlwifi: mvm: fix IBSS for devices that support station type API 2018-02-16 15:34:32 +02:00
Makefile iwlwifi: mvm: rs: add ops for the new rate scaling in the FW 2017-12-05 21:01:41 +02:00
mvm.h iwlwifi: mvm: save low latency causes in an enum 2018-03-28 22:43:40 +03:00
nvm.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers.git 2017-10-16 17:09:24 +03:00
offloading.c
ops.c wireless: Use octal not symbolic permissions 2018-03-27 11:01:13 +03:00
phy-ctxt.c iwlwifi: mvm: Move unused phy's to a default channel 2018-03-19 10:50:38 +02:00
power.c iwlwifi: reorganize firmware API 2017-08-01 12:41:43 +03:00
quota.c iwlwifi: mvm: adjust to quota offload 2017-12-20 18:28:25 +02:00
rs-fw.c iwlwifi: mvm: take RCU lock before dereferencing 2018-03-28 12:16:03 +03:00
rs.c wireless: Use octal not symbolic permissions 2018-03-27 11:01:13 +03:00
rs.h iwlwifi: mvm: rs: new rate scale API - add FW notifications 2017-12-05 21:01:41 +02:00
rx.c iwlwifi: mvm: support RX flags API change 2017-12-20 18:28:24 +02:00
rxmq.c iwlwifi: mvm: flip AMSDU addresses only for 9000 family 2018-03-28 12:16:03 +03:00
scan.c iwlwifi: fw api: support the new scan request FW API version 2018-03-28 22:43:37 +03:00
sf.c iwlwifi: mvm: prepare for station count change 2017-04-19 22:20:51 +03:00
sta.c iwlwifi: mvm: fix array out of bounds reference 2018-03-19 10:50:37 +02:00
sta.h iwlwifi: mvm: rs: introduce new API for rate scaling 2017-12-05 21:01:40 +02:00
tdls.c iwlwifi: mvm: use schedule_delayed_work() 2017-06-05 23:34:26 +03:00
testmode.h
time-event.c iwlwifi: mvm: Increase session protection time after CS 2018-03-19 10:50:36 +02:00
time-event.h
tof.c iwlwifi: reorganize firmware API 2017-08-01 12:41:43 +03:00
tof.h iwlwifi: reorganize firmware API 2017-08-01 12:41:43 +03:00
tt.c iwlwifi: mvm: return -ENODATA when reading the temperature with the FW down 2017-10-06 13:59:44 +03:00
tx.c iwlwifi: mvm: move TSO segment to a separate function 2018-03-28 12:16:04 +03:00
utils.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2018-03-31 23:33:04 -04:00