Thread (4 messages) 4 messages, 2 authors, 2021-05-07

Re: [RFC PATCH v1 1/1] iplink_can: add new CAN FD bittiming parameters: Transmitter Delay Compensation (TDC)

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2021-05-06 15:50:48
Also in: lkml, netdev

On Thu,  6 May 2021 20:20:07 +0900
Vincent Mailhol [off-list ref] 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);
...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help