caif: Add reference counting to service layer
authorSjur Braendeland <sjur.brandeland@stericsson.com>
Wed, 28 Apr 2010 08:54:36 +0000 (08:54 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Apr 2010 19:55:12 +0000 (12:55 -0700)
Changes:
o Added functions cfsrvl_get and cfsrvl_put.
o Added support release_client to use by socket and net device.
o Increase reference counting for in-flight packets from cfmuxl

Signed-off-by: Sjur Braendeland <sjur.brandeland@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/caif/caif_dev.h
include/net/caif/cfcnfg.h
include/net/caif/cfsrvl.h
net/caif/caif_dev.c
net/caif/cfcnfg.c
net/caif/cfmuxl.c
net/caif/cfsrvl.c

index 3aa1ff642323fd0f247129577256f013b4208c1e..318ab9478a446e078e3b466db81c1252b246670f 100644 (file)
@@ -69,6 +69,17 @@ int caif_connect_client(struct caif_connect_request *config,
  */
 int caif_disconnect_client(struct cflayer *client_layer);
 
+/**
+ * caif_release_client - Release adaptation layer reference to client.
+ *
+ * @client_layer: Client layer.
+ *
+ * Releases a client/adaptation layer use of the caif stack.
+ * This function must be used after caif_disconnect_client to
+ * decrease the reference count of the service layer.
+ */
+void caif_release_client(struct cflayer *client_layer);
+
 /**
  * connect_req_to_link_param - Translate configuration parameters
  *                             from socket format to internal format.
index f16b875acc48caf6a7e3c4c28715d694eeb1c45b..9fc2fc20b884287ab706de28f08d4dadc3f3906a 100644 (file)
@@ -96,6 +96,13 @@ int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer);
 int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg,
                        struct cflayer *adap_layer);
 
+/**
+ * cfcnfg_release_adap_layer - Used by client to release the adaptation layer.
+ *
+ * @adap_layer: Adaptation layer.
+ */
+void cfcnfg_release_adap_layer(struct cflayer *adap_layer);
+
 /**
  * cfcnfg_add_adaptation_layer - Add an adaptation layer to the CAIF stack.
  *
index b2a12db20cd224b230e7d6d21d2fb740bd1445ac..2dc9eb193ecf8ae3fcab37586a28a08310472986 100644 (file)
@@ -9,14 +9,18 @@
 #include <linux/list.h>
 #include <linux/stddef.h>
 #include <linux/types.h>
+#include <linux/kref.h>
+
 struct cfsrvl {
        struct cflayer layer;
        bool open;
        bool phy_flow_on;
        bool modem_flow_on;
        struct dev_info dev_info;
+       struct kref ref;
 };
 
+void cfsrvl_release(struct kref *kref);
 struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info);
 struct cflayer *cfdgml_create(u8 linkid, struct dev_info *dev_info);
 struct cflayer *cfutill_create(u8 linkid, struct dev_info *dev_info);
@@ -31,4 +35,22 @@ void cfsrvl_init(struct cfsrvl *service,
 bool cfsrvl_ready(struct cfsrvl *service, int *err);
 u8 cfsrvl_getphyid(struct cflayer *layer);
 
+static inline void cfsrvl_get(struct cflayer *layr)
+{
+       struct cfsrvl *s;
+       if (layr == NULL)
+               return;
+       s = container_of(layr, struct cfsrvl, layer);
+       kref_get(&s->ref);
+}
+
+static inline void cfsrvl_put(struct cflayer *layr)
+{
+       struct cfsrvl *s;
+       if (layr == NULL)
+               return;
+       s = container_of(layr, struct cfsrvl, layer);
+       kref_put(&s->ref, cfsrvl_release);
+}
+
 #endif                         /* CFSRVL_H_ */
index be1f674a3b676973f386ceb635d7425fcda22f90..0145bae0274f0162f68de48aebc9835ceef66dda 100644 (file)
@@ -346,6 +346,12 @@ int caif_disconnect_client(struct cflayer *adap_layer)
 }
 EXPORT_SYMBOL(caif_disconnect_client);
 
+void caif_release_client(struct cflayer *adap_layer)
+{
+       cfcnfg_release_adap_layer(adap_layer);
+}
+EXPORT_SYMBOL(caif_release_client);
+
 /* Per-namespace Caif devices handling */
 static int caif_init_net(struct net *net)
 {
index d52f2566916e81d77624fc95721555f8bedcada5..f94f3dfe85c1b78919075f2bc39149795aee12b6 100644 (file)
@@ -247,6 +247,13 @@ end:
 }
 EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer);
 
+void cfcnfg_release_adap_layer(struct cflayer *adap_layer)
+{
+       if (adap_layer->dn)
+               cfsrvl_put(adap_layer->dn);
+}
+EXPORT_SYMBOL(cfcnfg_release_adap_layer);
+
 static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id,
                                  struct cflayer *client_layer)
 {
index 6fb9f9e96cf8a242cc3f3e5e299a54c231621f84..7372f27f1d328c511374bdb29f7a63751d9fa5bb 100644 (file)
@@ -62,6 +62,7 @@ int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
 {
        struct cfmuxl *muxl = container_obj(layr);
        spin_lock(&muxl->receive_lock);
+       cfsrvl_get(up);
        list_add(&up->node, &muxl->srvl_list);
        spin_unlock(&muxl->receive_lock);
        return 0;
@@ -172,8 +173,11 @@ struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 id)
        struct cfmuxl *muxl = container_obj(layr);
        spin_lock(&muxl->receive_lock);
        up = get_up(muxl, id);
+       if (up == NULL)
+               return NULL;
        memset(muxl->up_cache, 0, sizeof(muxl->up_cache));
        list_del(&up->node);
+       cfsrvl_put(up);
        spin_unlock(&muxl->receive_lock);
        return up;
 }
@@ -203,8 +207,9 @@ static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt)
                 */
                return /* CFGLU_EPROT; */ 0;
        }
-
+       cfsrvl_get(up);
        ret = up->receive(up, pkt);
+       cfsrvl_put(up);
        return ret;
 }
 
index d470c51c6431259a19f1ca3752c09a0f5518e2af..aff31f34528f8e7748d3a804b736e410787ac34f 100644 (file)
@@ -158,6 +158,13 @@ void cfsrvl_init(struct cfsrvl *service,
        service->layer.ctrlcmd = cfservl_ctrlcmd;
        service->layer.modemcmd = cfservl_modemcmd;
        service->dev_info = *dev_info;
+       kref_init(&service->ref);
+}
+
+void cfsrvl_release(struct kref *kref)
+{
+       struct cfsrvl *service = container_of(kref, struct cfsrvl, ref);
+       kfree(service);
 }
 
 bool cfsrvl_ready(struct cfsrvl *service, int *err)