diff mbox

ath9k_htc: avoid memcpy when downloading firmware

Message ID 1425356643-2707-1-git-send-email-fred.chou.nd@gmail.com (mailing list archive)
State Rejected
Delegated to: Kalle Valo
Headers show

Commit Message

fred.chou.nd@gmail.com March 3, 2015, 4:24 a.m. UTC
From: Fred Chou <fred.chou.nd@gmail.com>

The temporary buffer to hold firmware data is not really needed,
and memcpy can be avoided by using data pointer instead.

Signed-off-by: Fred Chou <fred.chou.nd@gmail.com>
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Comments

Eric Dumazet March 3, 2015, 6 a.m. UTC | #1
On Tue, 2015-03-03 at 12:24 +0800, Fred Chou wrote:
> From: Fred Chou <fred.chou.nd@gmail.com>
> 
> The temporary buffer to hold firmware data is not really needed,
> and memcpy can be avoided by using data pointer instead.
> 
> Signed-off-by: Fred Chou <fred.chou.nd@gmail.com>
> ---
>  drivers/net/wireless/ath/ath9k/hif_usb.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
> index 10c02f5..0bc35a8 100644
> --- a/drivers/net/wireless/ath/ath9k/hif_usb.c
> +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
> @@ -986,30 +986,22 @@ static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
>  	const void *data = hif_dev->fw_data;

Here data can be vmalloc() backed.

>  	size_t len = hif_dev->fw_size;
>  	u32 addr = AR9271_FIRMWARE;
> -	u8 *buf = kzalloc(4096, GFP_KERNEL);

Here buf is kmalloc() backed.

>  	u32 firm_offset;
>  
> -	if (!buf)
> -		return -ENOMEM;
> -
>  	while (len) {
>  		transfer = min_t(size_t, len, 4096);
> -		memcpy(buf, data, transfer);
>  
>  		err = usb_control_msg(hif_dev->udev,
>  				      usb_sndctrlpipe(hif_dev->udev, 0),
>  				      FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
> -				      addr >> 8, 0, buf, transfer, HZ);


Are you sure usb_control_msg() accepts vmalloc()ed buffers ?

My guess is the answer is no.


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
fred.chou.nd@gmail.com March 3, 2015, 2:41 p.m. UTC | #2
On 3/3/2015 2:00 PM, Eric Dumazet wrote:
> On Tue, 2015-03-03 at 12:24 +0800, Fred Chou wrote:
>> From: Fred Chou <fred.chou.nd@gmail.com>
>>
>> The temporary buffer to hold firmware data is not really needed,
>> and memcpy can be avoided by using data pointer instead.
>>
>> Signed-off-by: Fred Chou <fred.chou.nd@gmail.com>
>> ---
>>  drivers/net/wireless/ath/ath9k/hif_usb.c | 12 ++----------
>>  1 file changed, 2 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
>> index 10c02f5..0bc35a8 100644
>> --- a/drivers/net/wireless/ath/ath9k/hif_usb.c
>> +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
>> @@ -986,30 +986,22 @@ static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
>>  	const void *data = hif_dev->fw_data;
> 
> Here data can be vmalloc() backed.
> 
>>  	size_t len = hif_dev->fw_size;
>>  	u32 addr = AR9271_FIRMWARE;
>> -	u8 *buf = kzalloc(4096, GFP_KERNEL);
> 
> Here buf is kmalloc() backed.
> 
>>  	u32 firm_offset;
>>  
>> -	if (!buf)
>> -		return -ENOMEM;
>> -
>>  	while (len) {
>>  		transfer = min_t(size_t, len, 4096);
>> -		memcpy(buf, data, transfer);
>>  
>>  		err = usb_control_msg(hif_dev->udev,
>>  				      usb_sndctrlpipe(hif_dev->udev, 0),
>>  				      FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
>> -				      addr >> 8, 0, buf, transfer, HZ);
> 
> 
> Are you sure usb_control_msg() accepts vmalloc()ed buffers ?
> 
> My guess is the answer is no.
> 
> 

I agree, and I would like to drop the patch. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kalle Valo March 3, 2015, 2:43 p.m. UTC | #3
Fred Chou <fred.chou.nd@gmail.com> writes:

>> Are you sure usb_control_msg() accepts vmalloc()ed buffers ?
>> 
>> My guess is the answer is no.
>> 
>> 
>
> I agree, and I would like to drop the patch. Thanks.

I dropped it from my queue.
diff mbox

Patch

diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
index 10c02f5..0bc35a8 100644
--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
+++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
@@ -986,30 +986,22 @@  static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev)
 	const void *data = hif_dev->fw_data;
 	size_t len = hif_dev->fw_size;
 	u32 addr = AR9271_FIRMWARE;
-	u8 *buf = kzalloc(4096, GFP_KERNEL);
 	u32 firm_offset;
 
-	if (!buf)
-		return -ENOMEM;
-
 	while (len) {
 		transfer = min_t(size_t, len, 4096);
-		memcpy(buf, data, transfer);
 
 		err = usb_control_msg(hif_dev->udev,
 				      usb_sndctrlpipe(hif_dev->udev, 0),
 				      FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT,
-				      addr >> 8, 0, buf, transfer, HZ);
-		if (err < 0) {
-			kfree(buf);
+				      addr >> 8, 0, data, transfer, HZ);
+		if (err < 0)
 			return err;
-		}
 
 		len -= transfer;
 		data += transfer;
 		addr += transfer;
 	}
-	kfree(buf);
 
 	if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info))
 		firm_offset = AR7010_FIRMWARE_TEXT;