diff mbox series

[net-next,v5,1/8] net: pktgen: fix mix of int/long

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

Commit Message

Peter Seiderer Feb. 13, 2025, 11:19 a.m. UTC
Fix mix of int/long (and multiple conversion from/to) by using consequently
size_t for i and max and ssize_t for len and adjust function signatures
of hex32_arg(), count_trail_chars(), num_arg() and strn_len() accordingly.

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v4 -> v5
  - split up patchset into part i/ii (suggested by Simon Horman)
  - instead of align to most common pattern (int) adjust all usages to
    size_t for i and max and ssize_t for len and adjust function signatures
    of hex32_arg(), count_trail_chars(), num_arg() and strn_len() accordingly
  - respect reverse xmas tree order for local variable declarations (where
    possible without too much code churn)
  - update subject line and patch description
  - fix checkpatch warning '"foo * bar" should be "foo *bar"' for
    count_trail_chars() and strn_len()

Changes v3 -> v4
  - new patch (factored out of patch 'net: pktgen: fix access outside of user
    given buffer in pktgen_if_write()')
---
 net/core/pktgen.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

Comments

Simon Horman Feb. 16, 2025, 1:57 p.m. UTC | #1
On Thu, Feb 13, 2025 at 12:19:13PM +0100, Peter Seiderer wrote:
> Fix mix of int/long (and multiple conversion from/to) by using consequently
> size_t for i and max and ssize_t for len and adjust function signatures
> of hex32_arg(), count_trail_chars(), num_arg() and strn_len() accordingly.
> 
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>
> ---
> Changes v4 -> v5
>   - split up patchset into part i/ii (suggested by Simon Horman)
>   - instead of align to most common pattern (int) adjust all usages to
>     size_t for i and max and ssize_t for len and adjust function signatures
>     of hex32_arg(), count_trail_chars(), num_arg() and strn_len() accordingly
>   - respect reverse xmas tree order for local variable declarations (where
>     possible without too much code churn)
>   - update subject line and patch description
>   - fix checkpatch warning '"foo * bar" should be "foo *bar"' for
>     count_trail_chars() and strn_len()
> 
> Changes v3 -> v4
>   - new patch (factored out of patch 'net: pktgen: fix access outside of user
>     given buffer in pktgen_if_write()')

Thanks Peter,

A minor nit below, but this looks good to me.

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

...

> @@ -777,10 +778,10 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
>  	return i;
>  }
>  
> -static int count_trail_chars(const char __user * user_buffer,
> -			     unsigned int maxlen)
> +static ssize_t count_trail_chars(const char __user *user_buffer,
> +				 size_t maxlen)

nit. as there will be a v2 anyway: the above can fit on one line.

>  {
> -	int i;
> +	size_t i;
>  
>  	for (i = 0; i < maxlen; i++) {
>  		char c;
diff mbox series

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 4f201a2db2dc..36ee0422c6cc 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -755,10 +755,11 @@  static int pktgen_if_show(struct seq_file *seq, void *v)
 }
 
 
-static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
-		     __u32 *num)
+static ssize_t hex32_arg(const char __user *user_buffer, size_t maxlen,
+			 __u32 *num)
 {
-	int i = 0;
+	size_t i = 0;
+
 	*num = 0;
 
 	for (; i < maxlen; i++) {
@@ -777,10 +778,10 @@  static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
 	return i;
 }
 
-static int count_trail_chars(const char __user * user_buffer,
-			     unsigned int maxlen)
+static ssize_t count_trail_chars(const char __user *user_buffer,
+				 size_t maxlen)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < maxlen; i++) {
 		char c;
@@ -802,10 +803,10 @@  static int count_trail_chars(const char __user * user_buffer,
 	return i;
 }
 
-static long num_arg(const char __user *user_buffer, unsigned long maxlen,
-				unsigned long *num)
+static ssize_t num_arg(const char __user *user_buffer, size_t maxlen,
+		       unsigned long *num)
 {
-	int i;
+	size_t i;
 	*num = 0;
 
 	for (i = 0; i < maxlen; i++) {
@@ -821,9 +822,9 @@  static long num_arg(const char __user *user_buffer, unsigned long maxlen,
 	return i;
 }
 
-static int strn_len(const char __user * user_buffer, unsigned int maxlen)
+static ssize_t strn_len(const char __user *user_buffer, size_t maxlen)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < maxlen; i++) {
 		char c;
@@ -853,8 +854,8 @@  static int strn_len(const char __user * user_buffer, unsigned int maxlen)
 static ssize_t get_imix_entries(const char __user *buffer,
 				struct pktgen_dev *pkt_dev)
 {
-	int i = 0;
-	long len;
+	size_t i = 0;
+	ssize_t len;
 	char c;
 
 	pkt_dev->n_imix_entries = 0;
@@ -903,9 +904,9 @@  static ssize_t get_imix_entries(const char __user *buffer,
 static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
 {
 	unsigned int n = 0;
+	size_t i = 0;
+	ssize_t len;
 	char c;
-	ssize_t i = 0;
-	int len;
 
 	pkt_dev->nr_labels = 0;
 	do {
@@ -964,7 +965,8 @@  static ssize_t pktgen_if_write(struct file *file,
 {
 	struct seq_file *seq = file->private_data;
 	struct pktgen_dev *pkt_dev = seq->private;
-	int i, max, len;
+	size_t i, max;
+	ssize_t len;
 	char name[16], valstr[32];
 	unsigned long value = 0;
 	char *pg_result = NULL;
@@ -1891,7 +1893,8 @@  static ssize_t pktgen_thread_write(struct file *file,
 {
 	struct seq_file *seq = file->private_data;
 	struct pktgen_thread *t = seq->private;
-	int i, max, len, ret;
+	size_t i, max;
+	ssize_t len, ret;
 	char name[40];
 	char *pg_result;