[TIPC]: Update version to 1.6.3
[safe/jmp/linux-2.6] / net / tipc / port.c
index 360920b..e2646a9 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * net/tipc/port.c: TIPC port code
- * 
- * Copyright (c) 1992-2006, Ericsson AB
- * Copyright (c) 2004-2005, Wind River Systems
+ *
+ * Copyright (c) 1992-2007, Ericsson AB
+ * Copyright (c) 2004-2007, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,6 @@
 #include "addr.h"
 #include "link.h"
 #include "node.h"
-#include "port.h"
 #include "name_table.h"
 #include "user_reg.h"
 #include "msg.h"
@@ -57,8 +56,8 @@
 static struct sk_buff *msg_queue_head = NULL;
 static struct sk_buff *msg_queue_tail = NULL;
 
-spinlock_t tipc_port_list_lock = SPIN_LOCK_UNLOCKED;
-static spinlock_t queue_lock = SPIN_LOCK_UNLOCKED;
+DEFINE_SPINLOCK(tipc_port_list_lock);
+static DEFINE_SPINLOCK(queue_lock);
 
 static LIST_HEAD(ports);
 static void port_handle_node_down(unsigned long ref);
@@ -126,8 +125,8 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain,
 
        ext_targets = tipc_nametbl_mc_translate(seq->type, seq->lower, seq->upper,
                                                TIPC_NODE_SCOPE, &dports);
-       
-       /* Send message to destinations (duplicate it only if necessary) */ 
+
+       /* Send message to destinations (duplicate it only if necessary) */
 
        if (ext_targets) {
                if (dports.count != 0) {
@@ -157,7 +156,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain,
 
 /**
  * tipc_port_recv_mcast - deliver multicast message to all destination ports
- * 
+ *
  * If there is no port list, perform a lookup to create one
  */
 
@@ -168,7 +167,6 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp)
        struct port_list *item = dp;
        int cnt = 0;
 
-       assert(buf);
        msg = buf_msg(buf);
 
        /* Create destination port list, if one wasn't supplied */
@@ -196,7 +194,7 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp)
                        struct sk_buff *b = skb_clone(buf, GFP_ATOMIC);
 
                        if (b == NULL) {
-                               warn("Buffer allocation failure\n");
+                               warn("Unable to deliver multicast message(s)\n");
                                msg_dbg(msg, "LOST:");
                                goto exit;
                        }
@@ -214,7 +212,7 @@ exit:
 
 /**
  * tipc_createport_raw - create a native TIPC port
- * 
+ *
  * Returns local port reference
  */
 
@@ -227,34 +225,34 @@ u32 tipc_createport_raw(void *usr_handle,
        struct tipc_msg *msg;
        u32 ref;
 
-       p_ptr = kmalloc(sizeof(*p_ptr), GFP_ATOMIC);
-       if (p_ptr == NULL) {
-               warn("Memory squeeze; failed to create port\n");
+       p_ptr = kzalloc(sizeof(*p_ptr), GFP_ATOMIC);
+       if (!p_ptr) {
+               warn("Port creation failed, no memory\n");
                return 0;
        }
-       memset(p_ptr, 0, sizeof(*p_ptr));
        ref = tipc_ref_acquire(p_ptr, &p_ptr->publ.lock);
        if (!ref) {
-               warn("Reference Table Exhausted\n");
+               warn("Port creation failed, reference table exhausted\n");
                kfree(p_ptr);
                return 0;
        }
 
        tipc_port_lock(ref);
+       p_ptr->publ.usr_handle = usr_handle;
+       p_ptr->publ.max_pkt = MAX_PKT_DEFAULT;
        p_ptr->publ.ref = ref;
        msg = &p_ptr->publ.phdr;
-       msg_init(msg, DATA_LOW, TIPC_NAMED_MSG, TIPC_OK, LONG_H_SIZE, 0);
+       msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, TIPC_OK, LONG_H_SIZE,
+                0);
        msg_set_orignode(msg, tipc_own_addr);
        msg_set_prevnode(msg, tipc_own_addr);
        msg_set_origport(msg, ref);
        msg_set_importance(msg,importance);
        p_ptr->last_in_seqno = 41;
        p_ptr->sent = 1;
-       p_ptr->publ.usr_handle = usr_handle;
        INIT_LIST_HEAD(&p_ptr->wait_list);
        INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
        p_ptr->congested_link = NULL;
-       p_ptr->max_pkt = MAX_PKT_DEFAULT;
        p_ptr->dispatcher = dispatcher;
        p_ptr->wakeup = wakeup;
        p_ptr->user_port = NULL;
@@ -275,7 +273,7 @@ int tipc_deleteport(u32 ref)
 
        tipc_withdraw(ref, 0, NULL);
        p_ptr = tipc_port_lock(ref);
-       if (!p_ptr) 
+       if (!p_ptr)
                return -EINVAL;
 
        tipc_ref_discard(ref);
@@ -304,7 +302,7 @@ int tipc_deleteport(u32 ref)
 
 /**
  * tipc_get_port() - return port associated with 'ref'
- * 
+ *
  * Note: Port is not locked.
  */
 
@@ -338,19 +336,19 @@ static int port_unreliable(struct port *p_ptr)
 int tipc_portunreliable(u32 ref, unsigned int *isunreliable)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
        *isunreliable = port_unreliable(p_ptr);
-       spin_unlock_bh(p_ptr->publ.lock);
+       tipc_port_unlock(p_ptr);
        return TIPC_OK;
 }
 
 int tipc_set_portunreliable(u32 ref, unsigned int isunreliable)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
@@ -367,19 +365,19 @@ static int port_unreturnable(struct port *p_ptr)
 int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
        *isunrejectable = port_unreturnable(p_ptr);
-       spin_unlock_bh(p_ptr->publ.lock);
+       tipc_port_unlock(p_ptr);
        return TIPC_OK;
 }
 
 int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
@@ -388,19 +386,19 @@ int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable)
        return TIPC_OK;
 }
 
-/* 
- * port_build_proto_msg(): build a port level protocol 
- * or a connection abortion message. Called with 
+/*
+ * port_build_proto_msg(): build a port level protocol
+ * or a connection abortion message. Called with
  * tipc_port lock on.
  */
 static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode,
                                            u32 origport, u32 orignode,
-                                           u32 usr, u32 type, u32 err, 
+                                           u32 usr, u32 type, u32 err,
                                            u32 seqno, u32 ack)
 {
        struct sk_buff *buf;
        struct tipc_msg *msg;
-       
+
        buf = buf_acquire(LONG_H_SIZE);
        if (buf) {
                msg = buf_msg(buf);
@@ -416,13 +414,6 @@ static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode,
        return buf;
 }
 
-int tipc_set_msg_option(struct tipc_port *tp_ptr, const char *opt, const u32 sz)
-{
-       msg_expand(&tp_ptr->phdr, msg_destnode(&tp_ptr->phdr));
-       msg_set_options(&tp_ptr->phdr, opt, sz);
-       return TIPC_OK;
-}
-
 int tipc_reject_msg(struct sk_buff *buf, u32 err)
 {
        struct tipc_msg *msg = buf_msg(buf);
@@ -463,10 +454,10 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err)
                msg_set_orignode(rmsg, tipc_own_addr);
        else
                msg_set_orignode(rmsg, msg_destnode(msg));
-       msg_set_size(rmsg, data_sz + hdr_sz); 
+       msg_set_size(rmsg, data_sz + hdr_sz);
        msg_set_nametype(rmsg, msg_nametype(msg));
        msg_set_nameinst(rmsg, msg_nameinst(msg));
-       memcpy(rbuf->data + hdr_sz, msg_data(msg), data_sz);
+       skb_copy_to_linear_data_offset(rbuf, hdr_sz, msg_data(msg), data_sz);
 
        /* send self-abort message when rejecting on a connected port */
        if (msg_connected(msg)) {
@@ -494,7 +485,7 @@ int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
        struct sk_buff *buf;
        int res;
 
-       res = msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, 
+       res = msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE,
                        !p_ptr->user_port, &buf);
        if (!buf)
                return res;
@@ -507,9 +498,14 @@ static void port_timeout(unsigned long ref)
        struct port *p_ptr = tipc_port_lock(ref);
        struct sk_buff *buf = NULL;
 
-       if (!p_ptr || !p_ptr->publ.connected)
+       if (!p_ptr)
                return;
 
+       if (!p_ptr->publ.connected) {
+               tipc_port_unlock(p_ptr);
+               return;
+       }
+
        /* Last probe answered ? */
        if (p_ptr->probing_state == PROBING) {
                buf = port_build_self_abort_msg(p_ptr, TIPC_ERR_NO_PORT);
@@ -520,7 +516,7 @@ static void port_timeout(unsigned long ref)
                                           tipc_own_addr,
                                           CONN_MANAGER,
                                           CONN_PROBE,
-                                          TIPC_OK, 
+                                          TIPC_OK,
                                           port_out_seqno(p_ptr),
                                           0);
                port_incr_out_seqno(p_ptr);
@@ -559,7 +555,7 @@ static struct sk_buff *port_build_self_abort_msg(struct port *p_ptr, u32 err)
                                    port_peernode(p_ptr),
                                    imp,
                                    TIPC_CONN_MSG,
-                                   err, 
+                                   err,
                                    p_ptr->last_in_seqno + 1,
                                    0);
 }
@@ -579,7 +575,7 @@ static struct sk_buff *port_build_peer_abort_msg(struct port *p_ptr, u32 err)
                                    tipc_own_addr,
                                    imp,
                                    TIPC_CONN_MSG,
-                                   err, 
+                                   err,
                                    port_out_seqno(p_ptr),
                                    0);
 }
@@ -610,7 +606,7 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf)
                        }
                }
                if (msg_type(msg) == CONN_ACK) {
-                       int wakeup = tipc_port_congested(p_ptr) && 
+                       int wakeup = tipc_port_congested(p_ptr) &&
                                     p_ptr->publ.congested &&
                                     p_ptr->wakeup;
                        p_ptr->acked += msg_msgcnt(msg);
@@ -627,10 +623,10 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf)
        }
        if (err) {
                r_buf = port_build_proto_msg(msg_origport(msg),
-                                            msg_orignode(msg), 
-                                            msg_destport(msg), 
+                                            msg_orignode(msg),
+                                            msg_destport(msg),
                                             tipc_own_addr,
-                                            DATA_HIGH,
+                                            TIPC_HIGH_IMPORTANCE,
                                             TIPC_CONN_MSG,
                                             err,
                                             0,
@@ -640,10 +636,10 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf)
 
        /* All is fine */
        if (msg_type(msg) == CONN_PROBE) {
-               r_buf = port_build_proto_msg(msg_origport(msg), 
-                                            msg_orignode(msg), 
-                                            msg_destport(msg), 
-                                            tipc_own_addr, 
+               r_buf = port_build_proto_msg(msg_origport(msg),
+                                            msg_orignode(msg),
+                                            msg_destport(msg),
+                                            tipc_own_addr,
                                             CONN_MANAGER,
                                             CONN_PROBE_REPLY,
                                             TIPC_OK,
@@ -662,39 +658,39 @@ exit:
 
 static void port_print(struct port *p_ptr, struct print_buf *buf, int full_id)
 {
-        struct publication *publ;
+       struct publication *publ;
 
        if (full_id)
-               tipc_printf(buf, "<%u.%u.%u:%u>:", 
+               tipc_printf(buf, "<%u.%u.%u:%u>:",
                            tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr),
-                            tipc_node(tipc_own_addr), p_ptr->publ.ref);
+                           tipc_node(tipc_own_addr), p_ptr->publ.ref);
        else
                tipc_printf(buf, "%-10u:", p_ptr->publ.ref);
 
-        if (p_ptr->publ.connected) {
-                u32 dport = port_peerport(p_ptr);
-                u32 destnode = port_peernode(p_ptr);
-
-                tipc_printf(buf, " connected to <%u.%u.%u:%u>",
-                            tipc_zone(destnode), tipc_cluster(destnode),
-                            tipc_node(destnode), dport);
-                if (p_ptr->publ.conn_type != 0)
-                        tipc_printf(buf, " via {%u,%u}",
-                                    p_ptr->publ.conn_type,
-                                    p_ptr->publ.conn_instance);
-        }
-        else if (p_ptr->publ.published) {
-                tipc_printf(buf, " bound to");
-                list_for_each_entry(publ, &p_ptr->publications, pport_list) {
+       if (p_ptr->publ.connected) {
+               u32 dport = port_peerport(p_ptr);
+               u32 destnode = port_peernode(p_ptr);
+
+               tipc_printf(buf, " connected to <%u.%u.%u:%u>",
+                           tipc_zone(destnode), tipc_cluster(destnode),
+                           tipc_node(destnode), dport);
+               if (p_ptr->publ.conn_type != 0)
+                       tipc_printf(buf, " via {%u,%u}",
+                                   p_ptr->publ.conn_type,
+                                   p_ptr->publ.conn_instance);
+       }
+       else if (p_ptr->publ.published) {
+               tipc_printf(buf, " bound to");
+               list_for_each_entry(publ, &p_ptr->publications, pport_list) {
                        if (publ->lower == publ->upper)
                                tipc_printf(buf, " {%u,%u}", publ->type,
                                            publ->lower);
                        else
-                               tipc_printf(buf, " {%u,%u,%u}", publ->type, 
+                               tipc_printf(buf, " {%u,%u,%u}", publ->type,
                                            publ->lower, publ->upper);
-                }
-        }
-        tipc_printf(buf, "\n");
+               }
+       }
+       tipc_printf(buf, "\n");
 }
 
 #define MAX_PORT_QUERY 32768
@@ -815,7 +811,7 @@ static void port_dispatcher_sigh(void *dummy)
                struct sk_buff *next = buf->next;
                struct tipc_msg *msg = buf_msg(buf);
                u32 dref = msg_destport(msg);
-               
+
                message_type = msg_type(msg);
                if (message_type > TIPC_DIRECT_MSG)
                        goto reject;    /* Unsupported message type */
@@ -835,13 +831,13 @@ static void port_dispatcher_sigh(void *dummy)
                        goto err;
 
                switch (message_type) {
-               
+
                case TIPC_CONN_MSG:{
                                tipc_conn_msg_event cb = up_ptr->conn_msg_cb;
                                u32 peer_port = port_peerport(p_ptr);
                                u32 peer_node = port_peernode(p_ptr);
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (unlikely(!connected)) {
                                        if (unlikely(published))
                                                goto reject;
@@ -853,9 +849,9 @@ static void port_dispatcher_sigh(void *dummy)
                                        goto reject;
                                if (unlikely(!cb))
                                        goto reject;
-                               if (unlikely(++p_ptr->publ.conn_unacked >= 
+                               if (unlikely(++p_ptr->publ.conn_unacked >=
                                             TIPC_FLOW_CONTROL_WIN))
-                                       tipc_acknowledge(dref, 
+                                       tipc_acknowledge(dref,
                                                         p_ptr->publ.conn_unacked);
                                skb_pull(buf, msg_hdr_sz(msg));
                                cb(usr_handle, dref, &buf, msg_data(msg),
@@ -865,13 +861,13 @@ static void port_dispatcher_sigh(void *dummy)
                case TIPC_DIRECT_MSG:{
                                tipc_msg_event cb = up_ptr->msg_cb;
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (unlikely(connected))
                                        goto reject;
                                if (unlikely(!cb))
                                        goto reject;
                                skb_pull(buf, msg_hdr_sz(msg));
-                               cb(usr_handle, dref, &buf, msg_data(msg), 
+                               cb(usr_handle, dref, &buf, msg_data(msg),
                                   msg_data_sz(msg), msg_importance(msg),
                                   &orig);
                                break;
@@ -880,7 +876,7 @@ static void port_dispatcher_sigh(void *dummy)
                case TIPC_NAMED_MSG:{
                                tipc_named_msg_event cb = up_ptr->named_msg_cb;
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (unlikely(connected))
                                        goto reject;
                                if (unlikely(!cb))
@@ -892,7 +888,7 @@ static void port_dispatcher_sigh(void *dummy)
                                dseq.upper = (message_type == TIPC_NAMED_MSG)
                                        ? dseq.lower : msg_nameupper(msg);
                                skb_pull(buf, msg_hdr_sz(msg));
-                               cb(usr_handle, dref, &buf, msg_data(msg), 
+                               cb(usr_handle, dref, &buf, msg_data(msg),
                                   msg_data_sz(msg), msg_importance(msg),
                                   &orig, &dseq);
                                break;
@@ -904,14 +900,14 @@ static void port_dispatcher_sigh(void *dummy)
                continue;
 err:
                switch (message_type) {
-               
+
                case TIPC_CONN_MSG:{
-                               tipc_conn_shutdown_event cb = 
+                               tipc_conn_shutdown_event cb =
                                        up_ptr->conn_err_cb;
                                u32 peer_port = port_peerport(p_ptr);
                                u32 peer_node = port_peernode(p_ptr);
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (!connected || !cb)
                                        break;
                                if (msg_origport(msg) != peer_port)
@@ -927,7 +923,7 @@ err:
                case TIPC_DIRECT_MSG:{
                                tipc_msg_err_event cb = up_ptr->err_cb;
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (connected || !cb)
                                        break;
                                skb_pull(buf, msg_hdr_sz(msg));
@@ -937,10 +933,10 @@ err:
                        }
                case TIPC_MCAST_MSG:
                case TIPC_NAMED_MSG:{
-                               tipc_named_msg_err_event cb = 
+                               tipc_named_msg_err_event cb =
                                        up_ptr->named_err_cb;
 
-                               spin_unlock_bh(p_ptr->publ.lock);
+                               tipc_port_unlock(p_ptr);
                                if (connected || !cb)
                                        break;
                                dseq.type =  msg_nametype(msg);
@@ -948,7 +944,7 @@ err:
                                dseq.upper = (message_type == TIPC_NAMED_MSG)
                                        ? dseq.lower : msg_nameupper(msg);
                                skb_pull(buf, msg_hdr_sz(msg));
-                               cb(usr_handle, dref, &buf, msg_data(msg), 
+                               cb(usr_handle, dref, &buf, msg_data(msg),
                                   msg_data_sz(msg), msg_errcode(msg), &dseq);
                                break;
                        }
@@ -983,9 +979,9 @@ static u32 port_dispatcher(struct tipc_port *dummy, struct sk_buff *buf)
        return TIPC_OK;
 }
 
-/* 
+/*
  * Wake up port after congestion: Called with port locked,
- *                                
+ *
  */
 
 static void port_wakeup_sh(unsigned long ref)
@@ -1030,7 +1026,7 @@ void tipc_acknowledge(u32 ref, u32 ack)
                                           tipc_own_addr,
                                           CONN_MANAGER,
                                           CONN_ACK,
-                                          TIPC_OK, 
+                                          TIPC_OK,
                                           port_out_seqno(p_ptr),
                                           ack);
        }
@@ -1043,24 +1039,25 @@ void tipc_acknowledge(u32 ref, u32 ack)
  *                    registry if non-zero user_ref.
  */
 
-int tipc_createport(u32 user_ref, 
-                   void *usr_handle, 
-                   unsigned int importance, 
-                   tipc_msg_err_event error_cb, 
-                   tipc_named_msg_err_event named_error_cb, 
-                   tipc_conn_shutdown_event conn_error_cb, 
-                   tipc_msg_event msg_cb, 
-                   tipc_named_msg_event named_msg_cb, 
-                   tipc_conn_msg_event conn_msg_cb, 
+int tipc_createport(u32 user_ref,
+                   void *usr_handle,
+                   unsigned int importance,
+                   tipc_msg_err_event error_cb,
+                   tipc_named_msg_err_event named_error_cb,
+                   tipc_conn_shutdown_event conn_error_cb,
+                   tipc_msg_event msg_cb,
+                   tipc_named_msg_event named_msg_cb,
+                   tipc_conn_msg_event conn_msg_cb,
                    tipc_continue_event continue_event_cb,/* May be zero */
                    u32 *portref)
 {
        struct user_port *up_ptr;
-       struct port *p_ptr; 
+       struct port *p_ptr;
        u32 ref;
 
-       up_ptr = (struct user_port *)kmalloc(sizeof(*up_ptr), GFP_ATOMIC);
-       if (up_ptr == NULL) {
+       up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC);
+       if (!up_ptr) {
+               warn("Port creation failed, no memory\n");
                return -ENOMEM;
        }
        ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, importance);
@@ -1084,7 +1081,7 @@ int tipc_createport(u32 user_ref,
        INIT_LIST_HEAD(&up_ptr->uport_list);
        tipc_reg_add_port(up_ptr);
        *portref = p_ptr->publ.ref;
-       dbg(" tipc_createport: %x with ref %u\n", p_ptr, p_ptr->publ.ref);        
+       dbg(" tipc_createport: %x with ref %u\n", p_ptr, p_ptr->publ.ref);
        tipc_port_unlock(p_ptr);
        return TIPC_OK;
 }
@@ -1099,12 +1096,12 @@ int tipc_ownidentity(u32 ref, struct tipc_portid *id)
 int tipc_portimportance(u32 ref, unsigned int *importance)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
        *importance = (unsigned int)msg_importance(&p_ptr->publ.phdr);
-       spin_unlock_bh(p_ptr->publ.lock);
+       tipc_port_unlock(p_ptr);
        return TIPC_OK;
 }
 
@@ -1119,7 +1116,7 @@ int tipc_set_portimportance(u32 ref, unsigned int imp)
        if (!p_ptr)
                return -EINVAL;
        msg_set_importance(&p_ptr->publ.phdr, (u32)imp);
-       spin_unlock_bh(p_ptr->publ.lock);
+       tipc_port_unlock(p_ptr);
        return TIPC_OK;
 }
 
@@ -1132,11 +1129,12 @@ int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
        int res = -EINVAL;
 
        p_ptr = tipc_port_lock(ref);
+       if (!p_ptr)
+               return -EINVAL;
+
        dbg("tipc_publ %u, p_ptr = %x, conn = %x, scope = %x, "
            "lower = %u, upper = %u\n",
            ref, p_ptr, p_ptr->publ.connected, scope, seq->lower, seq->upper);
-       if (!p_ptr)
-               return -EINVAL;
        if (p_ptr->publ.connected)
                goto exit;
        if (seq->lower > seq->upper)
@@ -1167,21 +1165,19 @@ int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
        struct publication *publ;
        struct publication *tpubl;
        int res = -EINVAL;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
-       if (!p_ptr->publ.published)
-               goto exit;
        if (!seq) {
-               list_for_each_entry_safe(publ, tpubl, 
+               list_for_each_entry_safe(publ, tpubl,
                                         &p_ptr->publications, pport_list) {
-                       tipc_nametbl_withdraw(publ->type, publ->lower, 
+                       tipc_nametbl_withdraw(publ->type, publ->lower,
                                              publ->ref, publ->key);
                }
                res = TIPC_OK;
        } else {
-               list_for_each_entry_safe(publ, tpubl, 
+               list_for_each_entry_safe(publ, tpubl,
                                         &p_ptr->publications, pport_list) {
                        if (publ->scope != scope)
                                continue;
@@ -1191,7 +1187,7 @@ int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
                                continue;
                        if (publ->upper != seq->upper)
                                break;
-                       tipc_nametbl_withdraw(publ->type, publ->lower, 
+                       tipc_nametbl_withdraw(publ->type, publ->lower,
                                              publ->ref, publ->key);
                        res = TIPC_OK;
                        break;
@@ -1199,7 +1195,6 @@ int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq)
        }
        if (list_empty(&p_ptr->publications))
                p_ptr->publ.published = 0;
-exit:
        tipc_port_unlock(p_ptr);
        return res;
 }
@@ -1241,7 +1236,7 @@ int tipc_connect2port(u32 ref, struct tipc_portid const *peer)
        res = TIPC_OK;
 exit:
        tipc_port_unlock(p_ptr);
-       p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref);
+       p_ptr->publ.max_pkt = tipc_link_get_max_pkt(peer->node, ref);
        return res;
 }
 
@@ -1290,7 +1285,7 @@ int tipc_shutdown(u32 ref)
                                           tipc_own_addr,
                                           imp,
                                           TIPC_CONN_MSG,
-                                          TIPC_CONN_SHUTDOWN, 
+                                          TIPC_CONN_SHUTDOWN,
                                           port_out_seqno(p_ptr),
                                           0);
        }
@@ -1302,7 +1297,7 @@ int tipc_shutdown(u32 ref)
 int tipc_isconnected(u32 ref, int *isconnected)
 {
        struct port *p_ptr;
-       
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
@@ -1315,7 +1310,7 @@ int tipc_peer(u32 ref, struct tipc_portid *peer)
 {
        struct port *p_ptr;
        int res;
-        
+
        p_ptr = tipc_port_lock(ref);
        if (!p_ptr)
                return -EINVAL;
@@ -1346,7 +1341,7 @@ int tipc_port_recv_sections(struct port *sender, unsigned int num_sect,
 {
        struct sk_buff *buf;
        int res;
-        
+
        res = msg_build(&sender->publ.phdr, msg_sect, num_sect,
                        MAX_MSG_SIZE, !sender->user_port, &buf);
        if (likely(buf))
@@ -1392,7 +1387,7 @@ int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect)
        return -ELINKCONG;
 }
 
-/** 
+/**
  * tipc_send_buf - send message buffer on connection
  */
 
@@ -1404,7 +1399,7 @@ int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz)
        u32 hsz;
        u32 sz;
        u32 res;
-        
+
        p_ptr = tipc_port_deref(ref);
        if (!p_ptr || !p_ptr->publ.connected)
                return -EINVAL;
@@ -1417,7 +1412,7 @@ int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz)
                return -ENOMEM;
 
        skb_push(buf, hsz);
-       memcpy(buf->data, (unchar *)msg, hsz);
+       skb_copy_to_linear_data(buf, msg, hsz);
        destnode = msg_destnode(msg);
        p_ptr->publ.congested = 1;
        if (!tipc_port_congested(p_ptr)) {
@@ -1445,12 +1440,12 @@ int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz)
  * tipc_forward2name - forward message sections to port name
  */
 
-int tipc_forward2name(u32 ref, 
-                     struct tipc_name const *name, 
+int tipc_forward2name(u32 ref,
+                     struct tipc_name const *name,
                      u32 domain,
-                     u32 num_sect, 
+                     u32 num_sect,
                      struct iovec const *msg_sect,
-                     struct tipc_portid const *orig, 
+                     struct tipc_portid const *orig,
                      unsigned int importance)
 {
        struct port *p_ptr;
@@ -1481,7 +1476,7 @@ int tipc_forward2name(u32 ref,
                p_ptr->sent++;
                if (likely(destnode == tipc_own_addr))
                        return tipc_port_recv_sections(p_ptr, num_sect, msg_sect);
-               res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, 
+               res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect,
                                                   destnode);
                if (likely(res != -ELINKCONG))
                        return res;
@@ -1491,7 +1486,7 @@ int tipc_forward2name(u32 ref,
                }
                return -ELINKCONG;
        }
-       return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, 
+       return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect,
                                         TIPC_ERR_NO_NAME);
 }
 
@@ -1499,10 +1494,10 @@ int tipc_forward2name(u32 ref,
  * tipc_send2name - send message sections to port name
  */
 
-int tipc_send2name(u32 ref, 
+int tipc_send2name(u32 ref,
                   struct tipc_name const *name,
-                  unsigned int domain, 
-                  unsigned int num_sect, 
+                  unsigned int domain,
+                  unsigned int num_sect,
                   struct iovec const *msg_sect)
 {
        struct tipc_portid orig;
@@ -1513,7 +1508,7 @@ int tipc_send2name(u32 ref,
                                 TIPC_PORT_IMPORTANCE);
 }
 
-/** 
+/**
  * tipc_forward_buf2name - forward message buffer to port name
  */
 
@@ -1553,7 +1548,7 @@ int tipc_forward_buf2name(u32 ref,
        if (skb_cow(buf, LONG_H_SIZE))
                return -ENOMEM;
        skb_push(buf, LONG_H_SIZE);
-       memcpy(buf->data, (unchar *)msg, LONG_H_SIZE);
+       skb_copy_to_linear_data(buf, msg, LONG_H_SIZE);
        msg_dbg(buf_msg(buf),"PREP:");
        if (likely(destport || destnode)) {
                p_ptr->sent++;
@@ -1569,14 +1564,14 @@ int tipc_forward_buf2name(u32 ref,
        return tipc_reject_msg(buf, TIPC_ERR_NO_NAME);
 }
 
-/** 
+/**
  * tipc_send_buf2name - send message buffer to port name
  */
 
-int tipc_send_buf2name(u32 ref, 
-                      struct tipc_name const *dest, 
+int tipc_send_buf2name(u32 ref,
+                      struct tipc_name const *dest,
                       u32 domain,
-                      struct sk_buff *buf, 
+                      struct sk_buff *buf,
                       unsigned int dsz)
 {
        struct tipc_portid orig;
@@ -1587,15 +1582,15 @@ int tipc_send_buf2name(u32 ref,
                                     TIPC_PORT_IMPORTANCE);
 }
 
-/** 
+/**
  * tipc_forward2port - forward message sections to port identity
  */
 
 int tipc_forward2port(u32 ref,
                      struct tipc_portid const *dest,
-                     unsigned int num_sect, 
+                     unsigned int num_sect,
                      struct iovec const *msg_sect,
-                     struct tipc_portid const *orig, 
+                     struct tipc_portid const *orig,
                      unsigned int importance)
 {
        struct port *p_ptr;
@@ -1628,24 +1623,24 @@ int tipc_forward2port(u32 ref,
        return -ELINKCONG;
 }
 
-/** 
- * tipc_send2port - send message sections to port identity 
+/**
+ * tipc_send2port - send message sections to port identity
  */
 
-int tipc_send2port(u32 ref, 
+int tipc_send2port(u32 ref,
                   struct tipc_portid const *dest,
-                  unsigned int num_sect, 
+                  unsigned int num_sect,
                   struct iovec const *msg_sect)
 {
        struct tipc_portid orig;
 
        orig.ref = ref;
        orig.node = tipc_own_addr;
-       return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig, 
+       return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig,
                                 TIPC_PORT_IMPORTANCE);
 }
 
-/** 
+/**
  * tipc_forward_buf2port - forward message buffer to port identity
  */
 int tipc_forward_buf2port(u32 ref,
@@ -1677,7 +1672,7 @@ int tipc_forward_buf2port(u32 ref,
                return -ENOMEM;
 
        skb_push(buf, DIR_MSG_H_SIZE);
-       memcpy(buf->data, (unchar *)msg, DIR_MSG_H_SIZE);
+       skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE);
        msg_dbg(msg, "buf2port: ");
        p_ptr->sent++;
        if (dest->node == tipc_own_addr)
@@ -1690,20 +1685,20 @@ int tipc_forward_buf2port(u32 ref,
        return -ELINKCONG;
 }
 
-/** 
+/**
  * tipc_send_buf2port - send message buffer to port identity
  */
 
-int tipc_send_buf2port(u32 ref, 
+int tipc_send_buf2port(u32 ref,
                       struct tipc_portid const *dest,
-                      struct sk_buff *buf, 
+                      struct sk_buff *buf,
                       unsigned int dsz)
 {
        struct tipc_portid orig;
 
        orig.ref = ref;
        orig.node = tipc_own_addr;
-       return tipc_forward_buf2port(ref, dest, buf, dsz, &orig, 
+       return tipc_forward_buf2port(ref, dest, buf, dsz, &orig,
                                     TIPC_PORT_IMPORTANCE);
 }