Subject: Re: [PATCH ethtool-next 2/2] netlink: tsinfo: add statistics support

From: Jakub Kicinski <[email-masked]>
Date: Tue, 16 Apr 2024 17:07:42 -0700

On Tue, 16 Apr 2024 13:37:17 -0700 Rahul Rameshbabu wrote:
> +		if (mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U32)) {
> +			is_u64 = true;
> +			if (mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U64)) {
> +				fprintf(stderr, "malformed netlink message (statistic)\n");
> +				goto err_close_stats;
> +			}
> +		}

possibly cleaner:

	__u64 val;

	if (!mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U32)) {
		val = mnl_attr_get_u32(tb[stats[i].attr]);
	} else if (!mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U64)) {
		val = mnl_attr_get_u64(tb[stats[i].attr]);
	} else {
		fprintf(stderr, "malformed netlink message (statistic)\n");
		goto err_close_stats;
	}