]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
soc: qcom: smd: Introduce callback setter
authorBjorn Andersson <bjorn.andersson@sonymobile.com>
Tue, 20 Oct 2015 02:42:56 +0000 (10:42 +0800)
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 11 Jan 2016 09:55:13 +0000 (09:55 +0000)
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>
drivers/soc/qcom/smd.c
include/linux/soc/qcom/smd.h

index 308c476e42ea40379158f5abdca36538628fe1f4..d0a3f80178c182df1fa491a7516fbe56b8cdd3d2 100644 (file)
@@ -316,6 +316,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
  */
@@ -757,8 +770,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);
@@ -774,7 +786,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;
 
@@ -793,16 +805,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);
index 841f66168c686ef94c62721e952f73f7452ed73c..5532e73f45d167c1261b6ac82caa96c84e644f68 100644 (file)
@@ -6,7 +6,9 @@
 
 struct qcom_smd;
 struct qcom_smd_lookup;
+struct qcom_smd_device;
 
+typedef int (*qcom_smd_cb_t)(struct qcom_smd_device *, const void *, size_t);
 
 /*
  * SMD channel states.
@@ -62,7 +64,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;
 
@@ -105,7 +107,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);