Skip to content

Commit df9bf19

Browse files
committed
pstore/ram: Refactor ftrace buffer merging
This changes the ftrace record merging code to be agnostic of pstore/ram, as the first step to making it available as a generic routine for other backends to use, such as pstore/zone. Link: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Kees Cook <[email protected]>
1 parent 26961d7 commit df9bf19

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

fs/pstore/ram.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,29 @@ static bool prz_ok(struct persistent_ram_zone *prz)
168168
persistent_ram_ecc_string(prz, NULL, 0));
169169
}
170170

171-
static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest,
172-
struct persistent_ram_zone *src)
171+
static
172+
ssize_t ftrace_log_combine(char **dest_log, size_t *dest_log_size,
173+
const char *src_log, size_t src_log_size)
173174
{
174175
size_t dest_size, src_size, total, dest_off, src_off;
175176
size_t dest_idx = 0, src_idx = 0, merged_idx = 0;
176177
void *merged_buf;
177178
struct pstore_ftrace_record *drec, *srec, *mrec;
178179
size_t record_size = sizeof(struct pstore_ftrace_record);
179180

180-
dest_off = dest->old_log_size % record_size;
181-
dest_size = dest->old_log_size - dest_off;
181+
dest_off = *dest_log_size % record_size;
182+
dest_size = *dest_log_size - dest_off;
182183

183-
src_off = src->old_log_size % record_size;
184-
src_size = src->old_log_size - src_off;
184+
src_off = src_log_size % record_size;
185+
src_size = src_log_size - src_off;
185186

186187
total = dest_size + src_size;
187188
merged_buf = kmalloc(total, GFP_KERNEL);
188189
if (!merged_buf)
189190
return -ENOMEM;
190191

191-
drec = (struct pstore_ftrace_record *)(dest->old_log + dest_off);
192-
srec = (struct pstore_ftrace_record *)(src->old_log + src_off);
192+
drec = (struct pstore_ftrace_record *)(*dest_log + dest_off);
193+
srec = (struct pstore_ftrace_record *)(src_log + src_off);
193194
mrec = (struct pstore_ftrace_record *)(merged_buf);
194195

195196
while (dest_size > 0 && src_size > 0) {
@@ -213,9 +214,9 @@ static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest,
213214
src_size -= record_size;
214215
}
215216

216-
kfree(dest->old_log);
217-
dest->old_log = merged_buf;
218-
dest->old_log_size = total;
217+
kfree(*dest_log);
218+
*dest_log = merged_buf;
219+
*dest_log_size = total;
219220

220221
return 0;
221222
}
@@ -291,7 +292,11 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
291292
tmp_prz->corrected_bytes +=
292293
prz_next->corrected_bytes;
293294
tmp_prz->bad_blocks += prz_next->bad_blocks;
294-
size = ftrace_log_combine(tmp_prz, prz_next);
295+
296+
size = ftrace_log_combine(&tmp_prz->old_log,
297+
&tmp_prz->old_log_size,
298+
prz_next->old_log,
299+
prz_next->old_log_size);
295300
if (size)
296301
goto out;
297302
}

0 commit comments

Comments
 (0)