[PATCH] libbpf: Remove unneeded conversion to bool

Thorsten Blum posted 1 patch 1 year, 11 months ago
tools/lib/bpf/libbpf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] libbpf: Remove unneeded conversion to bool
Posted by Thorsten Blum 1 year, 11 months ago
Fixes Coccinelle/coccicheck warning reported by boolconv.cocci.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index afd09571c482..2dda7a6c6f85 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1801,7 +1801,7 @@ static int set_kcfg_value_tri(struct extern_desc *ext, void *ext_val,
 				ext->name, value);
 			return -EINVAL;
 		}
-		*(bool *)ext_val = value == 'y' ? true : false;
+		*(bool *)ext_val = value == 'y';
 		break;
 	case KCFG_TRISTATE:
 		if (value == 'y')
-- 
2.44.0
Re: [PATCH] libbpf: Remove unneeded conversion to bool
Posted by Yonghong Song 1 year, 11 months ago
On 3/1/24 4:54 PM, Thorsten Blum wrote:
> Fixes Coccinelle/coccicheck warning reported by boolconv.cocci.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>

See
   https://lore.kernel.org/bpf/229F1668-2FE9-4B09-8314-DFB13B3D0A12@fb.com/

This has been discussed multiple times and recommendation is to keep it as is.

> ---
>   tools/lib/bpf/libbpf.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index afd09571c482..2dda7a6c6f85 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1801,7 +1801,7 @@ static int set_kcfg_value_tri(struct extern_desc *ext, void *ext_val,
>   				ext->name, value);
>   			return -EINVAL;
>   		}
> -		*(bool *)ext_val = value == 'y' ? true : false;
> +		*(bool *)ext_val = value == 'y';
>   		break;
>   	case KCFG_TRISTATE:
>   		if (value == 'y')