pstore: Pass record contents instead of copying

pstore_mkfile() shouldn't have to memcpy the record contents. It can use
the existing copy instead. This adjusts the allocation lifetime management
and renames the contents variable from "data" to "buf" to assist moving to
struct pstore_record in the future.

Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
Kees Cook
2017-03-04 22:46:41 -08:00
parent 7e8cc8dce1
commit 1dfff7dd67
2 changed files with 27 additions and 11 deletions

View File

@@ -828,14 +828,22 @@ void pstore_get_records(int quiet)
if (psi->open && psi->open(psi))
goto out;
/*
* Backend callback read() allocates record.buf. decompress_record()
* may reallocate record.buf. On success, pstore_mkfile() will keep
* the record.buf, so free it only on failure.
*/
while ((record.size = psi->read(&record)) > 0) {
decompress_record(&record);
rc = pstore_mkfile(&record);
if (rc) {
/* pstore_mkfile() did not take buf, so free it. */
kfree(record.buf);
if (rc != -EEXIST || !quiet)
failed++;
}
if (rc && (rc != -EEXIST || !quiet))
failed++;
kfree(record.buf);
/* Reset for next record. */
memset(&record, 0, sizeof(record));
record.psi = psi;
}