Commit ce14f894 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller

pktgen: refactor pg_init() code

This also shrinks the object size a little.

   text	   data	    bss	    dec	    hex	filename
  28834	    186	      8	  29028	   7164	net/core/pktgen.o
  28816	    186	      8	  29010	   7152	net/core/pktgen.o.AFTER
Signed-off-by: default avatarWANG Cong <xiyou.wangcong@gmail.com>
Cc: "David Miller" <davem@davemloft.net>,
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 68d5ac2e
...@@ -3707,6 +3707,7 @@ static int __init pg_init(void) ...@@ -3707,6 +3707,7 @@ static int __init pg_init(void)
{ {
int cpu; int cpu;
struct proc_dir_entry *pe; struct proc_dir_entry *pe;
int ret = 0;
pr_info("%s", version); pr_info("%s", version);
...@@ -3717,11 +3718,10 @@ static int __init pg_init(void) ...@@ -3717,11 +3718,10 @@ static int __init pg_init(void)
pe = proc_create(PGCTRL, 0600, pg_proc_dir, &pktgen_fops); pe = proc_create(PGCTRL, 0600, pg_proc_dir, &pktgen_fops);
if (pe == NULL) { if (pe == NULL) {
pr_err("ERROR: cannot create %s procfs entry\n", PGCTRL); pr_err("ERROR: cannot create %s procfs entry\n", PGCTRL);
proc_net_remove(&init_net, PG_PROC_DIR); ret = -EINVAL;
return -EINVAL; goto remove_dir;
} }
/* Register us to receive netdevice events */
register_netdevice_notifier(&pktgen_notifier_block); register_netdevice_notifier(&pktgen_notifier_block);
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
...@@ -3735,13 +3735,18 @@ static int __init pg_init(void) ...@@ -3735,13 +3735,18 @@ static int __init pg_init(void)
if (list_empty(&pktgen_threads)) { if (list_empty(&pktgen_threads)) {
pr_err("ERROR: Initialization failed for all threads\n"); pr_err("ERROR: Initialization failed for all threads\n");
unregister_netdevice_notifier(&pktgen_notifier_block); ret = -ENODEV;
remove_proc_entry(PGCTRL, pg_proc_dir); goto unregister;
proc_net_remove(&init_net, PG_PROC_DIR);
return -ENODEV;
} }
return 0; return 0;
unregister:
unregister_netdevice_notifier(&pktgen_notifier_block);
remove_proc_entry(PGCTRL, pg_proc_dir);
remove_dir:
proc_net_remove(&init_net, PG_PROC_DIR);
return ret;
} }
static void __exit pg_cleanup(void) static void __exit pg_cleanup(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment