aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2018-10-12 12:04:45 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-10-15 14:32:26 -0400
commit655603de68469adaff16842ac17a5aec9c9ce89b (patch)
treeb9abba9a202fdabb718d96ecd397e0b40f483723
parent4a2b2662e9d21648502e5be10dcd312b8fe85bca (diff)
gsmi: Fix bug in append_to_eventlog sysfs handler
The sysfs handler should return the number of bytes consumed, which in the case of a successful write is the entire buffer. Also fix a bug where param.data_len was being set to (count - (2 * sizeof(u32))) instead of just (count - sizeof(u32)). The latter is correct because we skip over the leading u32 which is our param.type, but we were also incorrectly subtracting sizeof(u32) on the line where we were actually setting param.data_len: param.data_len = count - sizeof(u32); This meant that for our example event.kernel_software_watchdog with total length 10 bytes, param.data_len was just 2 prior to this change. To test, successfully append an event to the log with gsmi sysfs. This sample event is for a "Kernel Software Watchdog" > xxd -g 1 event.kernel_software_watchdog 0000000: 01 00 00 00 ad de 06 00 00 00 > cat event.kernel_software_watchdog > /sys/firmware/gsmi/append_to_eventlog > mosys eventlog list | tail -1 14 | 2012-06-25 10:14:14 | Kernl Event | Software Watchdog Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@chromium.org> Signed-off-by: Furquan Shaikh <furquan@google.com> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Justin TerAvest <teravest@chromium.org> [zwisler: updated changelog for 2nd bug fix and upstream] Signed-off-by: Ross Zwisler <zwisler@google.com> Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/firmware/google/gsmi.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
index 734146eec1b9..3677d511f4c4 100644
--- a/drivers/firmware/google/gsmi.c
+++ b/drivers/firmware/google/gsmi.c
@@ -480,11 +480,10 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
480 if (count < sizeof(u32)) 480 if (count < sizeof(u32))
481 return -EINVAL; 481 return -EINVAL;
482 param.type = *(u32 *)buf; 482 param.type = *(u32 *)buf;
483 count -= sizeof(u32);
484 buf += sizeof(u32); 483 buf += sizeof(u32);
485 484
486 /* The remaining buffer is the data payload */ 485 /* The remaining buffer is the data payload */
487 if (count > gsmi_dev.data_buf->length) 486 if ((count - sizeof(u32)) > gsmi_dev.data_buf->length)
488 return -EINVAL; 487 return -EINVAL;
489 param.data_len = count - sizeof(u32); 488 param.data_len = count - sizeof(u32);
490 489
@@ -504,7 +503,7 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
504 503
505 spin_unlock_irqrestore(&gsmi_dev.lock, flags); 504 spin_unlock_irqrestore(&gsmi_dev.lock, flags);
506 505
507 return rc; 506 return (rc == 0) ? count : rc;
508 507
509} 508}
510 509