Skip to content

Commit

Permalink
soc: qcom: smd: Introduce callback setter
Browse files Browse the repository at this point in the history
Introduce a setter for the callback function pointer to clarify the
locking around the operation and to reduce some duplication.

Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
  • Loading branch information
Bjorn Andersson authored and Andy Gross committed Mar 30, 2016
1 parent 3b904b0 commit 39f0db2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 17 additions & 8 deletions drivers/soc/qcom/smd.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct qcom_smd_channel {
int fifo_size;

void *bounce_buffer;
int (*cb)(struct qcom_smd_device *, const void *, size_t);
qcom_smd_cb_t cb;

spinlock_t recv_lock;

Expand Down Expand Up @@ -377,6 +377,19 @@ static void qcom_smd_channel_reset(struct qcom_smd_channel *channel)
channel->pkt_size = 0;
}

/*
* Set the callback for a channel, with appropriate locking
*/
static void qcom_smd_channel_set_callback(struct qcom_smd_channel *channel,
qcom_smd_cb_t cb)
{
unsigned long flags;

spin_lock_irqsave(&channel->recv_lock, flags);
channel->cb = cb;
spin_unlock_irqrestore(&channel->recv_lock, flags);
};

/*
* Calculate the amount of data available in the rx fifo
*/
Expand Down Expand Up @@ -814,8 +827,7 @@ static int qcom_smd_dev_probe(struct device *dev)
if (!channel->bounce_buffer)
return -ENOMEM;

channel->cb = qsdrv->callback;

qcom_smd_channel_set_callback(channel, qsdrv->callback);
qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING);

qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED);
Expand All @@ -831,7 +843,7 @@ static int qcom_smd_dev_probe(struct device *dev)
err:
dev_err(&qsdev->dev, "probe failed\n");

channel->cb = NULL;
qcom_smd_channel_set_callback(channel, NULL);
kfree(channel->bounce_buffer);
channel->bounce_buffer = NULL;

Expand All @@ -850,16 +862,13 @@ static int qcom_smd_dev_remove(struct device *dev)
struct qcom_smd_device *qsdev = to_smd_device(dev);
struct qcom_smd_driver *qsdrv = to_smd_driver(dev);
struct qcom_smd_channel *channel = qsdev->channel;
unsigned long flags;

qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSING);

/*
* Make sure we don't race with the code receiving data.
*/
spin_lock_irqsave(&channel->recv_lock, flags);
channel->cb = NULL;
spin_unlock_irqrestore(&channel->recv_lock, flags);
qcom_smd_channel_set_callback(channel, NULL);

/* Wake up any sleepers in qcom_smd_send() */
wake_up_interruptible(&channel->fblockread_event);
Expand Down
4 changes: 3 additions & 1 deletion include/linux/soc/qcom/smd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct qcom_smd_device {
struct qcom_smd_channel *channel;
};

typedef int (*qcom_smd_cb_t)(struct qcom_smd_device *, const void *, size_t);

/**
* struct qcom_smd_driver - smd driver struct
* @driver: underlying device driver
Expand All @@ -42,7 +44,7 @@ struct qcom_smd_driver {

int (*probe)(struct qcom_smd_device *dev);
void (*remove)(struct qcom_smd_device *dev);
int (*callback)(struct qcom_smd_device *, const void *, size_t);
qcom_smd_cb_t callback;
};

int qcom_smd_driver_register(struct qcom_smd_driver *drv);
Expand Down

0 comments on commit 39f0db2

Please sign in to comment.