diff mbox series

[09/23] hw/net/e1000e_core: Use definition to avoid dynamic stack allocation

Message ID 20210505211047.1496765-10-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series misc: Remove variable-length arrays on the stack | expand

Commit Message

Philippe Mathieu-Daudé May 5, 2021, 9:10 p.m. UTC
The compiler isn't clever enough to figure 'min_buf_size'
is a constant, so help it by using a definitions instead.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/net/e1000e_core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Jason Wang May 6, 2021, 3:35 a.m. UTC | #1
在 2021/5/6 上午5:10, Philippe Mathieu-Daudé 写道:
> The compiler isn't clever enough to figure 'min_buf_size'
> is a constant, so help it by using a definitions instead.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Acked-by: Jason Wang <jasowang@redhat.com>


> ---
>   hw/net/e1000e_core.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
> index b75f2ab8fc1..4b1d4521a50 100644
> --- a/hw/net/e1000e_core.c
> +++ b/hw/net/e1000e_core.c
> @@ -1621,15 +1621,16 @@ e1000e_rx_fix_l4_csum(E1000ECore *core, struct NetRxPkt *pkt)
>       }
>   }
>   
> +/* Min. octets in an ethernet frame sans FCS */
> +#define MIN_BUF_SIZE 60
> +
>   ssize_t
>   e1000e_receive_iov(E1000ECore *core, const struct iovec *iov, int iovcnt)
>   {
>       static const int maximum_ethernet_hdr_len = (14 + 4);
> -    /* Min. octets in an ethernet frame sans FCS */
> -    static const int min_buf_size = 60;
>   
>       uint32_t n = 0;
> -    uint8_t min_buf[min_buf_size];
> +    uint8_t min_buf[MIN_BUF_SIZE];
>       struct iovec min_iov;
>       uint8_t *filter_buf;
>       size_t size, orig_size;
Richard Henderson May 7, 2021, 4:29 p.m. UTC | #2
On 5/5/21 2:10 PM, Philippe Mathieu-Daudé wrote:
> The compiler isn't clever enough to figure 'min_buf_size'
> is a constant, so help it by using a definitions instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@redhat.com>
> ---
>   hw/net/e1000e_core.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)

Fix the commit message along the lines of patch 7.
But the patch itself looks fine.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index b75f2ab8fc1..4b1d4521a50 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -1621,15 +1621,16 @@  e1000e_rx_fix_l4_csum(E1000ECore *core, struct NetRxPkt *pkt)
     }
 }
 
+/* Min. octets in an ethernet frame sans FCS */
+#define MIN_BUF_SIZE 60
+
 ssize_t
 e1000e_receive_iov(E1000ECore *core, const struct iovec *iov, int iovcnt)
 {
     static const int maximum_ethernet_hdr_len = (14 + 4);
-    /* Min. octets in an ethernet frame sans FCS */
-    static const int min_buf_size = 60;
 
     uint32_t n = 0;
-    uint8_t min_buf[min_buf_size];
+    uint8_t min_buf[MIN_BUF_SIZE];
     struct iovec min_iov;
     uint8_t *filter_buf;
     size_t size, orig_size;