[CONNECTOR]: Use netlink_has_listeners() to avoind unnecessary allocations.
authorEvgeniy Polyakov <johnpol@2ka.mipt.ru>
Tue, 21 Mar 2006 06:21:40 +0000 (22:21 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 21 Mar 2006 06:21:40 +0000 (22:21 -0800)
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>
Documentation/connector/connector.txt
drivers/connector/connector.c

index 57a314b..ad6e0ba 100644 (file)
@@ -69,10 +69,11 @@ Unregisters new callback with connector core.
 
 struct cb_id *id               - unique connector's user identifier.
 
-void cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask);
+int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask);
 
 Sends message to the specified groups.  It can be safely called from
-any context, but may silently fail under strong memory pressure.
+softirq context, but may silently fail under strong memory pressure.
+If there are no listeners for given group -ESRCH can be returned.
 
 struct cn_msg *                        - message header(with attached data).
 u32 __group                    - destination group.
index 505677f..d7125f4 100644 (file)
@@ -97,6 +97,9 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
                group = __group;
        }
 
+       if (!netlink_has_listeners(dev->nls, group))
+               return -ESRCH;
+
        size = NLMSG_SPACE(sizeof(*msg) + msg->len);
 
        skb = alloc_skb(size, gfp_mask);
@@ -111,9 +114,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
 
        NETLINK_CB(skb).dst_group = group;
 
-       netlink_broadcast(dev->nls, skb, 0, group, gfp_mask);
-
-       return 0;
+       return netlink_broadcast(dev->nls, skb, 0, group, gfp_mask);
 
 nlmsg_failure:
        kfree_skb(skb);