diff mbox series

[net-next,v3,04/10] net: pktgen: fix 'rate 0' error handling (return -EINVAL)

Message ID 20250203170201.1661703-5-ps.report@gmx.net (mailing list archive)
State New
Headers show
Series Some pktgen fixes/improvments | expand

Commit Message

Peter Seiderer Feb. 3, 2025, 5:01 p.m. UTC
Given an invalid 'rate' command e.g. 'rate 0' the return value is '1',
leading to the following misleading output:

- the good case

	$ echo "rate 100" > /proc/net/pktgen/lo\@0
	$ grep "Result:" /proc/net/pktgen/lo\@0
	Result: OK: rate=100

- the bad case (before the patch)

	$ echo "rate 0" > /proc/net/pktgen/lo\@0"
	-bash: echo: write error: Invalid argument
	$ grep "Result:" /proc/net/pktgen/lo\@0
	Result: No such parameter "ate"

- with patch applied

	$ echo "rate 0" > /proc/net/pktgen/lo\@0
	-bash: echo: write error: Invalid argument
	$ grep "Result:" /proc/net/pktgen/lo\@0
	Result: Idle

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v2 -> v3:
  - no changes

Changes v1 -> v2:
  - new patch
---
 net/core/pktgen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Feb. 4, 2025, 2:44 p.m. UTC | #1
On Mon, Feb 03, 2025 at 06:01:55PM +0100, Peter Seiderer wrote:
> Given an invalid 'rate' command e.g. 'rate 0' the return value is '1',
> leading to the following misleading output:
> 
> - the good case
> 
> 	$ echo "rate 100" > /proc/net/pktgen/lo\@0
> 	$ grep "Result:" /proc/net/pktgen/lo\@0
> 	Result: OK: rate=100
> 
> - the bad case (before the patch)
> 
> 	$ echo "rate 0" > /proc/net/pktgen/lo\@0"
> 	-bash: echo: write error: Invalid argument
> 	$ grep "Result:" /proc/net/pktgen/lo\@0
> 	Result: No such parameter "ate"
> 
> - with patch applied
> 
> 	$ echo "rate 0" > /proc/net/pktgen/lo\@0
> 	-bash: echo: write error: Invalid argument
> 	$ grep "Result:" /proc/net/pktgen/lo\@0
> 	Result: Idle
> 
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>

Reviewed-by: Simon Horman <horms@kernel.org>
diff mbox series

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 28dbbf70e142..75c7511bf492 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1115,7 +1115,7 @@  static ssize_t pktgen_if_write(struct file *file,
 
 		i += len;
 		if (!value)
-			return len;
+			return -EINVAL;
 		pkt_dev->delay = pkt_dev->min_pkt_size*8*NSEC_PER_USEC/value;
 		if (debug)
 			pr_info("Delay set at: %llu ns\n", pkt_dev->delay);