diff mbox series

[RFC,net-next,1/2] net: sched: act_api: add helper macro for tcf_action in module and net init/exit

Message ID 20220916085155.33750-2-shaozhengchao@huawei.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series refactor the module and net init/exit functions in tc_action | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline fail Detected static functions without inline keyword in header files: 1
netdev/build_32bit success Errors and warnings before: 70 this patch: 70
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 84 this patch: 84
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 31 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

shaozhengchao Sept. 16, 2022, 8:51 a.m. UTC
Helper macro for tcf_action that don't do anything special in module
and net init/exit. This eliminates a lot of boilerplate. Each module
may only use this macro once, and calling it replaces module/net_init()
and module/net_exit().

Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 include/net/act_api.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Cong Wang Sept. 17, 2022, 7:03 p.m. UTC | #1
On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
> Helper macro for tcf_action that don't do anything special in module
> and net init/exit. This eliminates a lot of boilerplate. Each module
> may only use this macro once, and calling it replaces module/net_init()
> and module/net_exit().
> 

This looks over engineering to me. I don't think this reduces any code
size or help any readability.

Thanks.
shaozhengchao Sept. 19, 2022, 11:07 a.m. UTC | #2
On 2022/9/18 3:03, Cong Wang wrote:
> On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
>> Helper macro for tcf_action that don't do anything special in module
>> and net init/exit. This eliminates a lot of boilerplate. Each module
>> may only use this macro once, and calling it replaces module/net_init()
>> and module/net_exit().
>>
> 
> This looks over engineering to me. I don't think this reduces any code
> size or help any readability.
> 
> Thanks.
Hi Wang:
	Thank you for your review. I think this macro can simplify
repeated code when adding action modules later.

Zhengchao Shao
Cong Wang Sept. 19, 2022, 4:50 p.m. UTC | #3
On Mon, Sep 19, 2022 at 07:07:22PM +0800, shaozhengchao wrote:
> 
> 
> On 2022/9/18 3:03, Cong Wang wrote:
> > On Fri, Sep 16, 2022 at 04:51:54PM +0800, Zhengchao Shao wrote:
> > > Helper macro for tcf_action that don't do anything special in module
> > > and net init/exit. This eliminates a lot of boilerplate. Each module
> > > may only use this macro once, and calling it replaces module/net_init()
> > > and module/net_exit().
> > > 
> > 
> > This looks over engineering to me. I don't think this reduces any code
> > size or help any readability.
> > 
> > Thanks.
> Hi Wang:
> 	Thank you for your review. I think this macro can simplify
> repeated code when adding action modules later.
> 

I don't think so, it hides the actual code in a less readable way. I'd
like to read the non-macro code.

Thanks.
diff mbox series

Patch

diff --git a/include/net/act_api.h b/include/net/act_api.h
index 61f2ceb3939e..dac8c6475efc 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -292,5 +292,31 @@  static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
 #endif
 }
 
+#define module_net_tcf_action(__mod, __act_ops) \
+static __net_init int __mod##_init_net(struct net *net) \
+{ \
+	struct tc_action_net *tn = net_generic(net, __act_ops.net_id);\
+	return tc_action_net_init(net, tn, &__act_ops);\
+} \
+static void __net_exit __mod##_exit_net(struct list_head *net_list) \
+{ \
+	tc_action_net_exit(net_list, __act_ops.net_id); \
+} \
+static struct pernet_operations __mod##_net_ops = { \
+	.init = __mod##_init_net, \
+	.exit_batch = __mod##_exit_net, \
+	.id   = &__act_ops.net_id, \
+	.size = sizeof(struct tc_action_net), \
+}; \
+static int __init __mod##_init_module(void) \
+{ \
+	return tcf_register_action(&__act_ops, &(__mod##_net_ops)); \
+} \
+module_init(__mod##_init_module); \
+static void __exit __mod##_cleanup_module(void) \
+{ \
+	tcf_unregister_action(&__act_ops, &(__mod##_net_ops)); \
+} \
+module_exit(__mod##_cleanup_module)
 
 #endif