Skip to content

Commit 5b20865

Browse files
Sjur Braendelanddavem330
authored andcommitted
caif: Add reference counting to service layer
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>
1 parent e539d83 commit 5b20865

7 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎include/net/caif/caif_dev.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ int caif_connect_client(struct caif_connect_request *config,
6969
*/
7070
int caif_disconnect_client(struct cflayer *client_layer);
7171

72+
/**
73+
* caif_release_client - Release adaptation layer reference to client.
74+
*
75+
* @client_layer: Client layer.
76+
*
77+
* Releases a client/adaptation layer use of the caif stack.
78+
* This function must be used after caif_disconnect_client to
79+
* decrease the reference count of the service layer.
80+
*/
81+
void caif_release_client(struct cflayer *client_layer);
82+
7283
/**
7384
* connect_req_to_link_param - Translate configuration parameters
7485
* from socket format to internal format.

‎include/net/caif/cfcnfg.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ int cfcnfg_del_phy_layer(struct cfcnfg *cnfg, struct cflayer *phy_layer);
9696
int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg,
9797
struct cflayer *adap_layer);
9898

99+
/**
100+
* cfcnfg_release_adap_layer - Used by client to release the adaptation layer.
101+
*
102+
* @adap_layer: Adaptation layer.
103+
*/
104+
void cfcnfg_release_adap_layer(struct cflayer *adap_layer);
105+
99106
/**
100107
* cfcnfg_add_adaptation_layer - Add an adaptation layer to the CAIF stack.
101108
*

‎include/net/caif/cfsrvl.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
#include <linux/list.h>
1010
#include <linux/stddef.h>
1111
#include <linux/types.h>
12+
#include <linux/kref.h>
13+
1214
struct cfsrvl {
1315
struct cflayer layer;
1416
bool open;
1517
bool phy_flow_on;
1618
bool modem_flow_on;
1719
struct dev_info dev_info;
20+
struct kref ref;
1821
};
1922

23+
void cfsrvl_release(struct kref *kref);
2024
struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info);
2125
struct cflayer *cfdgml_create(u8 linkid, struct dev_info *dev_info);
2226
struct cflayer *cfutill_create(u8 linkid, struct dev_info *dev_info);
@@ -31,4 +35,22 @@ void cfsrvl_init(struct cfsrvl *service,
3135
bool cfsrvl_ready(struct cfsrvl *service, int *err);
3236
u8 cfsrvl_getphyid(struct cflayer *layer);
3337

38+
static inline void cfsrvl_get(struct cflayer *layr)
39+
{
40+
struct cfsrvl *s;
41+
if (layr == NULL)
42+
return;
43+
s = container_of(layr, struct cfsrvl, layer);
44+
kref_get(&s->ref);
45+
}
46+
47+
static inline void cfsrvl_put(struct cflayer *layr)
48+
{
49+
struct cfsrvl *s;
50+
if (layr == NULL)
51+
return;
52+
s = container_of(layr, struct cfsrvl, layer);
53+
kref_put(&s->ref, cfsrvl_release);
54+
}
55+
3456
#endif /* CFSRVL_H_ */

‎net/caif/caif_dev.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ int caif_disconnect_client(struct cflayer *adap_layer)
346346
}
347347
EXPORT_SYMBOL(caif_disconnect_client);
348348

349+
void caif_release_client(struct cflayer *adap_layer)
350+
{
351+
cfcnfg_release_adap_layer(adap_layer);
352+
}
353+
EXPORT_SYMBOL(caif_release_client);
354+
349355
/* Per-namespace Caif devices handling */
350356
static int caif_init_net(struct net *net)
351357
{

‎net/caif/cfcnfg.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg, struct cflayer *adap_layer)
247247
}
248248
EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer);
249249

250+
void cfcnfg_release_adap_layer(struct cflayer *adap_layer)
251+
{
252+
if (adap_layer->dn)
253+
cfsrvl_put(adap_layer->dn);
254+
}
255+
EXPORT_SYMBOL(cfcnfg_release_adap_layer);
256+
250257
static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id,
251258
struct cflayer *client_layer)
252259
{

‎net/caif/cfmuxl.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
6262
{
6363
struct cfmuxl *muxl = container_obj(layr);
6464
spin_lock(&muxl->receive_lock);
65+
cfsrvl_get(up);
6566
list_add(&up->node, &muxl->srvl_list);
6667
spin_unlock(&muxl->receive_lock);
6768
return 0;
@@ -172,8 +173,11 @@ struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 id)
172173
struct cfmuxl *muxl = container_obj(layr);
173174
spin_lock(&muxl->receive_lock);
174175
up = get_up(muxl, id);
176+
if (up == NULL)
177+
return NULL;
175178
memset(muxl->up_cache, 0, sizeof(muxl->up_cache));
176179
list_del(&up->node);
180+
cfsrvl_put(up);
177181
spin_unlock(&muxl->receive_lock);
178182
return up;
179183
}
@@ -203,8 +207,9 @@ static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt)
203207
*/
204208
return /* CFGLU_EPROT; */ 0;
205209
}
206-
210+
cfsrvl_get(up);
207211
ret = up->receive(up, pkt);
212+
cfsrvl_put(up);
208213
return ret;
209214
}
210215

‎net/caif/cfsrvl.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ void cfsrvl_init(struct cfsrvl *service,
158158
service->layer.ctrlcmd = cfservl_ctrlcmd;
159159
service->layer.modemcmd = cfservl_modemcmd;
160160
service->dev_info = *dev_info;
161+
kref_init(&service->ref);
162+
}
163+
164+
void cfsrvl_release(struct kref *kref)
165+
{
166+
struct cfsrvl *service = container_of(kref, struct cfsrvl, ref);
167+
kfree(service);
161168
}
162169

163170
bool cfsrvl_ready(struct cfsrvl *service, int *err)

0 commit comments

Comments
 (0)