History

devlink: refactor devlink_nl_param_value_fill_one()

Lift the param type demux and value attr placement into a separate function. This new function, devlink_nl_param_put(), can be used to place additional types values in the value array, e.g., default, current, next values. This commit has no functional change.

Daniel Zahka committed 12 months ago

Commit 17a42aa1 parent 011d1331 file · +39 −31Browse files

Unified · Split

net/devlink/param.c+39−31
@@ -193,58 +193,66 @@ static int devlink_param_set(struct devlink *devlink, · 192 unmodified lines
193193 }
194194
195195 static int
196−devlink_nl_param_value_fill_one(struct sk_buff *msg,
197− enum devlink_param_type type,
198− enum devlink_param_cmode cmode,
199− union devlink_param_value val)
196+devlink_nl_param_value_put(struct sk_buff *msg, enum devlink_param_type type,
197+ int nla_type, union devlink_param_value val)
200198 {
201− struct nlattr *param_value_attr;
202−
203− param_value_attr = nla_nest_start_noflag(msg,
204− DEVLINK_ATTR_PARAM_VALUE);
205− if (!param_value_attr)
206− goto nla_put_failure;
207−
208− if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode))
209− goto value_nest_cancel;
210−
211199 switch (type) {
212200 case DEVLINK_PARAM_TYPE_U8:
213− if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu8))
214− goto value_nest_cancel;
201+ if (nla_put_u8(msg, nla_type, val.vu8))
202+ return -EMSGSIZE;
215203 break;
216204 case DEVLINK_PARAM_TYPE_U16:
217− if (nla_put_u16(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu16))
218− goto value_nest_cancel;
205+ if (nla_put_u16(msg, nla_type, val.vu16))
206+ return -EMSGSIZE;
219207 break;
220208 case DEVLINK_PARAM_TYPE_U32:
221− if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu32))
222− goto value_nest_cancel;
209+ if (nla_put_u32(msg, nla_type, val.vu32))
210+ return -EMSGSIZE;
223211 break;
224212 case DEVLINK_PARAM_TYPE_U64:
225− if (devlink_nl_put_u64(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,
226− val.vu64))
227− goto value_nest_cancel;
213+ if (devlink_nl_put_u64(msg, nla_type, val.vu64))
214+ return -EMSGSIZE;
228215 break;
229216 case DEVLINK_PARAM_TYPE_STRING:
230− if (nla_put_string(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,
231− val.vstr))
232− goto value_nest_cancel;
217+ if (nla_put_string(msg, nla_type, val.vstr))
218+ return -EMSGSIZE;
233219 break;
234220 case DEVLINK_PARAM_TYPE_BOOL:
235− if (val.vbool &&
236− nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA))
237− goto value_nest_cancel;
221+ if (val.vbool && nla_put_flag(msg, nla_type))
222+ return -EMSGSIZE;
238223 break;
239224 }
225+ return 0;
226+}
227+
228+static int
229+devlink_nl_param_value_fill_one(struct sk_buff *msg,
230+ enum devlink_param_type type,
231+ enum devlink_param_cmode cmode,
232+ union devlink_param_value val)
233+{
234+ struct nlattr *param_value_attr;
235+ int err = -EMSGSIZE;
236+
237+ param_value_attr = nla_nest_start_noflag(msg,
238+ DEVLINK_ATTR_PARAM_VALUE);
239+ if (!param_value_attr)
240+ return -EMSGSIZE;
241+
242+ if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode))
243+ goto value_nest_cancel;
244+
245+ err = devlink_nl_param_value_put(msg, type,
246+ DEVLINK_ATTR_PARAM_VALUE_DATA, val);
247+ if (err)
248+ goto value_nest_cancel;
240249
241250 nla_nest_end(msg, param_value_attr);
242251 return 0;
243252
244253 value_nest_cancel:
245254 nla_nest_cancel(msg, param_value_attr);
246−nla_put_failure:
247− return -EMSGSIZE;
255+ return err;
248256 }
249257
250258 static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t