summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>2016-02-15 12:12:01 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-02-20 17:09:14 -0500
commitf8560a9bc76b2cd5c06fa412cb7b5481d70fcf34 (patch)
tree346c88ac941281b11cb465268ddb1dd12eea9685
parent14136e368f909ced74f97cf04199d7288933ad41 (diff)
stm class: Use driver's packet callback return value
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>
-rw-r--r--drivers/hwtracing/stm/core.c19
-rw-r--r--include/linux/stm.h7
2 files changed, 19 insertions, 7 deletions
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 79cca94bfb58..0db303b50e51 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -380,8 +380,8 @@ static int stm_file_assign(struct stm_file *stmf, char *id, unsigned int width)
380 return ret; 380 return ret;
381} 381}
382 382
383static void stm_write(struct stm_data *data, unsigned int master, 383static ssize_t stm_write(struct stm_data *data, unsigned int master,
384 unsigned int channel, const char *buf, size_t count) 384 unsigned int channel, const char *buf, size_t count)
385{ 385{
386 unsigned int flags = STP_PACKET_TIMESTAMPED; 386 unsigned int flags = STP_PACKET_TIMESTAMPED;
387 const unsigned char *p = buf, nil = 0; 387 const unsigned char *p = buf, nil = 0;
@@ -393,9 +393,14 @@ static void stm_write(struct stm_data *data, unsigned int master,
393 sz = data->packet(data, master, channel, STP_PACKET_DATA, flags, 393 sz = data->packet(data, master, channel, STP_PACKET_DATA, flags,
394 sz, p); 394 sz, p);
395 flags = 0; 395 flags = 0;
396
397 if (sz < 0)
398 break;
396 } 399 }
397 400
398 data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, &nil); 401 data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, &nil);
402
403 return pos;
399} 404}
400 405
401static ssize_t stm_char_write(struct file *file, const char __user *buf, 406static 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,
433 return -EFAULT; 438 return -EFAULT;
434 } 439 }
435 440
436 stm_write(stm->data, stmf->output.master, stmf->output.channel, kbuf, 441 count = stm_write(stm->data, stmf->output.master, stmf->output.channel,
437 count); 442 kbuf, count);
438 443
439 kfree(kbuf); 444 kfree(kbuf);
440 445
@@ -996,9 +1001,9 @@ int stm_source_write(struct stm_source_data *data, unsigned int chan,
996 1001
997 stm = srcu_dereference(src->link, &stm_source_srcu); 1002 stm = srcu_dereference(src->link, &stm_source_srcu);
998 if (stm) 1003 if (stm)
999 stm_write(stm->data, src->output.master, 1004 count = stm_write(stm->data, src->output.master,
1000 src->output.channel + chan, 1005 src->output.channel + chan,
1001 buf, count); 1006 buf, count);
1002 else 1007 else
1003 count = -ENODEV; 1008 count = -ENODEV;
1004 1009
diff --git a/include/linux/stm.h b/include/linux/stm.h
index 9d0083d364e6..ab8ceca4f570 100644
--- a/include/linux/stm.h
+++ b/include/linux/stm.h
@@ -67,6 +67,13 @@ struct stm_device;
67 * description. That is, the lowest master that can be allocated to software 67 * description. That is, the lowest master that can be allocated to software
68 * writers is @sw_start and data from this writer will appear is @sw_start 68 * writers is @sw_start and data from this writer will appear is @sw_start
69 * master in the STP stream. 69 * master in the STP stream.
70 *
71 * The @packet callback should adhere to the following rules:
72 * 1) it must return the number of bytes it consumed from the payload;
73 * 2) therefore, if it sent a packet that does not have payload (like FLAG),
74 * it must return zero;
75 * 3) if it does not support the requested packet type/flag combination,
76 * it must return -ENOTSUPP.
70 */ 77 */
71struct stm_data { 78struct stm_data {
72 const char *name; 79 const char *name;