Commit b191ba0d599928372be5a89f75486eb58efab48a
Committed by
David S. Miller
1 parent
0ac81ae34e
Exists in
master
and in
4 other branches
[CONNECTOR]: Use netlink_has_listeners() to avoind unnecessary allocations.
Return -ESRCH from cn_netlink_send() when there are not listeners, just as it could be done by netlink_broadcast(). Propagate netlink_broadcast() error back to the caller. Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 2 changed files with 7 additions and 5 deletions Side-by-side Diff
Documentation/connector/connector.txt
... | ... | @@ -69,10 +69,11 @@ |
69 | 69 | |
70 | 70 | struct cb_id *id - unique connector's user identifier. |
71 | 71 | |
72 | -void cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask); | |
72 | +int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask); | |
73 | 73 | |
74 | 74 | Sends message to the specified groups. It can be safely called from |
75 | -any context, but may silently fail under strong memory pressure. | |
75 | +softirq context, but may silently fail under strong memory pressure. | |
76 | +If there are no listeners for given group -ESRCH can be returned. | |
76 | 77 | |
77 | 78 | struct cn_msg * - message header(with attached data). |
78 | 79 | u32 __group - destination group. |
drivers/connector/connector.c
... | ... | @@ -97,6 +97,9 @@ |
97 | 97 | group = __group; |
98 | 98 | } |
99 | 99 | |
100 | + if (!netlink_has_listeners(dev->nls, group)) | |
101 | + return -ESRCH; | |
102 | + | |
100 | 103 | size = NLMSG_SPACE(sizeof(*msg) + msg->len); |
101 | 104 | |
102 | 105 | skb = alloc_skb(size, gfp_mask); |
... | ... | @@ -111,9 +114,7 @@ |
111 | 114 | |
112 | 115 | NETLINK_CB(skb).dst_group = group; |
113 | 116 | |
114 | - netlink_broadcast(dev->nls, skb, 0, group, gfp_mask); | |
115 | - | |
116 | - return 0; | |
117 | + return netlink_broadcast(dev->nls, skb, 0, group, gfp_mask); | |
117 | 118 | |
118 | 119 | nlmsg_failure: |
119 | 120 | kfree_skb(skb); |