Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 311746
b: refs/heads/master
c: 15fd943
h: refs/heads/master
v: v3
  • Loading branch information
Ohad Ben-Cohen committed Jul 4, 2012
1 parent b55004a commit 2af488d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5a081caa0414b9bbb82c17ffab9d6fe66edbb72f
refs/heads/master: 15fd943af50dbc5f7f4de33835795c72595f7bf4
25 changes: 19 additions & 6 deletions trunk/drivers/rpmsg/virtio_rpmsg_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
}

kref_init(&ept->refcount);
mutex_init(&ept->cb_lock);

ept->rpdev = rpdev;
ept->cb = cb;
Expand Down Expand Up @@ -324,10 +325,16 @@ EXPORT_SYMBOL(rpmsg_create_ept);
static void
__rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept)
{
/* make sure new inbound messages can't find this ept anymore */
mutex_lock(&vrp->endpoints_lock);
idr_remove(&vrp->endpoints, ept->addr);
mutex_unlock(&vrp->endpoints_lock);

/* make sure in-flight inbound messages won't invoke cb anymore */
mutex_lock(&ept->cb_lock);
ept->cb = NULL;
mutex_unlock(&ept->cb_lock);

kref_put(&ept->refcount, __ept_release);
}

Expand Down Expand Up @@ -821,14 +828,20 @@ static void rpmsg_recv_done(struct virtqueue *rvq)

mutex_unlock(&vrp->endpoints_lock);

if (ept && ept->cb)
ept->cb(ept->rpdev, msg->data, msg->len, ept->priv, msg->src);
else
dev_warn(dev, "msg received with no recepient\n");
if (ept) {
/* make sure ept->cb doesn't go away while we use it */
mutex_lock(&ept->cb_lock);

/* farewell, ept, we don't need you anymore */
if (ept)
if (ept->cb)
ept->cb(ept->rpdev, msg->data, msg->len, ept->priv,
msg->src);

mutex_unlock(&ept->cb_lock);

/* farewell, ept, we don't need you anymore */
kref_put(&ept->refcount, __ept_release);
} else
dev_warn(dev, "msg received with no recepient\n");

/* publish the real size of the buffer */
sg_init_one(&sg, msg, RPMSG_BUF_SIZE);
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/rpmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <linux/device.h>
#include <linux/mod_devicetable.h>
#include <linux/kref.h>
#include <linux/mutex.h>

/* The feature bitmap for virtio rpmsg */
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
Expand Down Expand Up @@ -123,6 +124,7 @@ typedef void (*rpmsg_rx_cb_t)(struct rpmsg_channel *, void *, int, void *, u32);
* @rpdev: rpmsg channel device
* @refcount: when this drops to zero, the ept is deallocated
* @cb: rx callback handler
* @cb_lock: must be taken before accessing/changing @cb
* @addr: local rpmsg address
* @priv: private data for the driver's use
*
Expand All @@ -144,6 +146,7 @@ struct rpmsg_endpoint {
struct rpmsg_channel *rpdev;
struct kref refcount;
rpmsg_rx_cb_t cb;
struct mutex cb_lock;
u32 addr;
void *priv;
};
Expand Down

0 comments on commit 2af488d

Please sign in to comment.