nfsd: simplify fh_verify access checks
[safe/jmp/linux-2.6] / net / irda / irlap_frame.c
index 3c5a68e..7af2e74 100644 (file)
@@ -18,7 +18,7 @@
  *     published by the Free Software Foundation; either version 2 of
  *     the License, or (at your option) any later version.
  *
- *     Neither Dag Brattli nor University of Tromsø admit liability nor
+ *     Neither Dag Brattli nor University of Tromsø admit liability nor
  *     provide warranty for any of this software. This material is
  *     provided "AS-IS" and at no charge.
  *
@@ -101,6 +101,13 @@ void irlap_queue_xmit(struct irlap_cb *self, struct sk_buff *skb)
 
        irlap_insert_info(self, skb);
 
+       if (unlikely(self->mode & IRDA_MODE_MONITOR)) {
+               IRDA_DEBUG(3, "%s(): %s is in monitor mode\n", __func__,
+                          self->netdev->name);
+               dev_kfree_skb(skb);
+               return;
+       }
+
        dev_queue_xmit(skb);
 }
 
@@ -137,7 +144,7 @@ void irlap_send_snrm_frame(struct irlap_cb *self, struct qos_info *qos)
        frame->control = SNRM_CMD | PF_BIT;
 
        /*
-        *  If we are establishing a connection then insert QoS paramerters
+        *  If we are establishing a connection then insert QoS parameters
         */
        if (qos) {
                skb_put(tx_skb, 9); /* 25 left */
@@ -175,7 +182,7 @@ static void irlap_recv_snrm_cmd(struct irlap_cb *self, struct sk_buff *skb,
                /* Check if the new connection address is valid */
                if ((info->caddr == 0x00) || (info->caddr == 0xfe)) {
                        IRDA_DEBUG(3, "%s(), invalid connection address!\n",
-                                  __FUNCTION__);
+                                  __func__);
                        return;
                }
 
@@ -186,7 +193,7 @@ static void irlap_recv_snrm_cmd(struct irlap_cb *self, struct sk_buff *skb,
                /* Only accept if addressed directly to us */
                if (info->saddr != self->saddr) {
                        IRDA_DEBUG(2, "%s(), not addressed to us!\n",
-                                  __FUNCTION__);
+                                  __func__);
                        return;
                }
                irlap_do_event(self, RECV_SNRM_CMD, skb, info);
@@ -208,7 +215,7 @@ void irlap_send_ua_response_frame(struct irlap_cb *self, struct qos_info *qos)
        struct ua_frame *frame;
        int ret;
 
-       IRDA_DEBUG(2, "%s() <%ld>\n", __FUNCTION__, jiffies);
+       IRDA_DEBUG(2, "%s() <%ld>\n", __func__, jiffies);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
@@ -283,7 +290,7 @@ void irlap_send_disc_frame(struct irlap_cb *self)
        struct sk_buff *tx_skb = NULL;
        struct disc_frame *frame;
 
-       IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(3, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
@@ -314,7 +321,7 @@ void irlap_send_discovery_xid_frame(struct irlap_cb *self, int S, __u8 s,
        __u32 bcast = BROADCAST;
        __u8 *info;
 
-       IRDA_DEBUG(4, "%s(), s=%d, S=%d, command=%d\n", __FUNCTION__,
+       IRDA_DEBUG(4, "%s(), s=%d, S=%d, command=%d\n", __func__,
                   s, S, command);
 
        IRDA_ASSERT(self != NULL, return;);
@@ -407,13 +414,13 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
        __u8 *discovery_info;
        char *text;
 
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
 
        if (!pskb_may_pull(skb, sizeof(struct xid_frame))) {
-               IRDA_ERROR("%s: frame too short!\n", __FUNCTION__);
+               IRDA_ERROR("%s: frame too short!\n", __func__);
                return;
        }
 
@@ -425,12 +432,12 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
        /* Make sure frame is addressed to us */
        if ((info->saddr != self->saddr) && (info->saddr != BROADCAST)) {
                IRDA_DEBUG(0, "%s(), frame is not addressed to us!\n",
-                          __FUNCTION__);
+                          __func__);
                return;
        }
 
        if ((discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC)) == NULL) {
-               IRDA_WARNING("%s: kmalloc failed!\n", __FUNCTION__);
+               IRDA_WARNING("%s: kmalloc failed!\n", __func__);
                return;
        }
 
@@ -438,7 +445,7 @@ static void irlap_recv_discovery_xid_rsp(struct irlap_cb *self,
        discovery->data.saddr = self->saddr;
        discovery->timestamp = jiffies;
 
-       IRDA_DEBUG(4, "%s(), daddr=%08x\n", __FUNCTION__,
+       IRDA_DEBUG(4, "%s(), daddr=%08x\n", __func__,
                   discovery->data.daddr);
 
        discovery_info = skb_pull(skb, sizeof(struct xid_frame));
@@ -484,7 +491,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
        char *text;
 
        if (!pskb_may_pull(skb, sizeof(struct xid_frame))) {
-               IRDA_ERROR("%s: frame too short!\n", __FUNCTION__);
+               IRDA_ERROR("%s: frame too short!\n", __func__);
                return;
        }
 
@@ -496,7 +503,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
        /* Make sure frame is addressed to us */
        if ((info->saddr != self->saddr) && (info->saddr != BROADCAST)) {
                IRDA_DEBUG(0, "%s(), frame is not addressed to us!\n",
-                          __FUNCTION__);
+                          __func__);
                return;
        }
 
@@ -529,7 +536,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
                if((discovery_info == NULL) ||
                   !pskb_may_pull(skb, 3)) {
                        IRDA_ERROR("%s: discovery frame too short!\n",
-                                  __FUNCTION__);
+                                  __func__);
                        return;
                }
 
@@ -538,7 +545,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
                 */
                discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
                if (!discovery) {
-                       IRDA_WARNING("%s: unable to malloc!\n", __FUNCTION__);
+                       IRDA_WARNING("%s: unable to malloc!\n", __func__);
                        return;
                }
 
@@ -650,7 +657,7 @@ static void irlap_recv_rnr_frame(struct irlap_cb *self, struct sk_buff *skb,
 {
        info->nr = skb->data[1] >> 5;
 
-       IRDA_DEBUG(4, "%s(), nr=%d, %ld\n", __FUNCTION__, info->nr, jiffies);
+       IRDA_DEBUG(4, "%s(), nr=%d, %ld\n", __func__, info->nr, jiffies);
 
        if (command)
                irlap_do_event(self, RECV_RNR_CMD, skb, info);
@@ -661,7 +668,7 @@ static void irlap_recv_rnr_frame(struct irlap_cb *self, struct sk_buff *skb,
 static void irlap_recv_rej_frame(struct irlap_cb *self, struct sk_buff *skb,
                                 struct irlap_info *info, int command)
 {
-       IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(0, "%s()\n", __func__);
 
        info->nr = skb->data[1] >> 5;
 
@@ -675,7 +682,7 @@ static void irlap_recv_rej_frame(struct irlap_cb *self, struct sk_buff *skb,
 static void irlap_recv_srej_frame(struct irlap_cb *self, struct sk_buff *skb,
                                  struct irlap_info *info, int command)
 {
-       IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(0, "%s()\n", __func__);
 
        info->nr = skb->data[1] >> 5;
 
@@ -689,7 +696,7 @@ static void irlap_recv_srej_frame(struct irlap_cb *self, struct sk_buff *skb,
 static void irlap_recv_disc_frame(struct irlap_cb *self, struct sk_buff *skb,
                                  struct irlap_info *info, int command)
 {
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        /* Check if this is a command or a response frame */
        if (command)
@@ -748,7 +755,7 @@ void irlap_send_data_primary(struct irlap_cb *self, struct sk_buff *skb)
 
                irlap_send_i_frame( self, tx_skb, CMD_FRAME);
        } else {
-               IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
+               IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __func__);
                irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
                self->window -= 1;
        }
@@ -798,16 +805,19 @@ void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
                self->vs = (self->vs + 1) % 8;
                self->ack_required = FALSE;
 
+               irlap_next_state(self, LAP_NRM_P);
                irlap_send_i_frame(self, tx_skb, CMD_FRAME);
        } else {
-               IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
+               IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __func__);
 
                if (self->ack_required) {
                        irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
+                       irlap_next_state(self, LAP_NRM_P);
                        irlap_send_rr_frame(self, CMD_FRAME);
                        self->ack_required = FALSE;
                } else {
                        skb->data[1] |= PF_BIT;
+                       irlap_next_state(self, LAP_NRM_P);
                        irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
                }
        }
@@ -825,7 +835,7 @@ void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
         * See max_line_capacities[][] in qos.c for details. Jean II */
        transmission_time -= (self->final_timeout * self->bytes_left
                              / self->line_capacity);
-       IRDA_DEBUG(4, "%s() adjusting transmission_time : ft=%d, bl=%d, lc=%d -> tt=%d\n", __FUNCTION__, self->final_timeout, self->bytes_left, self->line_capacity, transmission_time);
+       IRDA_DEBUG(4, "%s() adjusting transmission_time : ft=%d, bl=%d, lc=%d -> tt=%d\n", __func__, self->final_timeout, self->bytes_left, self->line_capacity, transmission_time);
 
        /* We are allowed to transmit a maximum number of bytes again. */
        self->bytes_left = self->line_capacity;
@@ -972,17 +982,12 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
 {
        struct sk_buff *tx_skb;
        struct sk_buff *skb;
-       int count;
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
 
-       /* Initialize variables */
-       count = skb_queue_len(&self->wx_list);
-
        /*  Resend unacknowledged frame(s) */
-       skb = skb_peek(&self->wx_list);
-       while (skb != NULL) {
+       skb_queue_walk(&self->wx_list, skb) {
                irlap_wait_min_turn_around(self, &self->qos_tx);
 
                /* We copy the skb to be retransmitted since we will have to
@@ -991,7 +996,7 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
                /* tx_skb = skb_clone( skb, GFP_ATOMIC); */
                tx_skb = skb_copy(skb, GFP_ATOMIC);
                if (!tx_skb) {
-                       IRDA_DEBUG(0, "%s(), unable to copy\n", __FUNCTION__);
+                       IRDA_DEBUG(0, "%s(), unable to copy\n", __func__);
                        return;
                }
 
@@ -1001,21 +1006,12 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
                /*
                 *  Set poll bit on the last frame retransmitted
                 */
-               if (count-- == 1)
+               if (skb_queue_is_last(&self->wx_list, skb))
                        tx_skb->data[1] |= PF_BIT; /* Set p/f bit */
                else
                        tx_skb->data[1] &= ~PF_BIT; /* Clear p/f bit */
 
                irlap_send_i_frame(self, tx_skb, command);
-
-               /*
-                *  If our skb is the last buffer in the list, then
-                *  we are finished, if not, move to the next sk-buffer
-                */
-               if (skb == skb_peek_tail(&self->wx_list))
-                       skb = NULL;
-               else
-                       skb = skb->next;
        }
 #if 0 /* Not yet */
        /*
@@ -1023,7 +1019,7 @@ void irlap_resend_rejected_frames(struct irlap_cb *self, int command)
         */
        while (!skb_queue_empty(&self->txq)) {
 
-               IRDA_DEBUG(0, "%s(), sending additional frames!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), sending additional frames!\n", __func__);
                if (self->window > 0) {
                        skb = skb_dequeue( &self->txq);
                        IRDA_ASSERT(skb != NULL, return;);
@@ -1063,7 +1059,7 @@ void irlap_resend_rejected_frame(struct irlap_cb *self, int command)
                /* tx_skb = skb_clone( skb, GFP_ATOMIC); */
                tx_skb = skb_copy(skb, GFP_ATOMIC);
                if (!tx_skb) {
-                       IRDA_DEBUG(0, "%s(), unable to copy\n", __FUNCTION__);
+                       IRDA_DEBUG(0, "%s(), unable to copy\n", __func__);
                        return;
                }
 
@@ -1086,7 +1082,7 @@ void irlap_resend_rejected_frame(struct irlap_cb *self, int command)
 void irlap_send_ui_frame(struct irlap_cb *self, struct sk_buff *skb,
                         __u8 caddr, int command)
 {
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
@@ -1146,7 +1142,7 @@ static inline void irlap_recv_i_frame(struct irlap_cb *self,
 static void irlap_recv_ui_frame(struct irlap_cb *self, struct sk_buff *skb,
                                struct irlap_info *info)
 {
-       IRDA_DEBUG( 4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG( 4, "%s()\n", __func__);
 
        info->pf = skb->data[1] & PF_BIT;      /* Final bit */
 
@@ -1165,7 +1161,7 @@ static void irlap_recv_frmr_frame(struct irlap_cb *self, struct sk_buff *skb,
        __u8 *frame;
        int w, x, y, z;
 
-       IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(0, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == LAP_MAGIC, return;);
@@ -1173,7 +1169,7 @@ static void irlap_recv_frmr_frame(struct irlap_cb *self, struct sk_buff *skb,
        IRDA_ASSERT(info != NULL, return;);
 
        if (!pskb_may_pull(skb, 4)) {
-               IRDA_ERROR("%s: frame too short!\n", __FUNCTION__);
+               IRDA_ERROR("%s: frame too short!\n", __func__);
                return;
        }
 
@@ -1259,10 +1255,10 @@ static void irlap_recv_test_frame(struct irlap_cb *self, struct sk_buff *skb,
 {
        struct test_frame *frame;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        if (!pskb_may_pull(skb, sizeof(*frame))) {
-               IRDA_ERROR("%s: frame too short!\n", __FUNCTION__);
+               IRDA_ERROR("%s: frame too short!\n", __func__);
                return;
        }
        frame = (struct test_frame *) skb->data;
@@ -1271,7 +1267,7 @@ static void irlap_recv_test_frame(struct irlap_cb *self, struct sk_buff *skb,
        if (info->caddr == CBROADCAST) {
                if (skb->len < sizeof(struct test_frame)) {
                        IRDA_DEBUG(0, "%s() test frame too short!\n",
-                                  __FUNCTION__);
+                                  __func__);
                        return;
                }
 
@@ -1315,30 +1311,30 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
        struct irlap_cb *self;
        int command;
        __u8 control;
+       int ret = -1;
+
+       if (!net_eq(dev_net(dev), &init_net))
+               goto out;
 
        /* FIXME: should we get our own field? */
        self = (struct irlap_cb *) dev->atalk_ptr;
 
        /* If the net device is down, then IrLAP is gone! */
-       if (!self || self->magic != LAP_MAGIC) {
-               dev_kfree_skb(skb);
-               return -1;
-       }
+       if (!self || self->magic != LAP_MAGIC)
+               goto err;
 
        /* We are no longer an "old" protocol, so we need to handle
         * share and non linear skbs. This should never happen, so
         * we don't need to be clever about it. Jean II */
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
-               IRDA_ERROR("%s: can't clone shared skb!\n", __FUNCTION__);
-               dev_kfree_skb(skb);
-               return -1;
+               IRDA_ERROR("%s: can't clone shared skb!\n", __func__);
+               goto err;
        }
 
        /* Check if frame is large enough for parsing */
        if (!pskb_may_pull(skb, 2)) {
-               IRDA_ERROR("%s: frame too short!\n", __FUNCTION__);
-               dev_kfree_skb(skb);
-               return -1;
+               IRDA_ERROR("%s: frame too short!\n", __func__);
+               goto err;
        }
 
        command    = skb->data[0] & CMD_FRAME;
@@ -1352,7 +1348,7 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
        /*  First we check if this frame has a valid connection address */
        if ((info.caddr != self->caddr) && (info.caddr != CBROADCAST)) {
                IRDA_DEBUG(0, "%s(), wrong connection address!\n",
-                          __FUNCTION__);
+                          __func__);
                goto out;
        }
        /*
@@ -1387,7 +1383,7 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
                        break;
                default:
                        IRDA_WARNING("%s: Unknown S-frame %02x received!\n",
-                               __FUNCTION__, info.control);
+                               __func__, info.control);
                        break;
                }
                goto out;
@@ -1425,11 +1421,13 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
                break;
        default:
                IRDA_WARNING("%s: Unknown frame %02x received!\n",
-                               __FUNCTION__, info.control);
+                               __func__, info.control);
                break;
        }
 out:
+       ret = 0;
+err:
        /* Always drop our reference on the skb */
        dev_kfree_skb(skb);
-       return 0;
+       return ret;
 }