Commit e581ca81 authored by Kees Cook's avatar Kees Cook

pstore: Create common record initializer

In preparation for setting timestamps in the pstore core, create a common
initializer routine, instead of using static initializers.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent efb74e4b
...@@ -30,5 +30,7 @@ extern void pstore_get_backend_records(struct pstore_info *psi, ...@@ -30,5 +30,7 @@ extern void pstore_get_backend_records(struct pstore_info *psi,
extern int pstore_mkfile(struct dentry *root, extern int pstore_mkfile(struct dentry *root,
struct pstore_record *record); struct pstore_record *record);
extern bool pstore_is_mounted(void); extern bool pstore_is_mounted(void);
extern void pstore_record_init(struct pstore_record *record,
struct pstore_info *psi);
#endif #endif
...@@ -474,6 +474,14 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len) ...@@ -474,6 +474,14 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len)
return total_len; return total_len;
} }
void pstore_record_init(struct pstore_record *record,
struct pstore_info *psinfo)
{
memset(record, 0, sizeof(*record));
record->psi = psinfo;
}
/* /*
* callback from kmsg_dump. (s2,l2) has the most recently * callback from kmsg_dump. (s2,l2) has the most recently
* written bytes, older bytes are in (s1,l1). Save as much * written bytes, older bytes are in (s1,l1). Save as much
...@@ -509,15 +517,14 @@ static void pstore_dump(struct kmsg_dumper *dumper, ...@@ -509,15 +517,14 @@ static void pstore_dump(struct kmsg_dumper *dumper,
int header_size; int header_size;
int zipped_len = -1; int zipped_len = -1;
size_t dump_size; size_t dump_size;
struct pstore_record record = { struct pstore_record record;
.type = PSTORE_TYPE_DMESG,
.count = oopscount, pstore_record_init(&record, psinfo);
.reason = reason, record.type = PSTORE_TYPE_DMESG;
.part = part, record.count = oopscount;
.compressed = false, record.reason = reason;
.buf = psinfo->buf, record.part = part;
.psi = psinfo, record.buf = psinfo->buf;
};
if (big_oops_buf && is_locked) { if (big_oops_buf && is_locked) {
dst = big_oops_buf; dst = big_oops_buf;
...@@ -587,12 +594,12 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c) ...@@ -587,12 +594,12 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
const char *e = s + c; const char *e = s + c;
while (s < e) { while (s < e) {
struct pstore_record record = { struct pstore_record record;
.type = PSTORE_TYPE_CONSOLE,
.psi = psinfo,
};
unsigned long flags; unsigned long flags;
pstore_record_init(&record, psinfo);
record.type = PSTORE_TYPE_CONSOLE;
if (c > psinfo->bufsize) if (c > psinfo->bufsize)
c = psinfo->bufsize; c = psinfo->bufsize;
...@@ -845,7 +852,7 @@ void pstore_get_backend_records(struct pstore_info *psi, ...@@ -845,7 +852,7 @@ void pstore_get_backend_records(struct pstore_info *psi,
pr_err("out of memory creating record\n"); pr_err("out of memory creating record\n");
break; break;
} }
record->psi = psi; pstore_record_init(record, psi);
record->size = psi->read(record); record->size = psi->read(record);
......
...@@ -22,16 +22,16 @@ static DEFINE_MUTEX(pmsg_lock); ...@@ -22,16 +22,16 @@ static DEFINE_MUTEX(pmsg_lock);
static ssize_t write_pmsg(struct file *file, const char __user *buf, static ssize_t write_pmsg(struct file *file, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
struct pstore_record record = { struct pstore_record record;
.type = PSTORE_TYPE_PMSG,
.size = count,
.psi = psinfo,
};
int ret; int ret;
if (!count) if (!count)
return 0; return 0;
pstore_record_init(&record, psinfo);
record.type = PSTORE_TYPE_PMSG;
record.size = count;
/* check outside lock, page in any data. write_user also checks */ /* check outside lock, page in any data. write_user also checks */
if (!access_ok(VERIFY_READ, buf, count)) if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT; return -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment