stm class: Use driver's packet callback return value
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>
Mon, 15 Feb 2016 17:12:01 +0000 (19:12 +0200)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Wed, 1 Jun 2016 21:28:43 +0000 (15:28 -0600)
STM drivers provide a callback to generate/send individual STP packets;
it also tells the stm core how many bytes of payload it has consumed.
However, we would also need to use the negative space of this return
value to communicate errors that occur during the packet generation,
in which case the stm core will have to take appropriate action.

For now, we need to account for the possibility that the stm driver may
not support certain combinations of packet type/flags, in which case
it is expected to signal an error.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit f8560a9bc76b2cd5c06fa412cb7b5481d70fcf34)

drivers/hwtracing/stm/core.c
include/linux/stm.h

index 76697ad59f2d32baffa3f31ae8709c07509a7fa4..1f2b7b47692d76834f3eebcd45f8e345484a0881 100644 (file)
@@ -380,8 +380,8 @@ static int stm_file_assign(struct stm_file *stmf, char *id, unsigned int width)
        return ret;
 }
 
-static void stm_write(struct stm_data *data, unsigned int master,
-                     unsigned int channel, const char *buf, size_t count)
+static ssize_t stm_write(struct stm_data *data, unsigned int master,
+                         unsigned int channel, const char *buf, size_t count)
 {
        unsigned int flags = STP_PACKET_TIMESTAMPED;
        const unsigned char *p = buf, nil = 0;
@@ -393,9 +393,14 @@ static void stm_write(struct stm_data *data, unsigned int master,
                sz = data->packet(data, master, channel, STP_PACKET_DATA, flags,
                                  sz, p);
                flags = 0;
+
+               if (sz < 0)
+                       break;
        }
 
        data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, &nil);
+
+       return pos;
 }
 
 static ssize_t stm_char_write(struct file *file, const char __user *buf,
@@ -433,8 +438,8 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf,
                return -EFAULT;
        }
 
-       stm_write(stm->data, stmf->output.master, stmf->output.channel, kbuf,
-                 count);
+       count = stm_write(stm->data, stmf->output.master, stmf->output.channel,
+                         kbuf, count);
 
        kfree(kbuf);
 
@@ -996,9 +1001,9 @@ int stm_source_write(struct stm_source_data *data, unsigned int chan,
 
        stm = srcu_dereference(src->link, &stm_source_srcu);
        if (stm)
-               stm_write(stm->data, src->output.master,
-                         src->output.channel + chan,
-                         buf, count);
+               count = stm_write(stm->data, src->output.master,
+                                 src->output.channel + chan,
+                                 buf, count);
        else
                count = -ENODEV;
 
index 9d0083d364e642b6ac68ae56cdae3bc197ffebde..ab8ceca4f5705aaeadda9ed8798559c450637d06 100644 (file)
@@ -67,6 +67,13 @@ struct stm_device;
  * description. That is, the lowest master that can be allocated to software
  * writers is @sw_start and data from this writer will appear is @sw_start
  * master in the STP stream.
+ *
+ * The @packet callback should adhere to the following rules:
+ *   1) it must return the number of bytes it consumed from the payload;
+ *   2) therefore, if it sent a packet that does not have payload (like FLAG),
+ *      it must return zero;
+ *   3) if it does not support the requested packet type/flag combination,
+ *      it must return -ENOTSUPP.
  */
 struct stm_data {
        const char              *name;