aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2008-01-21 03:25:15 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:08:30 -0500
commit69ab4b7d6db68396dbfa827daa8d6f30f9b546a8 (patch)
tree5c87d44dc524774f553f8214dad13194fef89958
parent198a291ce3a9103f4738600e3cf5416b66e009d9 (diff)
[VLAN]: Clean up initialization code
- move module init/exit functions to end of file, remove some now unnecessary forward declarations - remove some obvious comments - clean up proc init function and move a proc-related printk there Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/8021q/vlan.c141
-rw-r--r--net/8021q/vlanproc.c21
2 files changed, 70 insertions, 92 deletions
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 69a9e0207b1..006d9a9bac9 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -50,16 +50,6 @@ static char vlan_version[] = DRV_VERSION;
50static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>"; 50static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
51static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>"; 51static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
52 52
53static int vlan_device_event(struct notifier_block *, unsigned long, void *);
54static int vlan_ioctl_handler(struct net *net, void __user *);
55static int unregister_vlan_dev(struct net_device *, unsigned short );
56
57static struct notifier_block vlan_notifier_block = {
58 .notifier_call = vlan_device_event,
59};
60
61/* These may be changed at run-time through IOCTLs */
62
63/* Determines interface naming scheme. */ 53/* Determines interface naming scheme. */
64unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; 54unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
65 55
@@ -70,79 +60,6 @@ static struct packet_type vlan_packet_type = {
70 60
71/* End of global variables definitions. */ 61/* End of global variables definitions. */
72 62
73/*
74 * Function vlan_proto_init (pro)
75 *
76 * Initialize VLAN protocol layer,
77 *
78 */
79static int __init vlan_proto_init(void)
80{
81 int err;
82
83 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright);
84 pr_info("All bugs added by %s\n", vlan_buggyright);
85
86 /* proc file system initialization */
87 err = vlan_proc_init();
88 if (err < 0) {
89 pr_err("%s: can't create entry in proc filesystem!\n",
90 __FUNCTION__);
91 return err;
92 }
93
94 dev_add_pack(&vlan_packet_type);
95
96 /* Register us to receive netdevice events */
97 err = register_netdevice_notifier(&vlan_notifier_block);
98 if (err < 0)
99 goto err1;
100
101 err = vlan_netlink_init();
102 if (err < 0)
103 goto err2;
104
105 vlan_ioctl_set(vlan_ioctl_handler);
106 return 0;
107
108err2:
109 unregister_netdevice_notifier(&vlan_notifier_block);
110err1:
111 vlan_proc_cleanup();
112 dev_remove_pack(&vlan_packet_type);
113 return err;
114}
115
116/*
117 * Module 'remove' entry point.
118 * o delete /proc/net/router directory and static entries.
119 */
120static void __exit vlan_cleanup_module(void)
121{
122 int i;
123
124 vlan_ioctl_set(NULL);
125 vlan_netlink_fini();
126
127 /* Un-register us from receiving netdevice events */
128 unregister_netdevice_notifier(&vlan_notifier_block);
129
130 dev_remove_pack(&vlan_packet_type);
131
132 /* This table must be empty if there are no module
133 * references left.
134 */
135 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) {
136 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
137 }
138 vlan_proc_cleanup();
139
140 synchronize_net();
141}
142
143module_init(vlan_proto_init);
144module_exit(vlan_cleanup_module);
145
146/* Must be invoked with RCU read lock (no preempt) */ 63/* Must be invoked with RCU read lock (no preempt) */
147static struct vlan_group *__vlan_find_group(int real_dev_ifindex) 64static struct vlan_group *__vlan_find_group(int real_dev_ifindex)
148{ 65{
@@ -592,6 +509,10 @@ out:
592 return NOTIFY_DONE; 509 return NOTIFY_DONE;
593} 510}
594 511
512static struct notifier_block vlan_notifier_block __read_mostly = {
513 .notifier_call = vlan_device_event,
514};
515
595/* 516/*
596 * VLAN IOCTL handler. 517 * VLAN IOCTL handler.
597 * o execute requested action or pass command to the device driver 518 * o execute requested action or pass command to the device driver
@@ -716,5 +637,59 @@ out:
716 return err; 637 return err;
717} 638}
718 639
640static int __init vlan_proto_init(void)
641{
642 int err;
643
644 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright);
645 pr_info("All bugs added by %s\n", vlan_buggyright);
646
647 err = vlan_proc_init();
648 if (err < 0)
649 goto err1;
650
651 err = register_netdevice_notifier(&vlan_notifier_block);
652 if (err < 0)
653 goto err2;
654
655 err = vlan_netlink_init();
656 if (err < 0)
657 goto err3;
658
659 dev_add_pack(&vlan_packet_type);
660 vlan_ioctl_set(vlan_ioctl_handler);
661 return 0;
662
663err3:
664 unregister_netdevice_notifier(&vlan_notifier_block);
665err2:
666 vlan_proc_cleanup();
667err1:
668 return err;
669}
670
671static void __exit vlan_cleanup_module(void)
672{
673 unsigned int i;
674
675 vlan_ioctl_set(NULL);
676 vlan_netlink_fini();
677
678 unregister_netdevice_notifier(&vlan_notifier_block);
679
680 dev_remove_pack(&vlan_packet_type);
681
682 /* This table must be empty if there are no module references left. */
683 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++)
684 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
685
686 vlan_proc_cleanup();
687
688 synchronize_net();
689}
690
691module_init(vlan_proto_init);
692module_exit(vlan_cleanup_module);
693
719MODULE_LICENSE("GPL"); 694MODULE_LICENSE("GPL");
720MODULE_VERSION(DRV_VERSION); 695MODULE_VERSION(DRV_VERSION);
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index 5da02e29a2c..971e6233801 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -158,15 +158,18 @@ void vlan_proc_cleanup(void)
158int __init vlan_proc_init(void) 158int __init vlan_proc_init(void)
159{ 159{
160 proc_vlan_dir = proc_mkdir(name_root, init_net.proc_net); 160 proc_vlan_dir = proc_mkdir(name_root, init_net.proc_net);
161 if (proc_vlan_dir) { 161 if (!proc_vlan_dir)
162 proc_vlan_conf = create_proc_entry(name_conf, 162 goto err;
163 S_IFREG|S_IRUSR|S_IWUSR, 163
164 proc_vlan_dir); 164 proc_vlan_conf = create_proc_entry(name_conf, S_IFREG|S_IRUSR|S_IWUSR,
165 if (proc_vlan_conf) { 165 proc_vlan_dir);
166 proc_vlan_conf->proc_fops = &vlan_fops; 166 if (!proc_vlan_conf)
167 return 0; 167 goto err;
168 } 168 proc_vlan_conf->proc_fops = &vlan_fops;
169 } 169 return 0;
170
171err:
172 pr_err("%s: can't create entry in proc filesystem!\n", __FUNCTION__);
170 vlan_proc_cleanup(); 173 vlan_proc_cleanup();
171 return -ENOBUFS; 174 return -ENOBUFS;
172} 175}