* [PATCH] cxgb3: remove VLA
@ 2018-03-06 5:39 Gustavo A. R. Silva
2018-03-07 17:25 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-06 5:39 UTC (permalink / raw)
To: Santosh Raspatur; +Cc: netdev, linux-kernel, Gustavo A. R. Silva
In preparation to enabling -Wvla, remove VLA and replace it
with dynamic memory allocation.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
drivers/net/ethernet/chelsio/cxgb3/t3_hw.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
index a89721f..ad6a280 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/t3_hw.c
@@ -683,20 +683,37 @@ int t3_seeprom_wp(struct adapter *adapter, int enable)
static int vpdstrtouint(char *s, int len, unsigned int base, unsigned int *val)
{
- char tok[len + 1];
+ char *tok;
+ int ret;
+
+ tok = kcalloc(len + 1, sizeof(*tok), GFP_KERNEL);
+ if (!tok)
+ return -ENOMEM;
memcpy(tok, s, len);
tok[len] = 0;
- return kstrtouint(strim(tok), base, val);
+ ret = kstrtouint(strim(tok), base, val);
+
+ kfree(tok);
+ return ret;
}
static int vpdstrtou16(char *s, int len, unsigned int base, u16 *val)
{
- char tok[len + 1];
+ char *tok;
+ int ret;
+
+ tok = kcalloc(len + 1, sizeof(*tok), GFP_KERNEL);
+ if (!tok)
+ return -ENOMEM;
memcpy(tok, s, len);
tok[len] = 0;
- return kstrtou16(strim(tok), base, val);
+
+ ret = kstrtou16(strim(tok), base, val);
+
+ kfree(tok);
+ return ret;
}
/**
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cxgb3: remove VLA
2018-03-06 5:39 [PATCH] cxgb3: remove VLA Gustavo A. R. Silva
@ 2018-03-07 17:25 ` David Miller
2018-03-07 17:30 ` Gustavo A. R. Silva
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-03-07 17:25 UTC (permalink / raw)
To: gustavo; +Cc: santosh, netdev, linux-kernel, garsilva
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Date: Mon, 5 Mar 2018 23:39:34 -0600
> In preparation to enabling -Wvla, remove VLA and replace it
> with dynamic memory allocation.
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
All of these lengths are limited by the encoding of the field in the
VPD, which is a u8, and thus 255 bytes.
Please just change the 'len' argument to these functions to a u8 and
use a 256 byte buffer on the stack.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cxgb3: remove VLA
2018-03-07 17:25 ` David Miller
@ 2018-03-07 17:30 ` Gustavo A. R. Silva
0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-03-07 17:30 UTC (permalink / raw)
To: David Miller, gustavo; +Cc: santosh, netdev, linux-kernel
On 03/07/2018 11:25 AM, David Miller wrote:
> From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
> Date: Mon, 5 Mar 2018 23:39:34 -0600
>
>> In preparation to enabling -Wvla, remove VLA and replace it
>> with dynamic memory allocation.
>>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>
> All of these lengths are limited by the encoding of the field in the
> VPD, which is a u8, and thus 255 bytes.
>
> Please just change the 'len' argument to these functions to a u8 and
> use a 256 byte buffer on the stack.
>
> Thanks.
>
OK. I got it.
Thanks for the feedback.
--
Gustavo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-07 17:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-06 5:39 [PATCH] cxgb3: remove VLA Gustavo A. R. Silva
2018-03-07 17:25 ` David Miller
2018-03-07 17:30 ` Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).