ipv4: udp: fix short packet and bad checksum logging
[safe/jmp/linux-2.6] / net / irda / iriap.c
index a047265..79a1e5a 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.
  *
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/skbuff.h>
+#include <linux/fs.h>
 #include <linux/string.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
+#include <linux/slab.h>
 
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
@@ -43,7 +45,7 @@
 
 #ifdef CONFIG_IRDA_DEBUG
 /* FIXME: This one should go in irlmp.c */
-static const char *ias_charset_types[] = {
+static const char *const ias_charset_types[] = {
        "CS_ASCII",
        "CS_ISO_8859_1",
        "CS_ISO_8859_2",
@@ -78,10 +80,10 @@ static int iriap_data_indication(void *instance, void *sap,
 
 static void iriap_watchdog_timer_expired(void *data);
 
-static inline void iriap_start_watchdog_timer(struct iriap_cb *self, 
-                                             int timeout) 
+static inline void iriap_start_watchdog_timer(struct iriap_cb *self,
+                                             int timeout)
 {
-       irda_start_timer(&self->watchdog_timer, timeout, self, 
+       irda_start_timer(&self->watchdog_timer, timeout, self,
                         iriap_watchdog_timer_expired);
 }
 
@@ -107,7 +109,7 @@ int __init iriap_init(void)
        irias_objects = hashbin_new(HB_LOCK);
        if (!irias_objects) {
                IRDA_WARNING("%s: Can't allocate irias_objects hashbin!\n",
-                            __FUNCTION__);
+                            __func__);
                hashbin_delete(iriap, NULL);
                return -ENOMEM;
        }
@@ -138,7 +140,7 @@ int __init iriap_init(void)
         */
        server = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        if (!server) {
-               IRDA_DEBUG(0, "%s(), unable to open server\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), unable to open server\n", __func__);
                return -1;
        }
        iriap_register_lsap(server, LSAP_IAS, IAS_SERVER);
@@ -152,7 +154,7 @@ int __init iriap_init(void)
  *    Initializes the IrIAP layer, called by the module cleanup code in
  *    irmod.c
  */
-void __exit iriap_cleanup(void)
+void iriap_cleanup(void)
 {
        irlmp_unregister_service(service_handle);
 
@@ -170,18 +172,17 @@ struct iriap_cb *iriap_open(__u8 slsap_sel, int mode, void *priv,
 {
        struct iriap_cb *self;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
-       self = kmalloc(sizeof(struct iriap_cb), GFP_ATOMIC);
+       self = kzalloc(sizeof(*self), GFP_ATOMIC);
        if (!self) {
-               IRDA_WARNING("%s: Unable to kmalloc!\n", __FUNCTION__);
+               IRDA_WARNING("%s: Unable to kmalloc!\n", __func__);
                return NULL;
        }
 
        /*
         *  Initialize instance
         */
-       memset(self, 0, sizeof(struct iriap_cb));
 
        self->magic = IAS_MAGIC;
        self->mode = mode;
@@ -217,7 +218,7 @@ EXPORT_SYMBOL(iriap_open);
  */
 static void __iriap_close(struct iriap_cb *self)
 {
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
@@ -241,7 +242,7 @@ void iriap_close(struct iriap_cb *self)
 {
        struct iriap_cb *entry;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
@@ -262,7 +263,7 @@ static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
 {
        notify_t notify;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        irda_notify_init(&notify);
        notify.connect_confirm       = iriap_connect_confirm;
@@ -277,7 +278,7 @@ static int iriap_register_lsap(struct iriap_cb *self, __u8 slsap_sel, int mode)
 
        self->lsap = irlmp_open_lsap(slsap_sel, &notify, 0);
        if (self->lsap == NULL) {
-               IRDA_ERROR("%s: Unable to allocated LSAP!\n", __FUNCTION__);
+               IRDA_ERROR("%s: Unable to allocated LSAP!\n", __func__);
                return -1;
        }
        self->slsap_sel = self->lsap->slsap_sel;
@@ -297,7 +298,7 @@ static void iriap_disconnect_indication(void *instance, void *sap,
 {
        struct iriap_cb *self;
 
-       IRDA_DEBUG(4, "%s(), reason=%s\n", __FUNCTION__, irlmp_reasons[reason]);
+       IRDA_DEBUG(4, "%s(), reason=%s\n", __func__, irlmp_reasons[reason]);
 
        self = (struct iriap_cb *) instance;
 
@@ -313,7 +314,7 @@ static void iriap_disconnect_indication(void *instance, void *sap,
                dev_kfree_skb(skb);
 
        if (self->mode == IAS_CLIENT) {
-               IRDA_DEBUG(4, "%s(), disconnect as client\n", __FUNCTION__);
+               IRDA_DEBUG(4, "%s(), disconnect as client\n", __func__);
 
 
                iriap_do_client_event(self, IAP_LM_DISCONNECT_INDICATION,
@@ -326,7 +327,7 @@ static void iriap_disconnect_indication(void *instance, void *sap,
                if (self->confirm)
                        self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
        } else {
-               IRDA_DEBUG(4, "%s(), disconnect as server\n", __FUNCTION__);
+               IRDA_DEBUG(4, "%s(), disconnect as server\n", __func__);
                iriap_do_server_event(self, IAP_LM_DISCONNECT_INDICATION,
                                      NULL);
                iriap_close(self);
@@ -340,15 +341,16 @@ static void iriap_disconnect_request(struct iriap_cb *self)
 {
        struct sk_buff *tx_skb;
 
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
 
-       tx_skb = dev_alloc_skb(64);
+       tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
        if (tx_skb == NULL) {
-               IRDA_DEBUG(0, "%s(), Could not allocate an sk_buff of length %d\n", 
-                       __FUNCTION__, 64);
+               IRDA_DEBUG(0,
+                          "%s(), Could not allocate an sk_buff of length %d\n",
+                          __func__, LMP_MAX_HEADER);
                return;
        }
 
@@ -396,7 +398,7 @@ int iriap_getvaluebyclass_request(struct iriap_cb *self,
        attr_len = strlen(attr);        /* Up to IAS_MAX_ATTRIBNAME = 60 */
 
        skb_len = self->max_header_size+2+name_len+1+attr_len+4;
-       tx_skb = dev_alloc_skb(skb_len);
+       tx_skb = alloc_skb(skb_len, GFP_ATOMIC);
        if (!tx_skb)
                return -ENOMEM;
 
@@ -450,15 +452,17 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
        n = 2;
 
        /* Get length, MSB first */
-       len = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
+       len = get_unaligned_be16(fp + n);
+       n += 2;
 
-       IRDA_DEBUG(4, "%s(), len=%d\n", __FUNCTION__, len);
+       IRDA_DEBUG(4, "%s(), len=%d\n", __func__, len);
 
        /* Get object ID, MSB first */
-       obj_id = be16_to_cpu(get_unaligned((__u16 *)(fp+n))); n += 2;
+       obj_id = get_unaligned_be16(fp + n);
+       n += 2;
 
        type = fp[n++];
-       IRDA_DEBUG(4, "%s(), Value type = %d\n", __FUNCTION__, type);
+       IRDA_DEBUG(4, "%s(), Value type = %d\n", __func__, type);
 
        switch (type) {
        case IAS_INTEGER:
@@ -467,7 +471,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
                value = irias_new_integer_value(tmp_cpu32);
 
                /*  Legal values restricted to 0x01-0x6f, page 15 irttp */
-               IRDA_DEBUG(4, "%s(), lsap=%d\n", __FUNCTION__, value->t.integer);
+               IRDA_DEBUG(4, "%s(), lsap=%d\n", __func__, value->t.integer);
                break;
        case IAS_STRING:
                charset = fp[n++];
@@ -487,7 +491,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
 /*             case CS_UNICODE: */
                default:
                        IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
-                                  __FUNCTION__, ias_charset_types[charset]);
+                                  __func__, ias_charset_types[charset]);
 
                        /* Aborting, close connection! */
                        iriap_disconnect_request(self);
@@ -495,7 +499,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
                        /* break; */
                }
                value_len = fp[n++];
-               IRDA_DEBUG(4, "%s(), strlen=%d\n", __FUNCTION__, value_len);
+               IRDA_DEBUG(4, "%s(), strlen=%d\n", __func__, value_len);
 
                /* Make sure the string is null-terminated */
                fp[n+value_len] = 0x00;
@@ -505,7 +509,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
                value = irias_new_string_value(fp+n);
                break;
        case IAS_OCT_SEQ:
-               value_len = be16_to_cpu(get_unaligned((__u16 *)(fp+n)));
+               value_len = get_unaligned_be16(fp + n);
                n += 2;
 
                /* Will truncate to IAS_MAX_OCTET_STRING bytes */
@@ -525,7 +529,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
        if (self->confirm)
                self->confirm(IAS_SUCCESS, obj_id, value, self->priv);
        else {
-               IRDA_DEBUG(0, "%s(), missing handler!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), missing handler!\n", __func__);
                irias_delete_value(value);
        }
 }
@@ -543,11 +547,11 @@ static void iriap_getvaluebyclass_response(struct iriap_cb *self,
 {
        struct sk_buff *tx_skb;
        int n;
-       __u32 tmp_be32;
+       __be32 tmp_be32;
        __be16 tmp_be16;
        __u8 *fp;
 
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
@@ -562,7 +566,8 @@ static void iriap_getvaluebyclass_response(struct iriap_cb *self,
         *  value. We add 32 bytes because of the 6 bytes for the frame and
         *  max 5 bytes for the value coding.
         */
-       tx_skb = dev_alloc_skb(value->len + self->max_header_size + 32);
+       tx_skb = alloc_skb(value->len + self->max_header_size + 32,
+                          GFP_ATOMIC);
        if (!tx_skb)
                return;
 
@@ -577,7 +582,7 @@ static void iriap_getvaluebyclass_response(struct iriap_cb *self,
        fp[n++] = ret_code;
 
        /* Insert list length (MSB first) */
-       tmp_be16 = __constant_htons(0x0001);
+       tmp_be16 = htons(0x0001);
        memcpy(fp+n, &tmp_be16, 2);  n += 2;
 
        /* Insert object identifier ( MSB first) */
@@ -608,12 +613,12 @@ static void iriap_getvaluebyclass_response(struct iriap_cb *self,
                memcpy(fp+n, value->t.oct_seq, value->len); n+=value->len;
                break;
        case IAS_MISSING:
-               IRDA_DEBUG( 3, "%s: sending IAS_MISSING\n", __FUNCTION__);
+               IRDA_DEBUG( 3, "%s: sending IAS_MISSING\n", __func__);
                skb_put(tx_skb, 1);
                fp[n++] = value->type;
                break;
        default:
-               IRDA_DEBUG(0, "%s(), type not implemented!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), type not implemented!\n", __func__);
                break;
        }
        iriap_do_r_connect_event(self, IAP_CALL_RESPONSE, tx_skb);
@@ -640,7 +645,7 @@ static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
        __u8 *fp;
        int n;
 
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
@@ -672,7 +677,7 @@ static void iriap_getvaluebyclass_indication(struct iriap_cb *self,
        if (attrib == NULL) {
                IRDA_DEBUG(2, "LM-IAS: Attribute %s not found\n", attr);
                iriap_getvaluebyclass_response(self, obj->id,
-                                              IAS_ATTRIB_UNKNOWN, 
+                                              IAS_ATTRIB_UNKNOWN,
                                               &irias_missing);
                return;
        }
@@ -695,12 +700,12 @@ void iriap_send_ack(struct iriap_cb *self)
        struct sk_buff *tx_skb;
        __u8 *frame;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
 
-       tx_skb = dev_alloc_skb(64);
+       tx_skb = alloc_skb(LMP_MAX_HEADER + 1, GFP_ATOMIC);
        if (!tx_skb)
                return;
 
@@ -726,7 +731,7 @@ void iriap_connect_request(struct iriap_cb *self)
                                    self->saddr, self->daddr,
                                    NULL, NULL);
        if (ret < 0) {
-               IRDA_DEBUG(0, "%s(), connect failed!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), connect failed!\n", __func__);
                self->confirm(IAS_DISCONNECT, 0, NULL, self->priv);
        }
 }
@@ -774,7 +779,7 @@ static void iriap_connect_indication(void *instance, void *sap,
 {
        struct iriap_cb *self, *new;
 
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
        self = (struct iriap_cb *) instance;
 
@@ -785,14 +790,14 @@ static void iriap_connect_indication(void *instance, void *sap,
        /* Start new server */
        new = iriap_open(LSAP_IAS, IAS_SERVER, NULL, NULL);
        if (!new) {
-               IRDA_DEBUG(0, "%s(), open failed\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), open failed\n", __func__);
                goto out;
        }
 
        /* Now attach up the new "socket" */
        new->lsap = irlmp_dup(self->lsap, new);
        if (!new->lsap) {
-               IRDA_DEBUG(0, "%s(), dup failed!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), dup failed!\n", __func__);
                goto out;
        }
 
@@ -822,7 +827,7 @@ static int iriap_data_indication(void *instance, void *sap,
        __u8  *frame;
        __u8  opcode;
 
-       IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(3, "%s()\n", __func__);
 
        self = (struct iriap_cb *) instance;
 
@@ -834,7 +839,7 @@ static int iriap_data_indication(void *instance, void *sap,
 
        if (self->mode == IAS_SERVER) {
                /* Call server */
-               IRDA_DEBUG(4, "%s(), Calling server!\n", __FUNCTION__);
+               IRDA_DEBUG(4, "%s(), Calling server!\n", __func__);
                iriap_do_r_connect_event(self, IAP_RECV_F_LST, skb);
                goto out;
        }
@@ -842,13 +847,13 @@ static int iriap_data_indication(void *instance, void *sap,
        if (~opcode & IAP_LST) {
                IRDA_WARNING("%s:, IrIAS multiframe commands or "
                             "results is not implemented yet!\n",
-                            __FUNCTION__);
+                            __func__);
                goto out;
        }
 
        /* Check for ack frames since they don't contain any data */
        if (opcode & IAP_ACK) {
-               IRDA_DEBUG(0, "%s() Got ack frame!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s() Got ack frame!\n", __func__);
                goto out;
        }
 
@@ -866,7 +871,7 @@ static int iriap_data_indication(void *instance, void *sap,
                        iriap_getvaluebyclass_confirm(self, skb);
                        break;
                case IAS_CLASS_UNKNOWN:
-                       IRDA_DEBUG(1, "%s(), No such class!\n", __FUNCTION__);
+                       IRDA_DEBUG(1, "%s(), No such class!\n", __func__);
                        /* Finished, close connection! */
                        iriap_disconnect_request(self);
 
@@ -879,7 +884,7 @@ static int iriap_data_indication(void *instance, void *sap,
                                              self->priv);
                        break;
                case IAS_ATTRIB_UNKNOWN:
-                       IRDA_DEBUG(1, "%s(), No such attribute!\n", __FUNCTION__);
+                       IRDA_DEBUG(1, "%s(), No such attribute!\n", __func__);
                        /* Finished, close connection! */
                        iriap_disconnect_request(self);
 
@@ -894,7 +899,7 @@ static int iriap_data_indication(void *instance, void *sap,
                }
                break;
        default:
-               IRDA_DEBUG(0, "%s(), Unknown op-code: %02x\n", __FUNCTION__,
+               IRDA_DEBUG(0, "%s(), Unknown op-code: %02x\n", __func__,
                           opcode);
                break;
        }
@@ -916,7 +921,7 @@ void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
        __u8 *fp;
        __u8 opcode;
 
-       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(4, "%s()\n", __func__);
 
        IRDA_ASSERT(self != NULL, return;);
        IRDA_ASSERT(self->magic == IAS_MAGIC, return;);
@@ -926,8 +931,8 @@ void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
 
        opcode = fp[0];
        if (~opcode & 0x80) {
-               IRDA_WARNING("%s: IrIAS multiframe commands or results"
-                            "is not implemented yet!\n", __FUNCTION__);
+               IRDA_WARNING("%s: IrIAS multiframe commands or results "
+                            "is not implemented yet!\n", __func__);
                return;
        }
        opcode &= 0x7f; /* Mask away LST bit */
@@ -935,7 +940,7 @@ void iriap_call_indication(struct iriap_cb *self, struct sk_buff *skb)
        switch (opcode) {
        case GET_INFO_BASE:
                IRDA_WARNING("%s: GetInfoBaseDetails not implemented yet!\n",
-                            __FUNCTION__);
+                            __func__);
                break;
        case GET_VALUE_BY_CLASS:
                iriap_getvaluebyclass_indication(self, skb);
@@ -962,14 +967,14 @@ static void iriap_watchdog_timer_expired(void *data)
 
 #ifdef CONFIG_PROC_FS
 
-static const char *ias_value_types[] = {
+static const char *const ias_value_types[] = {
        "IAS_MISSING",
        "IAS_INTEGER",
        "IAS_OCT_SEQ",
        "IAS_STRING"
 };
 
-static inline struct ias_object *irias_seq_idx(loff_t pos) 
+static inline struct ias_object *irias_seq_idx(loff_t pos)
 {
        struct ias_object *obj;
 
@@ -978,7 +983,7 @@ static inline struct ias_object *irias_seq_idx(loff_t pos)
                if (pos-- == 0)
                        break;
        }
-               
+
        return obj;
 }
 
@@ -993,7 +998,7 @@ static void *irias_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
        ++*pos;
 
-       return (v == SEQ_START_TOKEN) 
+       return (v == SEQ_START_TOKEN)
                ? (void *) hashbin_get_first(irias_objects)
                : (void *) hashbin_get_next(irias_objects);
 }
@@ -1025,7 +1030,7 @@ static int irias_seq_show(struct seq_file *seq, void *v)
                for (attrib = (struct ias_attrib *) hashbin_get_first(obj->attribs);
                     attrib != NULL;
                     attrib = (struct ias_attrib *) hashbin_get_next(obj->attribs)) {
-                    
+
                        IRDA_ASSERT(attrib->magic == IAS_ATTRIB_MAGIC,
                                    goto outloop; );
 
@@ -1044,14 +1049,14 @@ static int irias_seq_show(struct seq_file *seq, void *v)
                                           attrib->value->t.string);
                                break;
                        case IAS_OCT_SEQ:
-                               seq_printf(seq, "octet sequence (%d bytes)\n", 
+                               seq_printf(seq, "octet sequence (%d bytes)\n",
                                           attrib->value->len);
                                break;
                        case IAS_MISSING:
                                seq_puts(seq, "missing\n");
                                break;
                        default:
-                               seq_printf(seq, "type %d?\n", 
+                               seq_printf(seq, "type %d?\n",
                                           attrib->value->type);
                        }
                        seq_putc(seq, '\n');
@@ -1064,7 +1069,7 @@ static int irias_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations irias_seq_ops = {
+static const struct seq_operations irias_seq_ops = {
        .start  = irias_seq_start,
        .next   = irias_seq_next,
        .stop   = irias_seq_stop,
@@ -1078,7 +1083,7 @@ static int irias_seq_open(struct inode *inode, struct file *file)
        return seq_open(file, &irias_seq_ops);
 }
 
-struct file_operations irias_seq_fops = {
+const struct file_operations irias_seq_fops = {
        .owner          = THIS_MODULE,
        .open           = irias_seq_open,
        .read           = seq_read,