[PATCH v2] nls: Fix utf8s_to_utf16s parameter type in declaration and definition

ye.xingchen@zte.com.cn posted 1 patch 9 months, 1 week ago
fs/nls/nls_base.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
[PATCH v2] nls: Fix utf8s_to_utf16s parameter type in declaration and definition
Posted by ye.xingchen@zte.com.cn 9 months, 1 week ago
From: YeXingchen <ye.xingchen@zte.com.cn>

The declaration of utf8s_to_utf16s in the header file uses
bool maxlen as the parameter type, while the definition uses bool maxout.

This patch aligns the parameter name in the definition with the
declaration,changing inlen to len,maxout to maxlen to ensure consistency.

Signed-off-by: YeXingchen <ye.xingchen@zte.com.cn>
---
v1->v2
fix the parameter
 fs/nls/nls_base.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
index 18d597e49a19..fcce6ff1380a 100644
--- a/fs/nls/nls_base.c
+++ b/fs/nls/nls_base.c
@@ -129,24 +129,24 @@ static inline void put_utf16(wchar_t *s, unsigned c, enum utf16_endian endian)
 	}
 }

-int utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
-		wchar_t *pwcs, int maxout)
+int utf8s_to_utf16s(const u8 *s, int len, enum utf16_endian endian,
+		wchar_t *pwcs, int maxlen)
 {
 	u16 *op;
 	int size;
 	unicode_t u;

 	op = pwcs;
-	while (inlen > 0 && maxout > 0 && *s) {
+	while (len > 0 && maxlen > 0 && *s) {
 		if (*s & 0x80) {
-			size = utf8_to_utf32(s, inlen, &u);
+			size = utf8_to_utf32(s, len, &u);
 			if (size < 0)
 				return -EINVAL;
 			s += size;
-			inlen -= size;
+			len -= size;

 			if (u >= PLANE_SIZE) {
-				if (maxout < 2)
+				if (maxlen < 2)
 					break;
 				u -= PLANE_SIZE;
 				put_utf16(op++, SURROGATE_PAIR |
@@ -156,15 +156,15 @@ int utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
 						SURROGATE_LOW |
 						(u & SURROGATE_BITS),
 						endian);
-				maxout -= 2;
+				maxlen -= 2;
 			} else {
 				put_utf16(op++, u, endian);
-				maxout--;
+				maxlen--;
 			}
 		} else {
 			put_utf16(op++, *s++, endian);
-			inlen--;
-			maxout--;
+			len--;
+			maxlen--;
 		}
 	}
 	return op - pwcs;
-- 
2.25.1
Re: [PATCH v2] nls: Fix utf8s_to_utf16s parameter type in declaration and definition
Posted by Jan Kara 9 months, 1 week ago
On Thu 13-03-25 16:36:01, ye.xingchen@zte.com.cn wrote:
> From: YeXingchen <ye.xingchen@zte.com.cn>
> 
> The declaration of utf8s_to_utf16s in the header file uses
> bool maxlen as the parameter type, while the definition uses bool maxout.
> 
> This patch aligns the parameter name in the definition with the
> declaration,changing inlen to len,maxout to maxlen to ensure consistency.
> 
> Signed-off-by: YeXingchen <ye.xingchen@zte.com.cn>

Thanks for the patches but you should rather be modifying prototypes in
include/linux/nls.h to match the real declaration. If you actually check
the history, you'll notice commit 045ddc8991698 modified the implementation
but forgot to update the prototypes in include/linux/nls.h. And the names
in the implementation are indeed more descriptive.

								Honza


> ---
> v1->v2
> fix the parameter
>  fs/nls/nls_base.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
> index 18d597e49a19..fcce6ff1380a 100644
> --- a/fs/nls/nls_base.c
> +++ b/fs/nls/nls_base.c
> @@ -129,24 +129,24 @@ static inline void put_utf16(wchar_t *s, unsigned c, enum utf16_endian endian)
>  	}
>  }
> 
> -int utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
> -		wchar_t *pwcs, int maxout)
> +int utf8s_to_utf16s(const u8 *s, int len, enum utf16_endian endian,
> +		wchar_t *pwcs, int maxlen)
>  {
>  	u16 *op;
>  	int size;
>  	unicode_t u;
> 
>  	op = pwcs;
> -	while (inlen > 0 && maxout > 0 && *s) {
> +	while (len > 0 && maxlen > 0 && *s) {
>  		if (*s & 0x80) {
> -			size = utf8_to_utf32(s, inlen, &u);
> +			size = utf8_to_utf32(s, len, &u);
>  			if (size < 0)
>  				return -EINVAL;
>  			s += size;
> -			inlen -= size;
> +			len -= size;
> 
>  			if (u >= PLANE_SIZE) {
> -				if (maxout < 2)
> +				if (maxlen < 2)
>  					break;
>  				u -= PLANE_SIZE;
>  				put_utf16(op++, SURROGATE_PAIR |
> @@ -156,15 +156,15 @@ int utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
>  						SURROGATE_LOW |
>  						(u & SURROGATE_BITS),
>  						endian);
> -				maxout -= 2;
> +				maxlen -= 2;
>  			} else {
>  				put_utf16(op++, u, endian);
> -				maxout--;
> +				maxlen--;
>  			}
>  		} else {
>  			put_utf16(op++, *s++, endian);
> -			inlen--;
> -			maxout--;
> +			len--;
> +			maxlen--;
>  		}
>  	}
>  	return op - pwcs;
> -- 
> 2.25.1
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR