net/wireless: Use kmemdup rather than duplicating its implementation
kmemdup is introduced to duplicate a region of memory in a neat way. Rather than kmalloc/kzalloc + memcpy, which the programmer needs to write the size twice (sometimes lead to mistakes), kmemdup improves readability, leads to smaller code and also reduce the chances of mistakes. Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy. Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
This commit is contained in:
@@ -3650,7 +3650,7 @@ static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
|
||||
if (wait)
|
||||
return -EINVAL; /* Offload for wait not supported */
|
||||
|
||||
buf = kmalloc(data_len, GFP_KERNEL);
|
||||
buf = kmemdup(data, data_len, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -3661,7 +3661,6 @@ static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
|
||||
}
|
||||
|
||||
kfree(wmi->last_mgmt_tx_frame);
|
||||
memcpy(buf, data, data_len);
|
||||
wmi->last_mgmt_tx_frame = buf;
|
||||
wmi->last_mgmt_tx_frame_len = data_len;
|
||||
|
||||
@@ -3689,7 +3688,7 @@ static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
|
||||
if (wait)
|
||||
return -EINVAL; /* Offload for wait not supported */
|
||||
|
||||
buf = kmalloc(data_len, GFP_KERNEL);
|
||||
buf = kmemdup(data, data_len, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -3700,7 +3699,6 @@ static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
|
||||
}
|
||||
|
||||
kfree(wmi->last_mgmt_tx_frame);
|
||||
memcpy(buf, data, data_len);
|
||||
wmi->last_mgmt_tx_frame = buf;
|
||||
wmi->last_mgmt_tx_frame_len = data_len;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user