Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / irda / af_irda.c
index f415a4e..2f37c9f 100644 (file)
@@ -43,6 +43,7 @@
  ********************************************************************/
 
 #include <linux/config.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <asm/uaccess.h>
 
 #include <net/sock.h>
-#include <net/tcp.h>
+#include <net/tcp_states.h>
 
 #include <net/irda/af_irda.h>
 
 static int irda_create(struct socket *sock, int protocol);
 
-static struct proto_ops irda_stream_ops;
-static struct proto_ops irda_seqpacket_ops;
-static struct proto_ops irda_dgram_ops;
+static const struct proto_ops irda_stream_ops;
+static const struct proto_ops irda_seqpacket_ops;
+static const struct proto_ops irda_dgram_ops;
 
 #ifdef CONFIG_IRDA_ULTRA
-static struct proto_ops irda_ultra_ops;
+static const struct proto_ops irda_ultra_ops;
 #define ULTRA_MAX_DATA 382
 #endif /* CONFIG_IRDA_ULTRA */
 
@@ -87,11 +88,9 @@ static int irda_data_indication(void *instance, void *sap, struct sk_buff *skb)
 
        IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
-       self = (struct irda_sock *) instance;
-       ASSERT(self != NULL, return -1;);
-
-       sk = self->sk;
-       ASSERT(sk != NULL, return -1;);
+       self = instance;
+       sk = instance;
+       IRDA_ASSERT(sk != NULL, return -1;);
 
        err = sock_queue_rcv_skb(sk, skb);
        if (err) {
@@ -117,7 +116,7 @@ static void irda_disconnect_indication(void *instance, void *sap,
        struct irda_sock *self;
        struct sock *sk;
 
-       self = (struct irda_sock *) instance;
+       self = instance;
 
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
@@ -125,7 +124,7 @@ static void irda_disconnect_indication(void *instance, void *sap,
        if(skb)
                dev_kfree_skb(skb);
 
-       sk = self->sk;
+       sk = instance;
        if (sk == NULL) {
                IRDA_DEBUG(0, "%s(%p) : BUG : sk is NULL\n",
                           __FUNCTION__, self);
@@ -183,11 +182,11 @@ static void irda_connect_confirm(void *instance, void *sap,
        struct irda_sock *self;
        struct sock *sk;
 
-       self = (struct irda_sock *) instance;
+       self = instance;
 
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
-       sk = self->sk;
+       sk = instance;
        if (sk == NULL) {
                dev_kfree_skb(skb);
                return;
@@ -206,14 +205,16 @@ static void irda_connect_confirm(void *instance, void *sap,
        switch (sk->sk_type) {
        case SOCK_STREAM:
                if (max_sdu_size != 0) {
-                       ERROR("%s: max_sdu_size must be 0\n", __FUNCTION__);
+                       IRDA_ERROR("%s: max_sdu_size must be 0\n",
+                                  __FUNCTION__);
                        return;
                }
                self->max_data_size = irttp_get_max_seg_size(self->tsap);
                break;
        case SOCK_SEQPACKET:
                if (max_sdu_size == 0) {
-                       ERROR("%s: max_sdu_size cannot be 0\n", __FUNCTION__);
+                       IRDA_ERROR("%s: max_sdu_size cannot be 0\n",
+                                  __FUNCTION__);
                        return;
                }
                self->max_data_size = max_sdu_size;
@@ -245,11 +246,11 @@ static void irda_connect_indication(void *instance, void *sap,
        struct irda_sock *self;
        struct sock *sk;
 
-       self = (struct irda_sock *) instance;
+       self = instance;
 
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
-       sk = self->sk;
+       sk = instance;
        if (sk == NULL) {
                dev_kfree_skb(skb);
                return;
@@ -265,7 +266,8 @@ static void irda_connect_indication(void *instance, void *sap,
        switch (sk->sk_type) {
        case SOCK_STREAM:
                if (max_sdu_size != 0) {
-                       ERROR("%s: max_sdu_size must be 0\n", __FUNCTION__);
+                       IRDA_ERROR("%s: max_sdu_size must be 0\n",
+                                  __FUNCTION__);
                        kfree_skb(skb);
                        return;
                }
@@ -273,7 +275,8 @@ static void irda_connect_indication(void *instance, void *sap,
                break;
        case SOCK_SEQPACKET:
                if (max_sdu_size == 0) {
-                       ERROR("%s: max_sdu_size cannot be 0\n", __FUNCTION__);
+                       IRDA_ERROR("%s: max_sdu_size cannot be 0\n",
+                                  __FUNCTION__);
                        kfree_skb(skb);
                        return;
                }
@@ -298,13 +301,13 @@ static void irda_connect_indication(void *instance, void *sap,
  *    Accept incoming connection
  *
  */
-void irda_connect_response(struct irda_sock *self)
+static void irda_connect_response(struct irda_sock *self)
 {
        struct sk_buff *skb;
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        skb = dev_alloc_skb(64);
        if (skb == NULL) {
@@ -332,11 +335,9 @@ static void irda_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
-       self = (struct irda_sock *) instance;
-       ASSERT(self != NULL, return;);
-
-       sk = self->sk;
-       ASSERT(sk != NULL, return;);
+       self = instance;
+       sk = instance;
+       IRDA_ASSERT(sk != NULL, return;);
 
        switch (flow) {
        case FLOW_STOP:
@@ -373,7 +374,7 @@ static void irda_getvalue_confirm(int result, __u16 obj_id,
 
        self = (struct irda_sock *) priv;
        if (!self) {
-               WARNING("%s: lost myself!\n", __FUNCTION__);
+               IRDA_WARNING("%s: lost myself!\n", __FUNCTION__);
                return;
        }
 
@@ -422,7 +423,7 @@ static void irda_selective_discovery_indication(discinfo_t *discovery,
 
        self = (struct irda_sock *) priv;
        if (!self) {
-               WARNING("%s: lost myself!\n", __FUNCTION__);
+               IRDA_WARNING("%s: lost myself!\n", __FUNCTION__);
                return;
        }
 
@@ -448,7 +449,7 @@ static void irda_discovery_timeout(u_long priv)
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
        self = (struct irda_sock *) priv;
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        /* Nothing for the caller */
        self->cachelog = NULL;
@@ -470,7 +471,7 @@ static int irda_open_tsap(struct irda_sock *self, __u8 tsap_sel, char *name)
        notify_t notify;
 
        if (self->tsap) {
-               WARNING("%s: busy!\n", __FUNCTION__);
+               IRDA_WARNING("%s: busy!\n", __FUNCTION__);
                return -EBUSY;
        }
 
@@ -510,7 +511,7 @@ static int irda_open_lsap(struct irda_sock *self, int pid)
        notify_t notify;
 
        if (self->lsap) {
-               WARNING("%s(), busy!\n", __FUNCTION__);
+               IRDA_WARNING("%s(), busy!\n", __FUNCTION__);
                return -EBUSY;
        }
 
@@ -545,10 +546,11 @@ static int irda_find_lsap_sel(struct irda_sock *self, char *name)
 {
        IRDA_DEBUG(2, "%s(%p, %s)\n", __FUNCTION__, self, name);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        if (self->iriap) {
-               WARNING("%s(): busy with a previous query\n", __FUNCTION__);
+               IRDA_WARNING("%s(): busy with a previous query\n",
+                            __FUNCTION__);
                return -EBUSY;
        }
 
@@ -633,7 +635,7 @@ static int irda_discover_daddr_and_lsap_sel(struct irda_sock *self, char *name)
 
        IRDA_DEBUG(2, "%s(), name=%s\n", __FUNCTION__, name);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        /* Ask lmp for the current discovery log
         * Note : we have to use irlmp_get_discoveries(), as opposed
@@ -782,7 +784,7 @@ static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
        struct irda_sock *self = irda_sk(sk);
        int err;
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
@@ -839,7 +841,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
 
        IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        err = irda_create(newsock, sk->sk_protocol);
        if (err)
@@ -908,7 +910,7 @@ static int irda_accept(struct socket *sock, struct socket *newsock, int flags)
        newsk->sk_state = TCP_ESTABLISHED;
 
        new = irda_sk(newsk);
-       ASSERT(new != NULL, return -1;);
+       IRDA_ASSERT(new != NULL, return -1;);
 
        /* Now attach up the new socket */
        new->tsap = irttp_dup(self->tsap, new);
@@ -1012,11 +1014,23 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
                self->daddr = addr->sir_addr;
                IRDA_DEBUG(1, "%s(), daddr = %08x\n", __FUNCTION__, self->daddr);
 
-               /* Query remote LM-IAS */
-               err = irda_find_lsap_sel(self, addr->sir_name);
-               if (err) {
-                       IRDA_DEBUG(0, "%s(), connect failed!\n", __FUNCTION__);
-                       return err;
+               /* If we don't have a valid service name, we assume the
+                * user want to connect on a specific LSAP. Prevent
+                * the use of invalid LSAPs (IrLMP 1.1 p10). Jean II */
+               if((addr->sir_name[0] != '\0') ||
+                  (addr->sir_lsap_sel >= 0x70)) {
+                       /* Query remote LM-IAS using service name */
+                       err = irda_find_lsap_sel(self, addr->sir_name);
+                       if (err) {
+                               IRDA_DEBUG(0, "%s(), connect failed!\n", __FUNCTION__);
+                               return err;
+                       }
+               } else {
+                       /* Directly connect to the remote LSAP
+                        * specified by the sir_lsap field.
+                        * Please use with caution, in IrDA LSAPs are
+                        * dynamic and there is no "well-known" LSAP. */
+                       self->dtsap_sel = addr->sir_lsap_sel;
                }
        }
 
@@ -1058,6 +1072,12 @@ static int irda_connect(struct socket *sock, struct sockaddr *uaddr,
        return 0;
 }
 
+static struct proto irda_proto = {
+       .name     = "IRDA",
+       .owner    = THIS_MODULE,
+       .obj_size = sizeof(struct irda_sock),
+};
+
 /*
  * Function irda_create (sock, protocol)
  *
@@ -1082,28 +1102,19 @@ static int irda_create(struct socket *sock, int protocol)
        }
 
        /* Allocate networking socket */
-       if ((sk = sk_alloc(PF_IRDA, GFP_ATOMIC, 1, NULL)) == NULL)
-               return -ENOMEM;
-
-       /* Allocate IrDA socket */
-       self = sk->sk_protinfo = kmalloc(sizeof(struct irda_sock), GFP_ATOMIC);
-       if (self == NULL) {
-               sk_free(sk);
+       sk = sk_alloc(PF_IRDA, GFP_ATOMIC, &irda_proto, 1);
+       if (sk == NULL)
                return -ENOMEM;
-       }
-       memset(self, 0, sizeof(struct irda_sock));
 
+       self = irda_sk(sk);
        IRDA_DEBUG(2, "%s() : self is %p\n", __FUNCTION__, self);
 
        init_waitqueue_head(&self->query_wait);
 
        /* Initialise networking socket struct */
        sock_init_data(sock, sk);       /* Note : set sk->sk_refcnt to 1 */
-       sk_set_owner(sk, THIS_MODULE);
        sk->sk_family = PF_IRDA;
        sk->sk_protocol = protocol;
-       /* Link networking socket and IrDA socket structs together */
-       self->sk = sk;
 
        switch (sock->type) {
        case SOCK_STREAM:
@@ -1131,7 +1142,8 @@ static int irda_create(struct socket *sock, int protocol)
                        self->max_sdu_size_rx = TTP_SAR_UNBOUND;
                        break;
                default:
-                       ERROR("%s: protocol not supported!\n", __FUNCTION__);
+                       IRDA_ERROR("%s: protocol not supported!\n",
+                                  __FUNCTION__);
                        return -ESOCKTNOSUPPORT;
                }
                break;
@@ -1155,11 +1167,11 @@ static int irda_create(struct socket *sock, int protocol)
  *    Destroy socket
  *
  */
-void irda_destroy_socket(struct irda_sock *self)
+static void irda_destroy_socket(struct irda_sock *self)
 {
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        /* Unregister with IrLMP */
        irlmp_unregister_client(self->ckey);
@@ -1187,7 +1199,6 @@ void irda_destroy_socket(struct irda_sock *self)
                self->lsap = NULL;
        }
 #endif /* CONFIG_IRDA_ULTRA */
-       kfree(self);
 }
 
 /*
@@ -1208,8 +1219,6 @@ static int irda_release(struct socket *sock)
 
        /* Destroy IrDA socket */
        irda_destroy_socket(irda_sk(sk));
-       /* Prevent sock_def_destruct() to create havoc */
-       sk->sk_protinfo = NULL;
 
        sock_orphan(sk);
        sock->sk   = NULL;
@@ -1281,7 +1290,7 @@ static int irda_sendmsg(struct kiocb *iocb, struct socket *sock,
                return -ENOTCONN;
 
        self = irda_sk(sk);
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        /* Check if IrTTP is wants us to slow down */
 
@@ -1293,7 +1302,7 @@ static int irda_sendmsg(struct kiocb *iocb, struct socket *sock,
        if (sk->sk_state != TCP_ESTABLISHED)
                return -ENOTCONN;
 
-       /* Check that we don't send out to big frames */
+       /* Check that we don't send out too big frames */
        if (len > self->max_data_size) {
                IRDA_DEBUG(2, "%s(), Chopping frame from %zd to %d bytes!\n",
                           __FUNCTION__, len, self->max_data_size);
@@ -1344,7 +1353,7 @@ static int irda_recvmsg_dgram(struct kiocb *iocb, struct socket *sock,
 
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
                                flags & MSG_DONTWAIT, &err);
@@ -1396,7 +1405,7 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
 
        IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        if (sock->flags & __SO_ACCEPTCON)
                return(-EINVAL);
@@ -1430,8 +1439,9 @@ static int irda_recvmsg_stream(struct kiocb *iocb, struct socket *sock,
                        /*
                         *      POSIX 1003.1g mandates this order.
                         */
-                       if (sk->sk_err)
-                               ret = sock_error(sk);
+                       ret = sock_error(sk);
+                       if (ret)
+                               break;
                        else if (sk->sk_shutdown & RCV_SHUTDOWN)
                                ;
                        else if (noblock)
@@ -1533,10 +1543,10 @@ static int irda_sendmsg_dgram(struct kiocb *iocb, struct socket *sock,
                return -ENOTCONN;
 
        self = irda_sk(sk);
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        /*
-        * Check that we don't send out to big frames. This is an unreliable
+        * Check that we don't send out too big frames. This is an unreliable
         * service, so we have no fragmentation and no coalescence
         */
        if (len > self->max_data_size) {
@@ -1602,7 +1612,7 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
        }
 
        self = irda_sk(sk);
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        /* Check if an address was specified with sendto. Jean II */
        if (msg->msg_name) {
@@ -1632,7 +1642,7 @@ static int irda_sendmsg_ultra(struct kiocb *iocb, struct socket *sock,
        }
 
        /*
-        * Check that we don't send out to big frames. This is an unreliable
+        * Check that we don't send out too big frames. This is an unreliable
         * service, so we have no fragmentation and no coalescence
         */
        if (len > self->max_data_size) {
@@ -1675,7 +1685,7 @@ static int irda_shutdown(struct socket *sock, int how)
        struct sock *sk = sock->sk;
        struct irda_sock *self = irda_sk(sk);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        IRDA_DEBUG(1, "%s(%p)\n", __FUNCTION__, self);
 
@@ -1813,13 +1823,26 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                return -EINVAL;
        default:
                IRDA_DEBUG(1, "%s(), doing device ioctl!\n", __FUNCTION__);
-               return dev_ioctl(cmd, (void __user *) arg);
+               return -ENOIOCTLCMD;
        }
 
        /*NOTREACHED*/
        return 0;
 }
 
+#ifdef CONFIG_COMPAT
+/*
+ * Function irda_ioctl (sock, cmd, arg)
+ */
+static int irda_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       /*
+        * All IRDA's ioctl are standard ones.
+        */
+       return -ENOIOCTLCMD;
+}
+#endif
+
 /*
  * Function irda_setsockopt (sock, level, optname, optval, optlen)
  *
@@ -1836,7 +1859,7 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
        struct ias_attrib *     ias_attr;       /* Attribute in IAS object */
        int opt;
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        IRDA_DEBUG(2, "%s(%p)\n", __FUNCTION__, self);
 
@@ -2005,7 +2028,7 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
                }
 
                /* Remove the attribute (and maybe the object) */
-               irias_delete_attrib(ias_obj, ias_attr);
+               irias_delete_attrib(ias_obj, ias_attr, 1);
                kfree(ias_opt);
                break;
        case IRLMP_MAX_SDU_SIZE:
@@ -2021,8 +2044,8 @@ static int irda_setsockopt(struct socket *sock, int level, int optname,
                                   __FUNCTION__, opt);
                        self->max_sdu_size_rx = opt;
                } else {
-                       WARNING("%s: not allowed to set MAXSDUSIZE for this socket type!\n",
-                                       __FUNCTION__);
+                       IRDA_WARNING("%s: not allowed to set MAXSDUSIZE for this socket type!\n",
+                                    __FUNCTION__);
                        return -ENOPROTOOPT;
                }
                break;
@@ -2296,8 +2319,8 @@ bed:
 
                /* Check that we can proceed with IAP */
                if (self->iriap) {
-                       WARNING("%s: busy with a previous query\n",
-                                       __FUNCTION__);
+                       IRDA_WARNING("%s: busy with a previous query\n",
+                                    __FUNCTION__);
                        kfree(ias_opt);
                        return -EBUSY;
                }
@@ -2455,7 +2478,7 @@ static struct net_proto_family irda_family_ops = {
        .owner  = THIS_MODULE,
 };
 
-static struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
+static const struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
        .family =       PF_IRDA,
        .owner =        THIS_MODULE,
        .release =      irda_release,
@@ -2466,6 +2489,9 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
        .getname =      irda_getname,
        .poll =         irda_poll,
        .ioctl =        irda_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = irda_compat_ioctl,
+#endif
        .listen =       irda_listen,
        .shutdown =     irda_shutdown,
        .setsockopt =   irda_setsockopt,
@@ -2476,7 +2502,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
        .sendpage =     sock_no_sendpage,
 };
 
-static struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
+static const struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
        .family =       PF_IRDA,
        .owner =        THIS_MODULE,
        .release =      irda_release,
@@ -2487,6 +2513,9 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
        .getname =      irda_getname,
        .poll =         datagram_poll,
        .ioctl =        irda_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = irda_compat_ioctl,
+#endif
        .listen =       irda_listen,
        .shutdown =     irda_shutdown,
        .setsockopt =   irda_setsockopt,
@@ -2497,7 +2526,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
        .sendpage =     sock_no_sendpage,
 };
 
-static struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
+static const struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
        .family =       PF_IRDA,
        .owner =        THIS_MODULE,
        .release =      irda_release,
@@ -2508,6 +2537,9 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
        .getname =      irda_getname,
        .poll =         datagram_poll,
        .ioctl =        irda_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = irda_compat_ioctl,
+#endif
        .listen =       irda_listen,
        .shutdown =     irda_shutdown,
        .setsockopt =   irda_setsockopt,
@@ -2519,7 +2551,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
 };
 
 #ifdef CONFIG_IRDA_ULTRA
-static struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
+static const struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
        .family =       PF_IRDA,
        .owner =        THIS_MODULE,
        .release =      irda_release,
@@ -2530,6 +2562,9 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
        .getname =      irda_getname,
        .poll =         datagram_poll,
        .ioctl =        irda_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = irda_compat_ioctl,
+#endif
        .listen =       sock_no_listen,
        .shutdown =     irda_shutdown,
        .setsockopt =   irda_setsockopt,
@@ -2557,9 +2592,12 @@ SOCKOPS_WRAP(irda_ultra, PF_IRDA);
  */
 int __init irsock_init(void)
 {
-       sock_register(&irda_family_ops);
+       int rc = proto_register(&irda_proto, 0);
 
-       return 0;
+       if (rc == 0)
+               rc = sock_register(&irda_family_ops);
+
+       return rc;
 }
 
 /*
@@ -2571,6 +2609,5 @@ int __init irsock_init(void)
 void __exit irsock_cleanup(void)
 {
        sock_unregister(PF_IRDA);
-
-        return;
+       proto_unregister(&irda_proto);
 }