@@ -283,12 +283,18 @@ static void genl_unregister_mc_groups(struct genl_family *family)
283
283
__genl_unregister_mc_group (family , grp );
284
284
}
285
285
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 )
289
287
{
288
+ const struct genl_ops * ops = family -> ops ;
289
+ unsigned int n_ops = family -> n_ops ;
290
290
int i , j ;
291
291
292
+ if (WARN_ON (n_ops && !ops ))
293
+ return - EINVAL ;
294
+
295
+ if (!n_ops )
296
+ return 0 ;
297
+
292
298
for (i = 0 ; i < n_ops ; i ++ ) {
293
299
if (ops [i ].dumpit == NULL && ops [i ].doit == NULL )
294
300
return - EINVAL ;
@@ -313,6 +319,9 @@ static int genl_validate_add_ops(struct genl_family *family,
313
319
* The family id may equal GENL_ID_GENERATE causing an unique id to
314
320
* be automatically generated and assigned.
315
321
*
322
+ * The family's ops array must already be assigned, you can use the
323
+ * genl_register_family_with_ops() helper function.
324
+ *
316
325
* Return 0 on success or a negative error code.
317
326
*/
318
327
int __genl_register_family (struct genl_family * family )
@@ -325,6 +334,10 @@ int __genl_register_family(struct genl_family *family)
325
334
if (family -> id > GENL_MAX_ID )
326
335
goto errout ;
327
336
337
+ err = genl_validate_ops (family );
338
+ if (err )
339
+ return err ;
340
+
328
341
INIT_LIST_HEAD (& family -> mcast_groups );
329
342
330
343
genl_lock_all ();
@@ -372,40 +385,6 @@ int __genl_register_family(struct genl_family *family)
372
385
}
373
386
EXPORT_SYMBOL (__genl_register_family );
374
387
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
-
409
388
/**
410
389
* genl_unregister_family - unregister generic netlink family
411
390
* @family: generic netlink family
0 commit comments