[PATCH v2 3/3] configfs: Correct error value returned by API config_item_set_name()

Zijun Hu posted 3 patches 8 months, 1 week ago
There is a newer version of this series
[PATCH v2 3/3] configfs: Correct error value returned by API config_item_set_name()
Posted by Zijun Hu 8 months, 1 week ago
From: Zijun Hu <quic_zijuhu@quicinc.com>

kvasprintf() failure is often caused by memory allocation which has error
code -ENOMEM, but config_item_set_name() returns -EFAULT for the failure.

Fix by returning -ENOMEM instead of -EFAULT for the failure.

Reviewed-by: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 fs/configfs/item.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/configfs/item.c b/fs/configfs/item.c
index 254170a82aa337d95cbfbdf1a2db1023db3a2907..c378b5cbf87d28387a509c3cabb93eccfb520c9c 100644
--- a/fs/configfs/item.c
+++ b/fs/configfs/item.c
@@ -66,7 +66,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
 		name = kvasprintf(GFP_KERNEL, fmt, args);
 		va_end(args);
 		if (!name)
-			return -EFAULT;
+			return -ENOMEM;
 	}
 
 	/* Free the old name, if necessary. */

-- 
2.34.1
Re: [PATCH v2 3/3] configfs: Correct error value returned by API config_item_set_name()
Posted by Breno Leitao 8 months ago
On Tue, Apr 15, 2025 at 08:34:27PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> kvasprintf() failure is often caused by memory allocation which has error
> code -ENOMEM, but config_item_set_name() returns -EFAULT for the failure.
> 
> Fix by returning -ENOMEM instead of -EFAULT for the failure.
> 
> Reviewed-by: Joel Becker <jlbec@evilplan.org>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Reviewed-by: Breno Leitao <leitao@debian.org>

> ---
>  fs/configfs/item.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/configfs/item.c b/fs/configfs/item.c
> index 254170a82aa337d95cbfbdf1a2db1023db3a2907..c378b5cbf87d28387a509c3cabb93eccfb520c9c 100644
> --- a/fs/configfs/item.c
> +++ b/fs/configfs/item.c
> @@ -66,7 +66,7 @@ int config_item_set_name(struct config_item *item, const char *fmt, ...)
>  		name = kvasprintf(GFP_KERNEL, fmt, args);
>  		va_end(args);
>  		if (!name)
> -			return -EFAULT;
> +			return -ENOMEM;

I've checked that all the config_item_set_name() callers, who check for
the return value, are fine with this change also.

--breno