Skip to content

Commit 568508a

Browse files
jmberg-inteldavem330
authored andcommitted
genetlink: unify registration functions
Now that the ops assignment is just two variables rather than a long list iteration etc., there's no reason to separately export __genl_register_family() and __genl_register_family_with_ops(). Unify the two functions into __genl_register_family() and make genl_register_family_with_ops() call it after assigning the ops. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 052e312 commit 568508a

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

include/net/genetlink.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,34 @@ static inline int genl_register_family(struct genl_family *family)
131131
return __genl_register_family(family);
132132
}
133133

134-
int __genl_register_family_with_ops(struct genl_family *family,
135-
const struct genl_ops *ops, size_t n_ops);
136-
134+
/**
135+
* genl_register_family_with_ops - register a generic netlink family with ops
136+
* @family: generic netlink family
137+
* @ops: operations to be registered
138+
* @n_ops: number of elements to register
139+
*
140+
* Registers the specified family and operations from the specified table.
141+
* Only one family may be registered with the same family name or identifier.
142+
*
143+
* The family id may equal GENL_ID_GENERATE causing an unique id to
144+
* be automatically generated and assigned.
145+
*
146+
* Either a doit or dumpit callback must be specified for every registered
147+
* operation or the function will fail. Only one operation structure per
148+
* command identifier may be registered.
149+
*
150+
* See include/net/genetlink.h for more documenation on the operations
151+
* structure.
152+
*
153+
* Return 0 on success or a negative error code.
154+
*/
137155
static inline int genl_register_family_with_ops(struct genl_family *family,
138156
const struct genl_ops *ops, size_t n_ops)
139157
{
140158
family->module = THIS_MODULE;
141-
return __genl_register_family_with_ops(family, ops, n_ops);
159+
family->ops = ops;
160+
family->n_ops = n_ops;
161+
return __genl_register_family(family);
142162
}
143163

144164
int genl_unregister_family(struct genl_family *family);

net/netlink/genetlink.c

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,18 @@ static void genl_unregister_mc_groups(struct genl_family *family)
283283
__genl_unregister_mc_group(family, grp);
284284
}
285285

286-
static int genl_validate_add_ops(struct genl_family *family,
287-
const struct genl_ops *ops,
288-
unsigned int n_ops)
286+
static int genl_validate_ops(struct genl_family *family)
289287
{
288+
const struct genl_ops *ops = family->ops;
289+
unsigned int n_ops = family->n_ops;
290290
int i, j;
291291

292+
if (WARN_ON(n_ops && !ops))
293+
return -EINVAL;
294+
295+
if (!n_ops)
296+
return 0;
297+
292298
for (i = 0; i < n_ops; i++) {
293299
if (ops[i].dumpit == NULL && ops[i].doit == NULL)
294300
return -EINVAL;
@@ -313,6 +319,9 @@ static int genl_validate_add_ops(struct genl_family *family,
313319
* The family id may equal GENL_ID_GENERATE causing an unique id to
314320
* be automatically generated and assigned.
315321
*
322+
* The family's ops array must already be assigned, you can use the
323+
* genl_register_family_with_ops() helper function.
324+
*
316325
* Return 0 on success or a negative error code.
317326
*/
318327
int __genl_register_family(struct genl_family *family)
@@ -325,6 +334,10 @@ int __genl_register_family(struct genl_family *family)
325334
if (family->id > GENL_MAX_ID)
326335
goto errout;
327336

337+
err = genl_validate_ops(family);
338+
if (err)
339+
return err;
340+
328341
INIT_LIST_HEAD(&family->mcast_groups);
329342

330343
genl_lock_all();
@@ -372,40 +385,6 @@ int __genl_register_family(struct genl_family *family)
372385
}
373386
EXPORT_SYMBOL(__genl_register_family);
374387

375-
/**
376-
* __genl_register_family_with_ops - register a generic netlink family
377-
* @family: generic netlink family
378-
* @ops: operations to be registered
379-
* @n_ops: number of elements to register
380-
*
381-
* Registers the specified family and operations from the specified table.
382-
* Only one family may be registered with the same family name or identifier.
383-
*
384-
* The family id may equal GENL_ID_GENERATE causing an unique id to
385-
* be automatically generated and assigned.
386-
*
387-
* Either a doit or dumpit callback must be specified for every registered
388-
* operation or the function will fail. Only one operation structure per
389-
* command identifier may be registered.
390-
*
391-
* See include/net/genetlink.h for more documenation on the operations
392-
* structure.
393-
*
394-
* Return 0 on success or a negative error code.
395-
*/
396-
int __genl_register_family_with_ops(struct genl_family *family,
397-
const struct genl_ops *ops, size_t n_ops)
398-
{
399-
int err;
400-
401-
err = genl_validate_add_ops(family, ops, n_ops);
402-
if (err)
403-
return err;
404-
405-
return __genl_register_family(family);
406-
}
407-
EXPORT_SYMBOL(__genl_register_family_with_ops);
408-
409388
/**
410389
* genl_unregister_family - unregister generic netlink family
411390
* @family: generic netlink family

0 commit comments

Comments
 (0)