netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: netdev@vger.kernel.org, linux-can@vger.kernel.org
Subject: Re: [PATCH iproute2-next 5.16 v6 3/5] iplink_can: use PRINT_ANY to factorize code and fix signedness
Date: Fri, 7 Oct 2022 09:44:56 +0200	[thread overview]
Message-ID: <20221007074456.l2sh3s2siuv2a74m@pengutronix.de> (raw)
In-Reply-To: <20211103164428.692722-4-mailhol.vincent@wanadoo.fr>

[-- Attachment #1: Type: text/plain, Size: 2371 bytes --]

On 04.11.2021 01:44:26, Vincent Mailhol wrote:
> Current implementation heavily relies on some "if (is_json_context())"
> switches to decide the context and then does some print_*(PRINT_JSON,
> ...) when in json context and some fprintf(...) else.
> 
> Furthermore, current implementation uses either print_int() or the
> conversion specifier %d to print unsigned integers.
> 
> This patch factorizes each pairs of print_*(PRINT_JSON, ...) and
> fprintf() into a single print_*(PRINT_ANY, ...) call. While doing this
> replacement, it uses proper unsigned function print_uint() as well as
> the conversion specifier %u when the parameter is an unsigned integer.
> 
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

[...]

>  	if (tb[IFLA_CAN_TERMINATION_CONST] && tb[IFLA_CAN_TERMINATION]) {
> @@ -538,29 +483,21 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
>  			sizeof(*trm_const);
>  		int i;
>  
> -		if (is_json_context()) {
> -			print_hu(PRINT_JSON, "termination", NULL, *trm);
> -			open_json_array(PRINT_JSON, "termination_const");
> -			for (i = 0; i < trm_cnt; ++i)
> -				print_hu(PRINT_JSON, NULL, NULL, trm_const[i]);
> -			close_json_array(PRINT_JSON, NULL);
> -		} else {
> -			fprintf(f, "\n	  termination %hu [ ", *trm);
> -
> -			for (i = 0; i < trm_cnt - 1; ++i)
> -				fprintf(f, "%hu, ", trm_const[i]);
> -
> -			fprintf(f, "%hu ]", trm_const[i]);
                                        ^
> -		}
> +		can_print_nl_indent();
> +		print_hu(PRINT_ANY, "termination", " termination %hu [ ", *trm);

Always '['

> +		open_json_array(PRINT_JSON, "termination_const");
> +		for (i = 0; i < trm_cnt; ++i)
> +			print_hu(PRINT_ANY, NULL,
> +				 i < trm_cnt - 1 ? "%hu, " : "%hu",
> +				 trm_const[i]);
> +		close_json_array(PRINT_JSON, " ]");

']' only for JSON.

>  	}

I just noticed that the non JSON output for termination is missing the
closing ']'. See the output in the documentation update by Daniel:

| https://lore.kernel.org/all/4514353.LvFx2qVVIh@daniel6430

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-10-07  7:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 16:44 [PATCH iproute2-next 5.16 v6 0/5] iplink_can: cleaning, fixes and adding TDC support Vincent Mailhol
2021-11-03 16:44 ` [PATCH iproute2-next 5.16 v6 1/5] iplink_can: fix configuration ranges in print_usage() and add unit Vincent Mailhol
2021-11-03 16:44 ` [PATCH iproute2-next 5.16 v6 2/5] iplink_can: code refactoring of print_ctrlmode() Vincent Mailhol
2021-11-03 16:44 ` [PATCH iproute2-next 5.16 v6 3/5] iplink_can: use PRINT_ANY to factorize code and fix signedness Vincent Mailhol
2022-10-07  7:44   ` Marc Kleine-Budde [this message]
2022-10-10 11:04     ` Vincent MAILHOL
2021-11-03 16:44 ` [PATCH iproute2-next 5.16 v6 4/5] iplink_can: print brp and dbrp bittiming variables Vincent Mailhol
2021-11-03 16:44 ` [PATCH iproute2-next 5.16 v6 5/5] iplink_can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC) Vincent Mailhol
2021-11-04 15:50 ` [PATCH iproute2-next 5.16 v6 0/5] iplink_can: cleaning, fixes and adding TDC support patchwork-bot+netdevbpf

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=20221007074456.l2sh3s2siuv2a74m@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).