
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICS3XV -------------------------------- Clean resource when init ntuple/flow fail. Fixes: 4bed6ba0e88f ("net/oenetcls: introduce oenetcls for network optimization") Signed-off-by: Wang Liang <wangliang74@huawei.com> --- net/oenetcls/oenetcls.h | 4 ++-- net/oenetcls/oenetcls_flow.c | 17 ++++++++++++++--- net/oenetcls/oenetcls_main.c | 7 +++++-- net/oenetcls/oenetcls_ntuple.c | 5 +++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/net/oenetcls/oenetcls.h b/net/oenetcls/oenetcls.h index 2eef768e365e..f4a06214f320 100644 --- a/net/oenetcls/oenetcls.h +++ b/net/oenetcls/oenetcls.h @@ -179,9 +179,9 @@ int check_appname(char *task_name); int send_ethtool_ioctl(struct cmd_context *ctx, void *cmd); int alloc_rxq_id(int nid, int devid); void free_rxq_id(int nid, int devid, int rxq_id); -void oecls_ntuple_res_init(void); +int oecls_ntuple_res_init(void); void oecls_ntuple_res_clean(void); -void oecls_flow_res_init(void); +int oecls_flow_res_init(void); void oecls_flow_res_clean(void); #endif /* _NET_OENETCLS_H */ diff --git a/net/oenetcls/oenetcls_flow.c b/net/oenetcls/oenetcls_flow.c index aaa5881a817c..9a7550544305 100644 --- a/net/oenetcls/oenetcls_flow.c +++ b/net/oenetcls/oenetcls_flow.c @@ -391,11 +391,22 @@ static const struct oecls_hook_ops oecls_flow_ops = { .oecls_cfg_rxcls = NULL, }; -void oecls_flow_res_init(void) +int oecls_flow_res_init(void) { - oecls_sock_flow_table_init(); - oecls_dev_flow_table_init(); + int err; + + err = oecls_sock_flow_table_init(); + if (err) + return err; + + err = oecls_dev_flow_table_init(); + if (err) { + oecls_sock_flow_table_release(); + return err; + } + RCU_INIT_POINTER(oecls_ops, &oecls_flow_ops); + return 0; } void oecls_flow_res_clean(void) diff --git a/net/oenetcls/oenetcls_main.c b/net/oenetcls/oenetcls_main.c index ef3c6dabb2f3..181e480d571b 100644 --- a/net/oenetcls/oenetcls_main.c +++ b/net/oenetcls/oenetcls_main.c @@ -1040,9 +1040,12 @@ static __init int oecls_init(void) #endif if (mode == 0) - oecls_ntuple_res_init(); + err = oecls_ntuple_res_init(); else - oecls_flow_res_init(); + err = oecls_flow_res_init(); + + if (err) + goto clean_rxq; return 0; diff --git a/net/oenetcls/oenetcls_ntuple.c b/net/oenetcls/oenetcls_ntuple.c index 456fd01a581b..86fc9138b0df 100644 --- a/net/oenetcls/oenetcls_ntuple.c +++ b/net/oenetcls/oenetcls_ntuple.c @@ -571,16 +571,17 @@ static const struct oecls_hook_ops oecls_ntuple_ops = { .oecls_cfg_rxcls = ethtool_cfg_rxcls, }; -void oecls_ntuple_res_init(void) +int oecls_ntuple_res_init(void) { do_cfg_workqueue = alloc_ordered_workqueue("oecls_cfg", 0); if (!do_cfg_workqueue) { oecls_debug("alloc_ordered_workqueue fails\n"); - return; + return -ENOMEM; } init_oecls_sk_rules(); RCU_INIT_POINTER(oecls_ops, &oecls_ntuple_ops); + return 0; } void oecls_ntuple_res_clean(void) -- 2.34.1