[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210506085035.2fc33bf3@hermes.local>
Date: Thu, 6 May 2021 08:50:35 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: Vincent Mailhol <mailhol.vincent@...adoo.fr>
Cc: Marc Kleine-Budde <mkl@...gutronix.de>, linux-can@...r.kernel.org,
Oliver Hartkopp <socketcan@...tkopp.net>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH v1 1/1] iplink_can: add new CAN FD bittiming
parameters: Transmitter Delay Compensation (TDC)
On Thu, 6 May 2021 20:20:07 +0900
Vincent Mailhol <mailhol.vincent@...adoo.fr> wrote:
> + if (tb[IFLA_CAN_TDC_TDCV] && tb[IFLA_CAN_TDC_TDCO] &&
> + tb[IFLA_CAN_TDC_TDCF]) {
> + __u32 *tdcv = RTA_DATA(tb[IFLA_CAN_TDC_TDCV]);
> + __u32 *tdco = RTA_DATA(tb[IFLA_CAN_TDC_TDCO]);
> + __u32 *tdcf = RTA_DATA(tb[IFLA_CAN_TDC_TDCF]);
> +
> + if (is_json_context()) {
> + open_json_object("tdc");
> + print_int(PRINT_JSON, "tdcv", NULL, *tdcv);
> + print_int(PRINT_JSON, "tdco", NULL, *tdco);
> + print_int(PRINT_JSON, "tdcf", NULL, *tdcf);
> + close_json_object();
> + } else {
> + fprintf(f, "\n tdcv %d tdco %d tdcf %d",
> + *tdcv, *tdco, *tdcf);
> + }
> + }
> +
The most common pattern in iproute2 is to let json/non-json be decided
inside the print routine. I search for all instances of fprintf as
indication of broken code. Also these are not signed values so please
print unsigned. The code should use print_nl() to handle the single line
case. Also, there is helper to handle
Something like:
__u32 tdc = rte_getattr_u32(tb[IFLA_CAN_TDC_TDCV]);
open_json_object("tdc");
print_nl();
print_u32(PRINT_ANY, "tdcv", " tdcv %u", tdcv);
...
Powered by blists - more mailing lists