Skip to content

Commit

Permalink
ath10k: wmi: Use struct_size() helper in ath10k_wmi_alloc_skb()
Browse files Browse the repository at this point in the history
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes. Also, remove unnecessary
variable _len_.

This code was detected with the help of Coccinelle and, audited and
fixed manually.

Signed-off-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Kalle Valo <[email protected]>
Link: https://lore.kernel.org/r/20200616225132.GA19873@embeddedor
  • Loading branch information
GustavoARSilva authored and Kalle Valo committed Aug 31, 2020
1 parent 859228a commit e96eecd
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions drivers/net/wireless/ath/ath10k/wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6552,7 +6552,7 @@ static struct sk_buff *ath10k_wmi_op_gen_init(struct ath10k *ar)
struct wmi_init_cmd *cmd;
struct sk_buff *buf;
struct wmi_resource_config config = {};
u32 len, val;
u32 val;

config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS);
Expand Down Expand Up @@ -6604,10 +6604,8 @@ static struct sk_buff *ath10k_wmi_op_gen_init(struct ath10k *ar)
config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);

len = sizeof(*cmd) +
(sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);

buf = ath10k_wmi_alloc_skb(ar, len);
buf = ath10k_wmi_alloc_skb(ar, struct_size(cmd, mem_chunks.items,
ar->wmi.num_mem_chunks));
if (!buf)
return ERR_PTR(-ENOMEM);

Expand All @@ -6625,7 +6623,7 @@ static struct sk_buff *ath10k_wmi_10_1_op_gen_init(struct ath10k *ar)
struct wmi_init_cmd_10x *cmd;
struct sk_buff *buf;
struct wmi_resource_config_10x config = {};
u32 len, val;
u32 val;

config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
config.num_peers = __cpu_to_le32(TARGET_10X_NUM_PEERS);
Expand Down Expand Up @@ -6669,10 +6667,8 @@ static struct sk_buff *ath10k_wmi_10_1_op_gen_init(struct ath10k *ar)
config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);

len = sizeof(*cmd) +
(sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);

buf = ath10k_wmi_alloc_skb(ar, len);
buf = ath10k_wmi_alloc_skb(ar, struct_size(cmd, mem_chunks.items,
ar->wmi.num_mem_chunks));
if (!buf)
return ERR_PTR(-ENOMEM);

Expand All @@ -6690,7 +6686,7 @@ static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar)
struct wmi_init_cmd_10_2 *cmd;
struct sk_buff *buf;
struct wmi_resource_config_10x config = {};
u32 len, val, features;
u32 val, features;

config.num_vdevs = __cpu_to_le32(TARGET_10X_NUM_VDEVS);
config.num_peer_keys = __cpu_to_le32(TARGET_10X_NUM_PEER_KEYS);
Expand Down Expand Up @@ -6742,10 +6738,8 @@ static struct sk_buff *ath10k_wmi_10_2_op_gen_init(struct ath10k *ar)
config.num_msdu_desc = __cpu_to_le32(TARGET_10X_NUM_MSDU_DESC);
config.max_frag_entries = __cpu_to_le32(TARGET_10X_MAX_FRAG_ENTRIES);

len = sizeof(*cmd) +
(sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);

buf = ath10k_wmi_alloc_skb(ar, len);
buf = ath10k_wmi_alloc_skb(ar, struct_size(cmd, mem_chunks.items,
ar->wmi.num_mem_chunks));
if (!buf)
return ERR_PTR(-ENOMEM);

Expand Down Expand Up @@ -6777,7 +6771,6 @@ static struct sk_buff *ath10k_wmi_10_4_op_gen_init(struct ath10k *ar)
struct wmi_init_cmd_10_4 *cmd;
struct sk_buff *buf;
struct wmi_resource_config_10_4 config = {};
u32 len;

config.num_vdevs = __cpu_to_le32(ar->max_num_vdevs);
config.num_peers = __cpu_to_le32(ar->max_num_peers);
Expand Down Expand Up @@ -6839,10 +6832,8 @@ static struct sk_buff *ath10k_wmi_10_4_op_gen_init(struct ath10k *ar)
config.iphdr_pad_config = __cpu_to_le32(TARGET_10_4_IPHDR_PAD_CONFIG);
config.qwrap_config = __cpu_to_le32(TARGET_10_4_QWRAP_CONFIG);

len = sizeof(*cmd) +
(sizeof(struct host_memory_chunk) * ar->wmi.num_mem_chunks);

buf = ath10k_wmi_alloc_skb(ar, len);
buf = ath10k_wmi_alloc_skb(ar, struct_size(cmd, mem_chunks.items,
ar->wmi.num_mem_chunks));
if (!buf)
return ERR_PTR(-ENOMEM);

Expand Down Expand Up @@ -7550,12 +7541,9 @@ ath10k_wmi_op_gen_scan_chan_list(struct ath10k *ar,
struct sk_buff *skb;
struct wmi_channel_arg *ch;
struct wmi_channel *ci;
int len;
int i;

len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);

skb = ath10k_wmi_alloc_skb(ar, len);
skb = ath10k_wmi_alloc_skb(ar, struct_size(cmd, chan_info, arg->n_channels));
if (!skb)
return ERR_PTR(-EINVAL);

Expand Down

0 comments on commit e96eecd

Please sign in to comment.