public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine•com>
To: Maxim Georgiev <glipus@gmail•com>
Cc: mkubecek@suse•cz, netdev@vger•kernel.org, kuba@kernel•org
Subject: Re: [PATCH ethtool-next] Fixing boolean value output for Netlink reported values in JSON format
Date: Thu, 5 Jan 2023 13:11:33 +0100	[thread overview]
Message-ID: <Y7a+dS2Ga5fdPJ1Y@corigine.com> (raw)
In-Reply-To: <20221227173620.6577-1-glipus@gmail.com>

On Tue, Dec 27, 2022 at 10:36:20AM -0700, Maxim Georgiev wrote:
> Current implementation of show_bool_val() passes "val" parameter of pointer
> type as a last parameter to print_bool():
> https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/netlink.h#n131
> ...
> static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val)
> {
> 	if (is_json_context()) {
> 		if (val)
> >			print_bool(PRINT_JSON, key, NULL, val);
> 	} else {
> ...
> print_bool() expects the last parameter to be bool:
> https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/json_print.c#n153
> ...
> void print_bool(enum output_type type,
> 		const char *key,
> 		const char *fmt,
> 		bool value)
> {
> ...
> Current show_bool_val() implementation converts "val" pointer to bool while
> calling show_bool_val(). As a result show_bool_val() always prints the value
> as "true" as long as it gets a non-null pointer to the boolean value, even if
> the referred boolean value is false.
> 
> Fixes: 7e5c1ddbe67d ("pause: add --json support")
> Signed-off-by: Maxim Georgiev <glipus@gmail•com>

Reviewed-by: Simon Horman <simon.horman@corigine•com>

I'm assuming that val is never NULL :)

> ---
>  netlink/netlink.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/netlink/netlink.h b/netlink/netlink.h
> index 3240fca..1274a3b 100644
> --- a/netlink/netlink.h
> +++ b/netlink/netlink.h
> @@ -128,7 +128,7 @@ static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val)
>  {
>  	if (is_json_context()) {
>  		if (val)
> -			print_bool(PRINT_JSON, key, NULL, val);
> +			print_bool(PRINT_JSON, key, NULL, *val);
>  	} else {
>  		print_string(PRINT_FP, NULL, fmt, u8_to_bool(val));
>  	}
> -- 
> 2.38.1
> 

  reply	other threads:[~2023-01-05 12:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 17:36 [PATCH ethtool-next] Fixing boolean value output for Netlink reported values in JSON format Maxim Georgiev
2023-01-05 12:11 ` Simon Horman [this message]
2023-01-06 22:16   ` Max Georgiev
2023-01-09  8:08     ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y7a+dS2Ga5fdPJ1Y@corigine.com \
    --to=simon.horman@corigine$(echo .)com \
    --cc=glipus@gmail$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=mkubecek@suse$(echo .)cz \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox