X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net%2Feconet%2Faf_econet.c;fp=net%2Feconet%2Faf_econet.c;h=c792994d795257a90aaa87ad33d305db31613dd2;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=4d66aac134835fb082044c26041c6f6039e3ba24;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c index 4d66aac13..c792994d7 100644 --- a/net/econet/af_econet.c +++ b/net/econet/af_econet.c @@ -9,6 +9,7 @@ * */ +#include #include #include @@ -41,7 +42,6 @@ #include #include #include -#include #include #include @@ -49,7 +49,6 @@ static const struct proto_ops econet_ops; static struct hlist_head econet_sklist; static DEFINE_RWLOCK(econet_lock); -static DEFINE_MUTEX(econet_mutex); /* Since there are only 256 possible network numbers (or fewer, depends how you count) it makes sense to use a simple lookup table. */ @@ -125,8 +124,6 @@ static int econet_recvmsg(struct kiocb *iocb, struct socket *sock, msg->msg_namelen = sizeof(struct sockaddr_ec); - mutex_lock(&econet_mutex); - /* * Call the generic datagram receiver. This handles all sorts * of horrible races and re-entrancy so we can forget about it @@ -177,7 +174,6 @@ static int econet_recvmsg(struct kiocb *iocb, struct socket *sock, out_free: skb_free_datagram(sk, skb); out: - mutex_unlock(&econet_mutex); return err; } @@ -188,8 +184,8 @@ out: static int econet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) { struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr; - struct sock *sk; - struct econet_sock *eo; + struct sock *sk=sock->sk; + struct econet_sock *eo = ec_sk(sk); /* * Check legality @@ -199,18 +195,11 @@ static int econet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len sec->sec_family != AF_ECONET) return -EINVAL; - mutex_lock(&econet_mutex); - - sk = sock->sk; - eo = ec_sk(sk); - eo->cb = sec->cb; eo->port = sec->port; eo->station = sec->addr.station; eo->net = sec->addr.net; - mutex_unlock(&econet_mutex); - return 0; } @@ -295,8 +284,6 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, * Get and verify the address. */ - mutex_lock(&econet_mutex); - if (saddr == NULL) { struct econet_sock *eo = ec_sk(sk); @@ -305,10 +292,8 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, port = eo->port; cb = eo->cb; } else { - if (msg->msg_namelen < sizeof(struct sockaddr_ec)) { - mutex_unlock(&econet_mutex); + if (msg->msg_namelen < sizeof(struct sockaddr_ec)) return -EINVAL; - } addr.station = saddr->addr.station; addr.net = saddr->addr.net; port = saddr->port; @@ -319,21 +304,19 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, dev = net2dev_map[addr.net]; /* If not directly reachable, use some default */ - if (dev == NULL) { + if (dev == NULL) + { dev = net2dev_map[0]; /* No interfaces at all? */ - if (dev == NULL) { - mutex_unlock(&econet_mutex); + if (dev == NULL) return -ENETDOWN; - } } - if (len + 15 > dev->mtu) { - mutex_unlock(&econet_mutex); + if (len + 15 > dev->mtu) return -EMSGSIZE; - } - if (dev->type == ARPHRD_ECONET) { + if (dev->type == ARPHRD_ECONET) + { /* Real hardware Econet. We're not worthy etc. */ #ifdef CONFIG_ECONET_NATIVE unsigned short proto = 0; @@ -391,7 +374,6 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, dev_queue_xmit(skb); dev_put(dev); - mutex_unlock(&econet_mutex); return(len); out_free: @@ -402,18 +384,14 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, #else err = -EPROTOTYPE; #endif - mutex_unlock(&econet_mutex); - return err; } #ifdef CONFIG_ECONET_AUNUDP /* AUN virtual Econet. */ - if (udpsock == NULL) { - mutex_unlock(&econet_mutex); + if (udpsock == NULL) return -ENETDOWN; /* No socket - can't send */ - } /* Make up a UDP datagram and hand it off to some higher intellect. */ @@ -460,10 +438,8 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, void __user *base = msg->msg_iov[i].iov_base; size_t len = msg->msg_iov[i].iov_len; /* Check it now since we switch to KERNEL_DS later. */ - if (!access_ok(VERIFY_READ, base, len)) { - mutex_unlock(&econet_mutex); + if (!access_ok(VERIFY_READ, base, len)) return -EFAULT; - } iov[i+1].iov_base = base; iov[i+1].iov_len = len; size += len; @@ -471,11 +447,8 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, /* Get a skbuff (no data, just holds our cb information) */ if ((skb = sock_alloc_send_skb(sk, 0, - msg->msg_flags & MSG_DONTWAIT, - &err)) == NULL) { - mutex_unlock(&econet_mutex); + msg->msg_flags & MSG_DONTWAIT, &err)) == NULL) return err; - } eb = (struct ec_cb *)&skb->cb; @@ -502,8 +475,6 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, #else err = -EPROTOTYPE; #endif - mutex_unlock(&econet_mutex); - return err; } @@ -514,25 +485,18 @@ static int econet_sendmsg(struct kiocb *iocb, struct socket *sock, static int econet_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len, int peer) { - struct sock *sk; - struct econet_sock *eo; + struct sock *sk = sock->sk; + struct econet_sock *eo = ec_sk(sk); struct sockaddr_ec *sec = (struct sockaddr_ec *)uaddr; if (peer) return -EOPNOTSUPP; - mutex_lock(&econet_mutex); - - sk = sock->sk; - eo = ec_sk(sk); - sec->sec_family = AF_ECONET; sec->port = eo->port; sec->addr.station = eo->station; sec->addr.net = eo->net; - mutex_unlock(&econet_mutex); - *uaddr_len = sizeof(*sec); return 0; } @@ -558,13 +522,10 @@ static void econet_destroy_timer(unsigned long data) static int econet_release(struct socket *sock) { - struct sock *sk; - - mutex_lock(&econet_mutex); + struct sock *sk = sock->sk; - sk = sock->sk; if (!sk) - goto out_unlock; + return 0; econet_remove_socket(&econet_sklist, sk); @@ -588,14 +549,10 @@ static int econet_release(struct socket *sock) sk->sk_timer.expires = jiffies + HZ; sk->sk_timer.function = econet_destroy_timer; add_timer(&sk->sk_timer); - - goto out_unlock; + return 0; } sk_free(sk); - -out_unlock: - mutex_unlock(&econet_mutex); return 0; } @@ -651,7 +608,6 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg) struct ec_device *edev; struct net_device *dev; struct sockaddr_ec *sec; - int err; /* * Fetch the caller's info block into kernel space @@ -665,34 +621,38 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg) sec = (struct sockaddr_ec *)&ifr.ifr_addr; - mutex_lock(&econet_mutex); - - err = 0; - switch (cmd) { + switch (cmd) + { case SIOCSIFADDR: edev = dev->ec_ptr; - if (edev == NULL) { + if (edev == NULL) + { /* Magic up a new one. */ - edev = kzalloc(sizeof(struct ec_device), GFP_KERNEL); + edev = kmalloc(sizeof(struct ec_device), GFP_KERNEL); if (edev == NULL) { - err = -ENOMEM; - break; + printk("af_ec: memory squeeze.\n"); + dev_put(dev); + return -ENOMEM; } + memset(edev, 0, sizeof(struct ec_device)); dev->ec_ptr = edev; - } else + } + else net2dev_map[edev->net] = NULL; edev->station = sec->addr.station; edev->net = sec->addr.net; net2dev_map[sec->addr.net] = dev; if (!net2dev_map[0]) net2dev_map[0] = dev; - break; + dev_put(dev); + return 0; case SIOCGIFADDR: edev = dev->ec_ptr; - if (edev == NULL) { - err = -ENODEV; - break; + if (edev == NULL) + { + dev_put(dev); + return -ENODEV; } memset(sec, 0, sizeof(struct sockaddr_ec)); sec->addr.station = edev->station; @@ -700,19 +660,12 @@ static int ec_dev_ioctl(struct socket *sock, unsigned int cmd, void __user *arg) sec->sec_family = AF_ECONET; dev_put(dev); if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) - err = -EFAULT; - break; - - default: - err = -EINVAL; - break; + return -EFAULT; + return 0; } - mutex_unlock(&econet_mutex); - dev_put(dev); - - return err; + return -EINVAL; } /* @@ -746,7 +699,7 @@ static struct net_proto_family econet_family_ops = { .owner = THIS_MODULE, }; -static const struct proto_ops econet_ops = { +static const struct proto_ops SOCKOPS_WRAPPED(econet_ops) = { .family = PF_ECONET, .owner = THIS_MODULE, .release = econet_release, @@ -767,6 +720,9 @@ static const struct proto_ops econet_ops = { .sendpage = sock_no_sendpage, }; +#include +SOCKOPS_WRAP(econet, PF_ECONET); + #if defined(CONFIG_ECONET_AUNUDP) || defined(CONFIG_ECONET_NATIVE) /* * Find the listening socket, if any, for the given data.