tipc: some small patches
Subsystems (3)
cover tipc: some small patches
Some small and relatively straightforward patches that fix a number of minor issues. The patches are functionally unrelated to each other.
Ying Xue (5):
tipc: silence sparse warnings
tipc: make bearer and media naming consistent
tipc: avoid unnecessary lookup for tipc bearer instance
tipc: correct return value of recv_msg routine
tipc: correct return value of link_cmd_set_value routine
net/tipc/bearer.c | 18 ++++--------- net/tipc/bearer.h | 10 ++++---- net/tipc/eth_media.c | 68 +++++++++++++++++++++++++------------------------- net/tipc/ib_media.c | 58 +++++++++++++++++++++--------------------- net/tipc/link.c | 33 ++++++++++++++++-------- net/tipc/msg.c | 4 +-- net/tipc/socket.c | 6 ++--- 7 files changed, 100 insertions(+), 97 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/5 tipc: silence sparse warnings
From: Ying Xue <[email protected]>
Eliminate below sparse warnings:
net/tipc/link.c:1210:37: warning: cast removes address space of expression net/tipc/link.c:1218:59: warning: incorrect type in argument 2 (different address spaces)net/tipc/link.c:1218:59: expected void const [noderef] <asn:1>*fromnet/tipc/link.c:1218:59: got unsigned char const [usertype] *[assigned] sect_crsnet/tipc/msg.c:96:61: warning: incorrect type in argument 3 (different address spaces)net/tipc/msg.c:96:61: expected void const *fromnet/tipc/msg.c:96:61: got void [noderef] <asn:1>*const iov_basenet/tipc/socket.c:341:49: warning: Using plain integer as NULL pointer net/tipc/socket.c:1371:36: warning: Using plain integer as NULL pointer net/tipc/socket.c:1694:57: warning: Using plain integer as NULL pointer
--- net/tipc/link.c | 5 +++-- net/tipc/msg.c | 4 ++-- net/tipc/socket.c | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-)
net/tipc/link.c +3 -2
@@ -1165,7 +1165,7 @@ static int link_send_sections_long(struct tipc_port *sender,struct tipc_msg fragm_hdr;struct sk_buff *buf, *buf_chain, *prev;u32 fragm_crs, fragm_rest, hsz, sect_rest; -const unchar *sect_crs; +const unchar __user *sect_crs;int curr_sect;u32 fragm_no;int res =0 ;
@@ -1207,7 +1207,8 @@ again:if (!sect_rest) { sect_rest = msg_sect[++curr_sect].iov_len; - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base; + sect_crs = + (const unchar __user *)msg_sect[curr_sect].iov_base; }if (sect_rest < fragm_rest)
net/tipc/msg.c +2 -2
@@ -93,8 +93,8 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,skb_copy_to_linear_data (*buf, hdr, hsz);for (res =1 , cnt =0 ; res && (cnt < num_sect); cnt++) {skb_copy_to_linear_data_offset (*buf, pos, - msg_sect[cnt].iov_base, - msg_sect[cnt].iov_len); + (const void __force *)msg_sect[cnt].iov_base, + msg_sect[cnt].iov_len); pos += msg_sect[cnt].iov_len; }if (likely (res))
net/tipc/socket.c +3 -3
@@ -338,7 +338,7 @@ static int release(struct socket *sock) buf =__skb_dequeue (&sk->sk_receive_queue);if (buf ==NULL )break ; -if (TIPC_SKB_CB (buf)->handle !=0 ) +if (TIPC_SKB_CB (buf)->handle !=NULL )kfree_skb (buf);else { if ((sock->state == SS_CONNECTING) ||
@@ -1368,7 +1368,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)return TIPC_ERR_OVERLOAD ;/* Enqueue message */ -TIPC_SKB_CB (buf)->handle =0 ; +TIPC_SKB_CB (buf)->handle =NULL ;__skb_queue_tail (&sk->sk_receive_queue, buf);skb_set_owner_r (buf, sk);
@@ -1691,7 +1691,7 @@ restart:/* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ buf =__skb_dequeue (&sk->sk_receive_queue);if (buf) { -if (TIPC_SKB_CB (buf)->handle !=0 ) { +if (TIPC_SKB_CB (buf)->handle !=NULL ) {kfree_skb (buf); goto restart; }
Signature · 1 line
1.7.9.5
David Miller
maintainerRe: [PATCH net-next 1/5] tipc: silence sparse warnings
From: Jon Maloy <[email protected]>
Date: Tue, 24 Sep 2013 04:27:44 -0500
Quoted 15 lines
From: Ying Xue <[email protected]>
Eliminate below sparse warnings:
net/tipc/link.c:1210:37: warning: cast removes address space of expressionnet/tipc/link.c:1218:59: warning: incorrect type in argument 2 (different address spaces)net/tipc/link.c:1218:59: expected void const [noderef] <asn:1>*fromnet/tipc/link.c:1218:59: got unsigned char const [usertype] *[assigned]sect_crsnet/tipc/msg.c:96:61: warning: incorrect type in argument 3 (different address spaces)net/tipc/msg.c:96:61: expected void const *fromnet/tipc/msg.c:96:61: got void [noderef] <asn:1>*constiov_basenet/tipc/socket.c:341:49: warning: Using plain integer as NULL pointernet/tipc/socket.c:1371:36: warning: Using plain integer as NULL pointernet/tipc/socket.c:1694:57: warning: Using plain integer as NULL pointer
Quoted 4 lines
Signed-off-by Ying Xue <[email protected]>Signed-off-by Andreas Bofjäll <[email protected]>Reviewed-by Paul Gortmaker <[email protected]>Signed-off-by Jon Maloy <[email protected]>
These warnings are not just for fun, and they are certainly not an invitation to stick casts all over the place to make them go away.
They indicate real problems in the TIPC code.
There really are user pointers in the iovecs here, and that's why the iov_base member is annotated with "__user".
These iovecs carry pointers that come from userspace via socket calls.
And you absolutely cannot pass user pointers to skb_copy_to_linear_data() and friends as they access the source pointer using memcpy().
You have to use the proper interfaces for accessing userspace memory, ones that have their arguments annotated with __user.
I'm not applying this series, sorry.
Re: [PATCH net-next 1/5] tipc: silence sparse warnings
Quoted 28 lines · David Miller
From: Jon Maloy <[email protected]>
Date: Tue, 24 Sep 2013 04:27:44 -0500Quoted 15 lines
From: Ying Xue <[email protected]>
Eliminate below sparse warnings:
net/tipc/link.c:1210:37: warning: cast removes address space of expressionnet/tipc/link.c:1218:59: warning: incorrect type in argument 2 (different address spaces)net/tipc/link.c:1218:59: expected void const [noderef] <asn:1>*fromnet/tipc/link.c:1218:59: got unsigned char const [usertype] *[assigned]sect_crsnet/tipc/msg.c:96:61: warning: incorrect type in argument 3 (different address spaces)net/tipc/msg.c:96:61: expected void const *fromnet/tipc/msg.c:96:61: got void [noderef] <asn:1>*constiov_basenet/tipc/socket.c:341:49: warning: Using plain integer as NULL pointernet/tipc/socket.c:1371:36: warning: Using plain integer as NULL pointernet/tipc/socket.c:1694:57: warning: Using plain integer as NULL pointerQuoted 4 lines
Signed-off-by Ying Xue <[email protected]>Signed-off-by Andreas Bofjäll <[email protected]>Reviewed-by Paul Gortmaker <[email protected]>Signed-off-by Jon Maloy <[email protected]>These warnings are not just for fun, and they are certainly not an invitation to stick casts all over the place to make them go away.
They indicate real problems in the TIPC code.
Quoted 8 lines
There really are user pointers in the iovecs here, and that's why the
iov_basemember is annotated with "__user".These iovecs carry pointers that come from userspace via socket calls.
And you absolutely cannot pass user pointers to
skb_copy_to_linear_data()and friends as they access the source pointer usingmemcpy().
Good point!
It's better for us to use memcpy_fromiovecend() instead of skb_copy_to_linear_data() and its friends.
We will submit another version to correct this error soon.
Regards,
Ying
Quoted 6 lines
You have to use the proper interfaces for accessing userspace memory, ones that have their arguments annotated with
__user.I'm not applying this series, sorry.
Re: [PATCH net-next 1/5] tipc: silence sparse warnings
Quoted 5 lines · Ying Xue
Good point!
It's better for us to usememcpy_fromiovecend()instead ofskb_copy_to_linear_data()and its friends.We will submit another version to correct this error soon.
I could be wrong here, but I think you should also remove the entire cast on line 1210 in link.c:
sect_crs = msg_sect[curr_sect].iov_base;
There should be no reason to cast there since you made sect_crs into const unchar* __user and msg_sect[].iov_base is void* __user.
/Andreas
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
Re: [PATCH net-next 1/5] tipc: silence sparse warnings
Quoted 7 lines · Andreas Bofjäll
Quoted 5 lines · Ying Xue
Good point!
It's better for us to usememcpy_fromiovecend()instead ofskb_copy_to_linear_data()and its friends.We will submit another version to correct this error soon.
Quoted 8 lines
I could be wrong here, but I think you should also remove the entire cast on line 1210 in
link.c:
sect_crs= msg_sect[curr_sect].iov_base;There should be no reason to cast there since you made
sect_crsinto const unchar*__userand msg_sect[].iov_base is void*__user.
You are right, thank you for your nice reminder!
Regards,
Ying
Quoted 3 lines
/Andreas
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
Re: [PATCH net-next 1/5] tipc: silence sparse warnings
Quoted 7 lines · Ying Xue
Quoted 6 lines · Andreas Bofjäll
Quoted 5 lines · Ying Xue
Good point!
It's better for us to usememcpy_fromiovecend()instead ofskb_copy_to_linear_data()and its friends.We will submit another version to correct this error soon.
Can you fix this asap, so I can re-post it? And, let's continue the thread in tipc-discussion only until we (incl Paul) are happy with this patch.
///jon
Quoted 16 lines
Quoted 8 lines
I could be wrong here, but I think you should also remove the entire cast on line 1210 in
link.c:
sect_crs= msg_sect[curr_sect].iov_base;There should be no reason to cast there since you made
sect_crsinto const unchar*__userand msg_sect[].iov_base is void*__user.You are right, thank you for your nice reminder!
Regards,
YingQuoted 3 lines
/Andreas
PATCH 2/5 tipc: make bearer and media naming consistent
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
TIPC 'bearer' exists as an abstract concept, while 'media' is deemed a specific implementation of a bearer, such as Ethernet or Infiniband media. When a component inside TIPC wants to control a specific media, it only needs to access the generic bearer API to achieve this. However, in the current media implementations, the 'bearer' name is also extensively used in media specific function and variable names.
This may create confusion, so we choose to replace the term 'bearer' with 'media' in all function names, variable names, and prefixes where this is what really is meant.
Note that this change is cosmetic only, and no runtime behaviour changes are made here.
--- net/tipc/bearer.c | 4 ++-- net/tipc/bearer.h | 8 ++++---- net/tipc/eth_media.c | 56 +++++++++++++++++++++++++------------------------- net/tipc/ib_media.c | 46 ++++++++++++++++++++--------------------- 4 files changed, 57 insertions(+), 57 deletions(-)
net/tipc/bearer.c +2 -2
@@ -387,7 +387,7 @@ restart: b_ptr = &tipc_bearers[bearer_id];strcpy (b_ptr->name, name); - res = m_ptr->enable_bearer (b_ptr); + res = m_ptr->enable_media (b_ptr);if (res) {pr_warn ("Bearer <%s> rejected, enable failure (%d)\n" , name, -res);
@@ -465,7 +465,7 @@ static void bearer_disable(struct tipc_bearer *b_ptr)pr_info ("Disabling bearer <%s>\n" , b_ptr->name);spin_lock_bh (&b_ptr->lock); b_ptr->blocked =1 ; - b_ptr->media->disable_bearer (b_ptr); + b_ptr->media->disable_media (b_ptr);list_for_each_entry_safe (l_ptr, temp_l_ptr, &b_ptr->links, link_list) {tipc_link_delete (l_ptr); }
net/tipc/bearer.h +4 -4
@@ -75,8 +75,8 @@ struct tipc_bearer;/** * struct tipc_media - TIPC media information available to internal users * @send_msg: routine which handles buffer transmission -* @enable_bearer: routine which enables a bearer -* @disable_bearer: routine which disables a bearer +* @enable_media: routine which enables a media +* @disable_media: routine which disables a media * @addr2str: routine which converts media address to string * @addr2msg: routine which converts media address to protocol message area * @msg2addr: routine which converts media address from protocol message area
@@ -91,8 +91,8 @@ struct tipc_media {int (*send_msg)(struct sk_buff *buf,struct tipc_bearer *b_ptr,struct tipc_media_addr *dest); -int (*enable_bearer)(struct tipc_bearer *b_ptr); -void (*disable_bearer)(struct tipc_bearer *b_ptr); +int (*enable_media)(struct tipc_bearer *b_ptr); +void (*disable_media)(struct tipc_bearer *b_ptr);int (*addr2str)(struct tipc_media_addr *a,char *str_buf,int str_size);int (*addr2msg)(struct tipc_media_addr *a,char *msg_area); int (*msg2addr)(const struct tipc_bearer *b_ptr,
net/tipc/eth_media.c +28 -28
154 lines not on this page · raw message
net/tipc/ib_media.c +23 -23
129 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 3/5 tipc: avoid unnecessary lookup for tipc bearer instance
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
tipc_block_bearer() currently takes a bearer name (const char*) as argument. This requires the function to make a lookup to find the pointer to the corresponding bearer struct. In the current code base this is not necessary, since the only two callers (tipc_continue(),recv_notification()) already have validated copies of this pointer, and hence can pass it directly in the function call.
We change tipc_block_bearer() to directly take struct tipc_bearer* as argument instead.
--- net/tipc/bearer.c | 14 +++----------- net/tipc/bearer.h | 2 +- net/tipc/eth_media.c | 6 +++--- net/tipc/ib_media.c | 6 +++--- 4 files changed, 10 insertions(+), 18 deletions(-)
net/tipc/bearer.c +3 -11
@@ -420,23 +420,15 @@ exit: }/** -* tipc_block_bearer - Block the bearer with the given name, and reset all its links +* tipc_block_bearer - Block the bearer, and reset all its links */ -int tipc_block_bearer (const char *name) +int tipc_block_bearer (struct tipc_bearer *b_ptr) { -struct tipc_bearer *b_ptr =NULL ;struct tipc_link *l_ptr;struct tipc_link *temp_l_ptr;read_lock_bh (&tipc_net_lock); - b_ptr =tipc_bearer_find (name); -if (!b_ptr) { -pr_warn ("Attempt to block unknown bearer <%s>\n" , name); -read_unlock_bh (&tipc_net_lock); -return -EINVAL ; - } - -pr_info ("Blocking bearer <%s>\n" , name); +pr_info ("Blocking bearer <%s>\n" , b_ptr->name);spin_lock_bh (&b_ptr->lock); b_ptr->blocked =1 ;list_for_each_entry_safe (l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
net/tipc/bearer.h +1 -1
@@ -163,7 +163,7 @@ int tipc_register_media(struct tipc_media *m_ptr);void tipc_recv_msg (struct sk_buff *buf,struct tipc_bearer *tb_ptr); -int tipc_block_bearer (const char *name); +int tipc_block_bearer (struct tipc_bearer *b_ptr);void tipc_continue (struct tipc_bearer *tb_ptr);int tipc_enable_bearer (const char *bearer_name,u32 disc_domain,u32 priority);
net/tipc/eth_media.c +3 -3
@@ -265,17 +265,17 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,if (netif_carrier_ok (dev))tipc_continue (eb_ptr->bearer);else -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);break ;case NETDEV_UP :tipc_continue (eb_ptr->bearer);break ;case NETDEV_DOWN : -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);break ;case NETDEV_CHANGEMTU :case NETDEV_CHANGEADDR : -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);tipc_continue (eb_ptr->bearer);break ;case NETDEV_UNREGISTER :
net/tipc/ib_media.c +3 -3
@@ -258,17 +258,17 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,if (netif_carrier_ok (dev))tipc_continue (ib_ptr->bearer);else -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);break ;case NETDEV_UP :tipc_continue (ib_ptr->bearer);break ;case NETDEV_DOWN : -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);break ;case NETDEV_CHANGEMTU :case NETDEV_CHANGEADDR : -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);tipc_continue (ib_ptr->bearer);break ;case NETDEV_UNREGISTER :
Signature · 1 line
1.7.9.5
PATCH 4/5 tipc: correct return value of recv_msg routine
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
Currently, rcv_msg() always returns zero on a packet delivery upcall from net_device.
To make its behavior more compliant with the way this API should be used, we change this to let it return NET_RX_SUCCESS (which is zero anyway) when it is able to handle the packet, and NET_RX_DROP otherwise. The latter does not imply any functional change, it only enables the driver to keep more accurate statistics about the fate of delivered packets.
--- net/tipc/eth_media.c | 6 +++--- net/tipc/ib_media.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
net/tipc/eth_media.c +3 -3
@@ -132,18 +132,18 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }if (likely (eb_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { buf->next =NULL ;tipc_recv_msg (buf, eb_ptr->bearer); -return 0 ; +return NET_RX_SUCCESS ; } }kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }/**
net/tipc/ib_media.c +3 -3
@@ -125,18 +125,18 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }if (likely (ib_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { buf->next =NULL ;tipc_recv_msg (buf, ib_ptr->bearer); -return 0 ; +return NET_RX_SUCCESS ; } }kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }/**
Signature · 1 line
1.7.9.5
PATCH 5/5 tipc: correct return value of link_cmd_set_value routine
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
link_cmd_set_value() takes commands for link, bearer and media related configuration. Genereally the function returns 0 when a command is recognized, and -EINVAL when it is not. However, in the switch for link related commands it returns 0 even when the command is unrecognized. This will sometimes make it look as if a failed configuration command has been successful, but has otherwise no negative effects.
We remove this anomaly by returning -EINVAL even for link commands. We also rework all three switches to make them conforming to common kernel coding style.
--- net/tipc/link.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
net/tipc/link.c +19 -9
@@ -2647,6 +2647,7 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)struct tipc_link *l_ptr;struct tipc_bearer *b_ptr;struct tipc_media *m_ptr; +int res =0 ; l_ptr =link_find_link (name, &node);if (l_ptr) {
@@ -2669,9 +2670,12 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)case TIPC_CMD_SET_LINK_WINDOW :tipc_link_set_queue_limits (l_ptr, new_value);break ; +default : + res = -EINVAL ; +break ; }tipc_node_unlock (node); -return 0 ; +return res; } b_ptr =tipc_bearer_find (name);
@@ -2679,15 +2683,18 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)switch (cmd) {case TIPC_CMD_SET_LINK_TOL : b_ptr->tolerance = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_PRI : b_ptr->priority = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_WINDOW : b_ptr->window = new_value; -return 0 ; +break ; +default : + res = -EINVAL ; +break ; } -return -EINVAL ; +return res; } m_ptr =tipc_media_find (name);
@@ -2696,15 +2703,18 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)switch (cmd) {case TIPC_CMD_SET_LINK_TOL : m_ptr->tolerance = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_PRI : m_ptr->priority = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_WINDOW : m_ptr->window = new_value; -return 0 ; +break ; +default : + res = -EINVAL ; +break ; } -return -EINVAL ; +return res; } struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Signature · 1 line
1.7.9.5