diff options
Diffstat (limited to 'net/can/af_can.c')
-rw-r--r-- | net/can/af_can.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/net/can/af_can.c b/net/can/af_can.c index 5158e886630f..36b9f22ed83a 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c | |||
@@ -118,7 +118,6 @@ static int can_create(struct net *net, struct socket *sock, int protocol) | |||
118 | { | 118 | { |
119 | struct sock *sk; | 119 | struct sock *sk; |
120 | struct can_proto *cp; | 120 | struct can_proto *cp; |
121 | char module_name[sizeof("can-proto-000")]; | ||
122 | int err = 0; | 121 | int err = 0; |
123 | 122 | ||
124 | sock->state = SS_UNCONNECTED; | 123 | sock->state = SS_UNCONNECTED; |
@@ -129,26 +128,21 @@ static int can_create(struct net *net, struct socket *sock, int protocol) | |||
129 | if (net != &init_net) | 128 | if (net != &init_net) |
130 | return -EAFNOSUPPORT; | 129 | return -EAFNOSUPPORT; |
131 | 130 | ||
131 | #ifdef CONFIG_KMOD | ||
132 | /* try to load protocol module, when CONFIG_KMOD is defined */ | 132 | /* try to load protocol module, when CONFIG_KMOD is defined */ |
133 | if (!proto_tab[protocol]) { | 133 | if (!proto_tab[protocol]) { |
134 | sprintf(module_name, "can-proto-%d", protocol); | 134 | err = request_module("can-proto-%d", protocol); |
135 | err = request_module(module_name); | ||
136 | 135 | ||
137 | /* | 136 | /* |
138 | * In case of error we only print a message but don't | 137 | * In case of error we only print a message but don't |
139 | * return the error code immediately. Below we will | 138 | * return the error code immediately. Below we will |
140 | * return -EPROTONOSUPPORT | 139 | * return -EPROTONOSUPPORT |
141 | */ | 140 | */ |
142 | if (err == -ENOSYS) { | 141 | if (err && printk_ratelimit()) |
143 | if (printk_ratelimit()) | 142 | printk(KERN_ERR "can: request_module " |
144 | printk(KERN_INFO "can: request_module(%s)" | 143 | "(can-proto-%d) failed.\n", protocol); |
145 | " not implemented.\n", module_name); | ||
146 | } else if (err) { | ||
147 | if (printk_ratelimit()) | ||
148 | printk(KERN_ERR "can: request_module(%s)" | ||
149 | " failed.\n", module_name); | ||
150 | } | ||
151 | } | 144 | } |
145 | #endif | ||
152 | 146 | ||
153 | spin_lock(&proto_tab_lock); | 147 | spin_lock(&proto_tab_lock); |
154 | cp = proto_tab[protocol]; | 148 | cp = proto_tab[protocol]; |
@@ -662,26 +656,26 @@ int can_proto_register(struct can_proto *cp) | |||
662 | return -EINVAL; | 656 | return -EINVAL; |
663 | } | 657 | } |
664 | 658 | ||
659 | err = proto_register(cp->prot, 0); | ||
660 | if (err < 0) | ||
661 | return err; | ||
662 | |||
665 | spin_lock(&proto_tab_lock); | 663 | spin_lock(&proto_tab_lock); |
666 | if (proto_tab[proto]) { | 664 | if (proto_tab[proto]) { |
667 | printk(KERN_ERR "can: protocol %d already registered\n", | 665 | printk(KERN_ERR "can: protocol %d already registered\n", |
668 | proto); | 666 | proto); |
669 | err = -EBUSY; | 667 | err = -EBUSY; |
670 | goto errout; | 668 | } else { |
669 | proto_tab[proto] = cp; | ||
670 | |||
671 | /* use generic ioctl function if not defined by module */ | ||
672 | if (!cp->ops->ioctl) | ||
673 | cp->ops->ioctl = can_ioctl; | ||
671 | } | 674 | } |
675 | spin_unlock(&proto_tab_lock); | ||
672 | 676 | ||
673 | err = proto_register(cp->prot, 0); | ||
674 | if (err < 0) | 677 | if (err < 0) |
675 | goto errout; | 678 | proto_unregister(cp->prot); |
676 | |||
677 | proto_tab[proto] = cp; | ||
678 | |||
679 | /* use generic ioctl function if the module doesn't bring its own */ | ||
680 | if (!cp->ops->ioctl) | ||
681 | cp->ops->ioctl = can_ioctl; | ||
682 | |||
683 | errout: | ||
684 | spin_unlock(&proto_tab_lock); | ||
685 | 679 | ||
686 | return err; | 680 | return err; |
687 | } | 681 | } |
@@ -700,9 +694,10 @@ void can_proto_unregister(struct can_proto *cp) | |||
700 | printk(KERN_ERR "BUG: can: protocol %d is not registered\n", | 694 | printk(KERN_ERR "BUG: can: protocol %d is not registered\n", |
701 | proto); | 695 | proto); |
702 | } | 696 | } |
703 | proto_unregister(cp->prot); | ||
704 | proto_tab[proto] = NULL; | 697 | proto_tab[proto] = NULL; |
705 | spin_unlock(&proto_tab_lock); | 698 | spin_unlock(&proto_tab_lock); |
699 | |||
700 | proto_unregister(cp->prot); | ||
706 | } | 701 | } |
707 | EXPORT_SYMBOL(can_proto_unregister); | 702 | EXPORT_SYMBOL(can_proto_unregister); |
708 | 703 | ||