Subject: Re: [RFC net-next 1/6] devlink: add device information API

From: Jiri Pirko <[email-masked]>
Date: Tue, 15 Jan 2019 11:15:12 +0100

Tue, Jan 15, 2019 at 01:50:03AM CET, [email-masked] wrote:

[...]

>+static int devlink_nl_info_sn_fill(struct sk_buff *msg, struct devlink *devlink,
>+				   struct netlink_ext_ack *extack)
>+{
>+	unsigned char sn[32];

:/ Not good to have number directly here.

>+	size_t len = 0;
>+	int err;
>+
>+	if (!devlink->ops->serial_get)
>+		return 0;
>+
>+	err = devlink->ops->serial_get(devlink, sn, ARRAY_SIZE(sn), &len,
>+				       extack);

Maybe it would be good to have a helper to fill this as well. That way,
driver could pass buffer of any length and helper would encode it into
skb.

>+	if (err)
>+		return err;
>+
>+	return nla_put(msg, DEVLINK_ATTR_INFO_SERIAL_NUMBER, len, sn);
>+}

[...]