Skip to content

Commit 6f93a30

Browse files
committed
devlink: use DEVLINK_VAR_ATTR_TYPE_* instead of NLA_* in fmsg
JIRA: https://issues.redhat.com/browse/RHEL-105064 commit 88debb5 Author: Jiri Pirko <jiri@resnulli.us> Date: Mon May 5 13:45:13 2025 +0200 devlink: use DEVLINK_VAR_ATTR_TYPE_* instead of NLA_* in fmsg Use newly introduced DEVLINK_VAR_ATTR_TYPE_* enum values instead of internal NLA_* in fmsg health reporter code. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Link: https://patch.msgid.link/20250505114513.53370-5-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 25d2852 commit 6f93a30

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed

net/devlink/health.c

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ static void devlink_fmsg_put_name(struct devlink_fmsg *fmsg, const char *name)
735735
return;
736736
}
737737

738-
item->nla_type = NLA_NUL_STRING;
738+
item->nla_type = DEVLINK_VAR_ATTR_TYPE_NUL_STRING;
739739
item->len = strlen(name) + 1;
740740
item->attrtype = DEVLINK_ATTR_FMSG_OBJ_NAME;
741741
memcpy(&item->value, name, item->len);
@@ -822,32 +822,37 @@ static void devlink_fmsg_put_value(struct devlink_fmsg *fmsg,
822822
static void devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value)
823823
{
824824
devlink_fmsg_err_if_binary(fmsg);
825-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_FLAG);
825+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
826+
DEVLINK_VAR_ATTR_TYPE_FLAG);
826827
}
827828

828829
static void devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value)
829830
{
830831
devlink_fmsg_err_if_binary(fmsg);
831-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U8);
832+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
833+
DEVLINK_VAR_ATTR_TYPE_U8);
832834
}
833835

834836
void devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value)
835837
{
836838
devlink_fmsg_err_if_binary(fmsg);
837-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U32);
839+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
840+
DEVLINK_VAR_ATTR_TYPE_U32);
838841
}
839842
EXPORT_SYMBOL_GPL(devlink_fmsg_u32_put);
840843

841844
static void devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value)
842845
{
843846
devlink_fmsg_err_if_binary(fmsg);
844-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U64);
847+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
848+
DEVLINK_VAR_ATTR_TYPE_U64);
845849
}
846850

847851
void devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value)
848852
{
849853
devlink_fmsg_err_if_binary(fmsg);
850-
devlink_fmsg_put_value(fmsg, value, strlen(value) + 1, NLA_NUL_STRING);
854+
devlink_fmsg_put_value(fmsg, value, strlen(value) + 1,
855+
DEVLINK_VAR_ATTR_TYPE_NUL_STRING);
851856
}
852857
EXPORT_SYMBOL_GPL(devlink_fmsg_string_put);
853858

@@ -857,7 +862,8 @@ void devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
857862
if (!fmsg->err && !fmsg->putting_binary)
858863
fmsg->err = -EINVAL;
859864

860-
devlink_fmsg_put_value(fmsg, value, value_len, NLA_BINARY);
865+
devlink_fmsg_put_value(fmsg, value, value_len,
866+
DEVLINK_VAR_ATTR_TYPE_BINARY);
861867
}
862868
EXPORT_SYMBOL_GPL(devlink_fmsg_binary_put);
863869

@@ -927,57 +933,27 @@ void devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
927933
}
928934
EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_put);
929935

930-
static int
931-
devlink_fmsg_item_fill_type(struct devlink_fmsg_item *msg, struct sk_buff *skb)
932-
{
933-
enum devlink_var_attr_type var_attr_type;
934-
935-
switch (msg->nla_type) {
936-
case NLA_FLAG:
937-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_FLAG;
938-
break;
939-
case NLA_U8:
940-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_U8;
941-
break;
942-
case NLA_U32:
943-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_U32;
944-
break;
945-
case NLA_U64:
946-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_U64;
947-
break;
948-
case NLA_NUL_STRING:
949-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_NUL_STRING;
950-
break;
951-
case NLA_BINARY:
952-
var_attr_type = DEVLINK_VAR_ATTR_TYPE_BINARY;
953-
break;
954-
default:
955-
return -EINVAL;
956-
}
957-
return nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE, var_attr_type);
958-
}
959-
960936
static int
961937
devlink_fmsg_item_fill_data(struct devlink_fmsg_item *msg, struct sk_buff *skb)
962938
{
963939
int attrtype = DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA;
964940
u8 tmp;
965941

966942
switch (msg->nla_type) {
967-
case NLA_FLAG:
943+
case DEVLINK_VAR_ATTR_TYPE_FLAG:
968944
/* Always provide flag data, regardless of its value */
969945
tmp = *(bool *)msg->value;
970946

971947
return nla_put_u8(skb, attrtype, tmp);
972-
case NLA_U8:
948+
case DEVLINK_VAR_ATTR_TYPE_U8:
973949
return nla_put_u8(skb, attrtype, *(u8 *)msg->value);
974-
case NLA_U32:
950+
case DEVLINK_VAR_ATTR_TYPE_U32:
975951
return nla_put_u32(skb, attrtype, *(u32 *)msg->value);
976-
case NLA_U64:
952+
case DEVLINK_VAR_ATTR_TYPE_U64:
977953
return devlink_nl_put_u64(skb, attrtype, *(u64 *)msg->value);
978-
case NLA_NUL_STRING:
954+
case DEVLINK_VAR_ATTR_TYPE_NUL_STRING:
979955
return nla_put_string(skb, attrtype, (char *)&msg->value);
980-
case NLA_BINARY:
956+
case DEVLINK_VAR_ATTR_TYPE_BINARY:
981957
return nla_put(skb, attrtype, msg->len, (void *)&msg->value);
982958
default:
983959
return -EINVAL;
@@ -1011,7 +987,8 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
1011987
err = nla_put_flag(skb, item->attrtype);
1012988
break;
1013989
case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
1014-
err = devlink_fmsg_item_fill_type(item, skb);
990+
err = nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,
991+
item->nla_type);
1015992
if (err)
1016993
break;
1017994
err = devlink_fmsg_item_fill_data(item, skb);

0 commit comments

Comments
 (0)