Well, it's up to you. You *could* implement:
#define call_security(method , ...) \
({ int __ret; \
if (try_module_get(security_ops->owner)) { \
__ret = security_ops->method(__VA_ARGS__); \
module_put(security_ops->owner); \
} else \
/* If unloading or loading, default to "allow" */ \
__ret = 0; \
__ret; \
})
Now, if you don't have CONFIG_MODULES this becomes the code as it is
now. If you don't have CONFIG_MODULE_UNLOAD, this becomes:
if (security_ops->owner && security_ops->owner->live)
__ret = security_ops->method(__VA_ARGS__);
else
__ret = 0;
With the case of CONFIG_MODULE_UNLOAD, it looks *really* horrible (53
instructions with 6 branches: ewww...). So I would recommend
register_security insert a shim and take the hit itself:
#ifdef CONFIG_MODULE_UNLOAD
if (ops->owner) {
module_ops->real = ops;
ops = module_ops;
}
#endif
Then module_ops does the inc/dec wrappers (well, it can optimize if
the ops can't sleep...).
Rusty.
-- Anyone who quotes me in their sig is an idiot. -- Rusty Russell. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/