mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-24 20:54:10 +08:00
pstore: Allocate records on heap instead of stack
In preparation for handling records off to pstore_mkfile(), allocate the record instead of reusing stack. This still always frees the record, though, since pstore_mkfile() isn't yet keeping it. Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
1dfff7dd67
commit
2a2b0acf76
@ -818,8 +818,7 @@ static void decompress_record(struct pstore_record *record)
|
|||||||
void pstore_get_records(int quiet)
|
void pstore_get_records(int quiet)
|
||||||
{
|
{
|
||||||
struct pstore_info *psi = psinfo;
|
struct pstore_info *psi = psinfo;
|
||||||
struct pstore_record record = { .psi = psi, };
|
int failed = 0;
|
||||||
int failed = 0, rc;
|
|
||||||
|
|
||||||
if (!psi)
|
if (!psi)
|
||||||
return;
|
return;
|
||||||
@ -833,19 +832,34 @@ void pstore_get_records(int quiet)
|
|||||||
* may reallocate record.buf. On success, pstore_mkfile() will keep
|
* may reallocate record.buf. On success, pstore_mkfile() will keep
|
||||||
* the record.buf, so free it only on failure.
|
* the record.buf, so free it only on failure.
|
||||||
*/
|
*/
|
||||||
while ((record.size = psi->read(&record)) > 0) {
|
for (;;) {
|
||||||
decompress_record(&record);
|
struct pstore_record *record;
|
||||||
rc = pstore_mkfile(&record);
|
int rc;
|
||||||
|
|
||||||
|
record = kzalloc(sizeof(*record), GFP_KERNEL);
|
||||||
|
if (!record) {
|
||||||
|
pr_err("out of memory creating record\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
record->psi = psi;
|
||||||
|
|
||||||
|
record->size = psi->read(record);
|
||||||
|
|
||||||
|
/* No more records left in backend? */
|
||||||
|
if (record->size <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
decompress_record(record);
|
||||||
|
rc = pstore_mkfile(record);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
/* pstore_mkfile() did not take buf, so free it. */
|
/* pstore_mkfile() did not take buf, so free it. */
|
||||||
kfree(record.buf);
|
kfree(record->buf);
|
||||||
if (rc != -EEXIST || !quiet)
|
if (rc != -EEXIST || !quiet)
|
||||||
failed++;
|
failed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset for next record. */
|
/* Reset for next record. */
|
||||||
memset(&record, 0, sizeof(record));
|
kfree(record);
|
||||||
record.psi = psi;
|
|
||||||
}
|
}
|
||||||
if (psi->close)
|
if (psi->close)
|
||||||
psi->close(psi);
|
psi->close(psi);
|
||||||
|
Loading…
Reference in New Issue
Block a user