Re: [PATCH iproute2-next v2 2/2] devlink: support u64-array values in devlink param show/set
From: Ratheesh Kannoth <hidden>
Date: 2026-07-01 02:57:40
Also in:
lkml
On 2026-06-30 at 20:06:17, David Ahern (dsahern@kernel.org) wrote:
On 6/29/26 7:50 PM, Ratheesh Kannoth wrote:quoted
--- a/devlink/devlink.c +++ b/devlink/devlink.c +{ + struct devlink_param_u64_array new_arr = {}; + char *copy, *token, *saveptr = NULL; + char delim[] = " ,"; + uint64_t val; + int err; + + copy = strdup(param_value); + if (!copy) + return -ENOMEM; + + token = strtok_r(copy, delim, &saveptr); + while (token) { + if (new_arr.size >= DEVLINK_PARAM_MAX_ARRAY_SIZE) { + free(copy); + pr_err("Too many array elements (max %d)\n", + DEVLINK_PARAM_MAX_ARRAY_SIZE); + return -EINVAL; + } + err = get_u64((__u64 *)&val, token, 10); + if (err) { + free(copy); + pr_err("Value \"%s\" is not a number or not within range\n", + token); + return err; + } + new_arr.val[new_arr.size++] = val; + token = strtok_r(NULL, delim, &saveptr); + } + free(copy); + + if (cur && param_value_u64_array_equal(&new_arr, cur)) + return 1; + + for (uint64_t i = 0; i < new_arr.size; i++) + mnl_attr_put_u64(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, new_arr.val[i]);Why can't this put be done in the loop above as the string is processed?
We need to complete parsing first to check if the new array is identical to the current one (param_value_u64_array_equal()). If they match, the function returns early without populating the Netlink attributes. This follows the coding std used for other data types in devlink.