All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: remove VLA usage
@ 2018-03-08  0:19 Laszlo Toth
  2018-03-08  1:26 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Laszlo Toth @ 2018-03-08  0:19 UTC (permalink / raw)
  To: David S. Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev

Separated snmp_seq_show_tcp_udp() to tcp and udp variants,
so the usage of max_t() for the array size can be emitted.

Signed-off-by: Laszlo Toth <laszlth@gmail.com>
---
 net/ipv4/proc.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index dc5edc8..67f7d76 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -46,8 +46,6 @@
 #include <net/sock.h>
 #include <net/raw.h>
 
-#define TCPUDP_MIB_MAX max_t(u32, UDP_MIB_MAX, TCP_MIB_MAX)
-
 /*
  *	Report socket allocation statistics [mea@utu.fi]
  */
@@ -398,13 +396,13 @@ static int snmp_seq_show_ipstats(struct seq_file *seq, void *v)
 	return 0;
 }
 
-static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
+static int snmp_seq_show_tcp(struct seq_file *seq, void *v)
 {
-	unsigned long buff[TCPUDP_MIB_MAX];
+	unsigned long buff[TCP_MIB_MAX];
 	struct net *net = seq->private;
 	int i;
 
-	memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
+	memset(buff, 0, TCP_MIB_MAX * sizeof(unsigned long));
 
 	seq_puts(seq, "\nTcp:");
 	for (i = 0; snmp4_tcp_list[i].name; i++)
@@ -421,7 +419,16 @@ static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
 			seq_printf(seq, " %lu", buff[i]);
 	}
 
-	memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
+	return 0;
+}
+
+static int snmp_seq_show_udp(struct seq_file *seq, void *v)
+{
+	unsigned long buff[UDP_MIB_MAX];
+	struct net *net = seq->private;
+	int i;
+
+	memset(buff, 0, UDP_MIB_MAX * sizeof(unsigned long));
 
 	snmp_get_cpu_field_batch(buff, snmp4_udp_list,
 				 net->mib.udp_statistics);
@@ -432,7 +439,7 @@ static int snmp_seq_show_tcp_udp(struct seq_file *seq, void *v)
 	for (i = 0; snmp4_udp_list[i].name; i++)
 		seq_printf(seq, " %lu", buff[i]);
 
-	memset(buff, 0, TCPUDP_MIB_MAX * sizeof(unsigned long));
+	memset(buff, 0, UDP_MIB_MAX * sizeof(unsigned long));
 
 	/* the UDP and UDP-Lite MIBs are the same */
 	seq_puts(seq, "\nUdpLite:");
@@ -455,7 +462,8 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
 	icmp_put(seq);	/* RFC 2011 compatibility */
 	icmpmsg_put(seq);
 
-	snmp_seq_show_tcp_udp(seq, v);
+	snmp_seq_show_tcp(seq, v);
+	snmp_seq_show_udp(seq, v);
 
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: remove VLA usage
  2018-03-08  0:19 [PATCH] net: remove VLA usage Laszlo Toth
@ 2018-03-08  1:26 ` David Miller
  2018-03-09 22:24   ` Laszlo Toth
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-03-08  1:26 UTC (permalink / raw)
  To: laszlth; +Cc: kuznet, yoshfuji, netdev

From: Laszlo Toth <laszlth@gmail.com>
Date: Thu, 8 Mar 2018 01:19:53 +0100

> Separated snmp_seq_show_tcp_udp() to tcp and udp variants,
> so the usage of max_t() for the array size can be emitted.
> 
> Signed-off-by: Laszlo Toth <laszlth@gmail.com>

But it's a max on a constant value, computed at compile
time.

I don't see at all why this is necessary.

If the compiler can't figure this out, fix it.

If the compiler warns on this with -Wvla, fix it.

Because there is no reason to have two separate routines for this.

Thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: remove VLA usage
  2018-03-08  1:26 ` David Miller
@ 2018-03-09 22:24   ` Laszlo Toth
  0 siblings, 0 replies; 3+ messages in thread
From: Laszlo Toth @ 2018-03-09 22:24 UTC (permalink / raw)
  To: David Miller; +Cc: laszlth, kuznet, yoshfuji, netdev

On Wed, Mar 07, 2018 at 08:26:14PM -0500, David Miller wrote:
> From: Laszlo Toth <laszlth@gmail.com>
> Date: Thu, 8 Mar 2018 01:19:53 +0100
> 
> > Separated snmp_seq_show_tcp_udp() to tcp and udp variants,
> > so the usage of max_t() for the array size can be emitted.
> > 
> > Signed-off-by: Laszlo Toth <laszlth@gmail.com>
> 
> But it's a max on a constant value, computed at compile
> time.
> 
> I don't see at all why this is necessary.
> 
> If the compiler can't figure this out, fix it.
> 
> If the compiler warns on this with -Wvla, fix it.
> 
> Because there is no reason to have two separate routines for this.
> 
> Thank you.

Yea, since then they'll fix max* defines, so this is unnecessary.
Let's just ignore it.

Laszlo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-09 22:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-08  0:19 [PATCH] net: remove VLA usage Laszlo Toth
2018-03-08  1:26 ` David Miller
2018-03-09 22:24   ` Laszlo Toth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.