2015-12-01 05:41:19

by Brent Taylor

[permalink] [raw]
Subject: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.

Signed-off-by: Brent Taylor <[email protected]>
---
drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
index 6ae0734..4f2b124d 100644
--- a/drivers/net/wireless/ath/ath6kl/init.c
+++ b/drivers/net/wireless/ath/ath6kl/init.c
@@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
return ret;

*fw_len = fw_entry->size;
- *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
+ if (&ar->fw == fw)
+ *fw = vmalloc(fw_entry->size);
+ else
+ *fw = kmalloc(fw_entry->size, GFP_KERNEL);

if (*fw == NULL)
ret = -ENOMEM;
+ else
+ memcpy(*fw, fw_entry->data, fw_entry->size);

release_firmware(fw_entry);

--
2.6.3


2015-12-01 13:08:39

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Hello.

On 12/1/2015 8:41 AM, Brent Taylor wrote:

> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7,

The scripts/checkpatch.pl now enforces certain format of the commit citing.

> ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.

This script also checks for unwrapped changelogs. Please run your patches
thru it before posting.

> Signed-off-by: Brent Taylor <[email protected]>
[...]

MBR, Sergei

2015-12-13 00:52:42

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

On Tue, Dec 1, 2015 at 7:41 AM, Brent Taylor <[email protected]> wrote:
> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.
>

I think I already told someone that this kind of fixes miss the
symmetric kvfree() calls. Please, fix.


> Signed-off-by: Brent Taylor <[email protected]>
> ---
> drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
> index 6ae0734..4f2b124d 100644
> --- a/drivers/net/wireless/ath/ath6kl/init.c
> +++ b/drivers/net/wireless/ath/ath6kl/init.c
> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
> return ret;
>
> *fw_len = fw_entry->size;
> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
> + if (&ar->fw == fw)
> + *fw = vmalloc(fw_entry->size);
> + else
> + *fw = kmalloc(fw_entry->size, GFP_KERNEL);
>
> if (*fw == NULL)
> ret = -ENOMEM;
> + else
> + memcpy(*fw, fw_entry->data, fw_entry->size);
>
> release_firmware(fw_entry);
>
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/



--
With Best Regards,
Andy Shevchenko

2015-12-21 19:23:16

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Hi Brent,

On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.
>
> Signed-off-by: Brent Taylor <[email protected]>
> ---
> drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
> index 6ae0734..4f2b124d 100644
> --- a/drivers/net/wireless/ath/ath6kl/init.c
> +++ b/drivers/net/wireless/ath/ath6kl/init.c
> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
> return ret;
>
> *fw_len = fw_entry->size;
> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
> + if (&ar->fw == fw)
> + *fw = vmalloc(fw_entry->size);
> + else
> + *fw = kmalloc(fw_entry->size, GFP_KERNEL);

Why vmalloc and kmalloc both are required? can't use either
vmalloc or kmalloc?
>
> if (*fw == NULL)
> ret = -ENOMEM;
> + else
> + memcpy(*fw, fw_entry->data, fw_entry->size);
>
> release_firmware(fw_entry);
>
> --
> 2.6.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

-Souptick

2015-12-21 21:53:47

by Brent Taylor

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

On Mon, Dec 21, 2015 at 1:23 PM, Souptick Joarder <[email protected]> wrote:
> Hi Brent,
>
> On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
>> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.
>>
>> Signed-off-by: Brent Taylor <[email protected]>
>> ---
>> drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
>> index 6ae0734..4f2b124d 100644
>> --- a/drivers/net/wireless/ath/ath6kl/init.c
>> +++ b/drivers/net/wireless/ath/ath6kl/init.c
>> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
>> return ret;
>>
>> *fw_len = fw_entry->size;
>> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
>> + if (&ar->fw == fw)
>> + *fw = vmalloc(fw_entry->size);
>> + else
>> + *fw = kmalloc(fw_entry->size, GFP_KERNEL);
>
> Why vmalloc and kmalloc both are required? can't use either
> vmalloc or kmalloc?

My original problem was that kmemdup (which uses kmalloc) could not
allocate enough memory
to hold the firmware that is placed into "ar->fw". In the function
ath6kl_core_cleanup (in core.c),
the "ar->fw" pointer is the only one that uses vfree which was changed in commit
8437754c83351d6213c1a47ff029c1126d6042a7.

I was trying to change as little as possible and I wasn't sure if
there was a reason that any of the
other firmware items needed to be allocated with kmalloc or if they
could be changed to use vmalloc.

2015-12-21 22:06:33

by Dan Kephart

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Hi Brent and Souptick,




On 12/21/15, 2:23 PM, "ath6kl on behalf of Souptick Joarder" <[email protected] on behalf of [email protected]> wrote:

>Hi Brent,
>
>On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
>> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.
>>
>> Signed-off-by: Brent Taylor <[email protected]>
>> ---
>> drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
>> index 6ae0734..4f2b124d 100644
>> --- a/drivers/net/wireless/ath/ath6kl/init.c
>> +++ b/drivers/net/wireless/ath/ath6kl/init.c
>> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
>> return ret;
>>
>> *fw_len = fw_entry->size;
>> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
>> + if (&ar->fw == fw)
>> + *fw = vmalloc(fw_entry->size);
>> + else
>> + *fw = kmalloc(fw_entry->size, GFP_KERNEL);
>
> Why vmalloc and kmalloc both are required? can't use either
>vmalloc or kmalloc?

My guess is the reason to use both vmalloc and kmalloc is that the firmware blob can be near 128KB. I know our ar6003 firmwares approach that. So vmalloc must have been chosen to avoid any issues if it was greater than 128KB. So kmalloc is used for all the small firmware pieces (board data, otp.bin, etc) but vmalloc for the firmware itself.

I personally fixed this issue for loading the firmware (but not board data, opt.bin, etc) in the api1 and testmode functions by have it call a new helper function:

static int ath6kl_get_fw_vm(struct ath6kl *ar, const char *filename,
u8 **fw, size_t *fw_len)
{
const struct firmware *fw_entry;
int ret;

ret = request_firmware(&fw_entry, filename, ar->dev);
if (ret)
return ret;

*fw_len = fw_entry->size;
*fw = vmalloc(*fw_len);

if (*fw == NULL)
ret = -ENOMEM;

memcpy(*fw, fw_entry->data, *fw_len);

release_firmware(fw_entry);

return ret;
}



>>
>> if (*fw == NULL)
>> ret = -ENOMEM;
>> + else
>> + memcpy(*fw, fw_entry->data, fw_entry->size);
>>
>> release_firmware(fw_entry);
>>
>> --
>> 2.6.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>-Souptick
>
>_______________________________________________
>ath6kl mailing list
>[email protected]
>http://lists.infradead.org/mailman/listinfo/ath6kl

- Dan Kephart
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2015-12-22 09:05:41

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Hi Brent,

On Tue, Dec 22, 2015 at 3:23 AM, Brent Taylor <[email protected]> wrote:
> On Mon, Dec 21, 2015 at 1:23 PM, Souptick Joarder <[email protected]> wrote:
>> Hi Brent,
>>
>> On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
>>> Since commit 8437754c83351d6213c1a47ff029c1126d6042a7, ar->fw is expected to be pointing to memory allocated by vmalloc. If the api1 method (via ath6kl_fetch_fw_api1) is used to allocate memory for ar->fw, then kmemdup is used. This patch checks if the firmware being loaded is the 'fw' image, then use vmalloc, otherwise use kmalloc.
>>>
>>> Signed-off-by: Brent Taylor <[email protected]>
>>> ---
>>> drivers/net/wireless/ath/ath6kl/init.c | 7 ++++++-
>>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
>>> index 6ae0734..4f2b124d 100644
>>> --- a/drivers/net/wireless/ath/ath6kl/init.c
>>> +++ b/drivers/net/wireless/ath/ath6kl/init.c
>>> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
>>> return ret;
>>>
>>> *fw_len = fw_entry->size;
>>> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
>>> + if (&ar->fw == fw)
>>> + *fw = vmalloc(fw_entry->size);
>>> + else
>>> + *fw = kmalloc(fw_entry->size, GFP_KERNEL)
>>
>> Why vmalloc and kmalloc both are required? can't use either
>> vmalloc or kmalloc?
>
> My original problem was that kmemdup (which uses kmalloc) could not
> allocate enough memory

If kmemdump ( which uses kmalloc) could not allocate memory then
using kmalloc again can lead to same problem.
I guess it will be correct to use
*fw = vmalloc(fw_entry->size);
Correct me if i am wrong.

> to hold the firmware that is placed into "ar->fw". In the function
> ath6kl_core_cleanup (in core.c),
> the "ar->fw" pointer is the only one that uses vfree which was changed in commit
> 8437754c83351d6213c1a47ff029c1126d6042a7.
>
> I was trying to change as little as possible and I wasn't sure if
> there was a reason that any of the
> other firmware items needed to be allocated with kmalloc or if they
> could be changed to use vmalloc.

-Souptick

2015-12-22 09:12:35

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Souptick Joarder <[email protected]> writes:

> Hi Brent,
>
> On Tue, Dec 22, 2015 at 3:23 AM, Brent Taylor <[email protected]> wrote:
>> On Mon, Dec 21, 2015 at 1:23 PM, Souptick Joarder <[email protected]> wrote:
>>> Hi Brent,
>>>
>>> On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
>>>
>>>> --- a/drivers/net/wireless/ath/ath6kl/init.c
>>>> +++ b/drivers/net/wireless/ath/ath6kl/init.c
>>>> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
>>>> return ret;
>>>>
>>>> *fw_len = fw_entry->size;
>>>> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
>>>> + if (&ar->fw == fw)
>>>> + *fw = vmalloc(fw_entry->size);
>>>> + else
>>>> + *fw = kmalloc(fw_entry->size, GFP_KERNEL)
>>>
>>> Why vmalloc and kmalloc both are required? can't use either
>>> vmalloc or kmalloc?
>>
>> My original problem was that kmemdup (which uses kmalloc) could not
>> allocate enough memory
>
> If kmemdump ( which uses kmalloc) could not allocate memory then
> using kmalloc again can lead to same problem.
> I guess it will be correct to use
> *fw = vmalloc(fw_entry->size);
> Correct me if i am wrong.

That sounds best. But remember take into account DMA requirements, IIRC
you cannot DMA from vmalloc memory on all platforms.

--
Kalle Valo

2015-12-29 18:16:47

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH] ath6kl: Use vmalloc to allocate ar->fw for api1 method

Brent,

On Tue, Dec 22, 2015 at 2:42 PM, Kalle Valo <[email protected]> wrote:
> Souptick Joarder <[email protected]> writes:
>
>> Hi Brent,
>>
>> On Tue, Dec 22, 2015 at 3:23 AM, Brent Taylor <[email protected]> wrote:
>>> On Mon, Dec 21, 2015 at 1:23 PM, Souptick Joarder <[email protected]> wrote:
>>>> Hi Brent,
>>>>
>>>> On Tue, Dec 1, 2015 at 11:11 AM, Brent Taylor <[email protected]> wrote:
>>>>
>>>>> --- a/drivers/net/wireless/ath/ath6kl/init.c
>>>>> +++ b/drivers/net/wireless/ath/ath6kl/init.c
>>>>> @@ -673,10 +673,15 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
>>>>> return ret;
>>>>>
>>>>> *fw_len = fw_entry->size;
>>>>> - *fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
>>>>> + if (&ar->fw == fw)
>>>>> + *fw = vmalloc(fw_entry->size);
>>>>> + else
>>>>> + *fw = kmalloc(fw_entry->size, GFP_KERNEL)
>>>>
>>>> Why vmalloc and kmalloc both are required? can't use either
>>>> vmalloc or kmalloc?
>>>
>>> My original problem was that kmemdup (which uses kmalloc) could not
>>> allocate enough memory
>>
>> If kmemdump ( which uses kmalloc) could not allocate memory then
>> using kmalloc again can lead to same problem.
>> I guess it will be correct to use
>> *fw = vmalloc(fw_entry->size);
>> Correct me if i am wrong.
>
> That sounds best. But remember take into account DMA requirements, IIRC
> you cannot DMA from vmalloc memory on all platforms.

Is it possible to modify the patch as per feedback from Kalle.

>
> --
> Kalle Valo

-Souptick