Skip to content

Commit b05c950

Browse files
joelagnelkees
authored andcommitted
pstore/ram: Simplify ramoops_get_next_prz() arguments
(1) remove type argument from ramoops_get_next_prz() Since we store the type of the prz when we initialize it, we no longer need to pass it again in ramoops_get_next_prz() since we can just use that to setup the pstore record. So lets remove it from the argument list. (2) remove max argument from ramoops_get_next_prz() Looking at the code flow, the 'max' checks are already being done on the prz passed to ramoops_get_next_prz(). Lets remove it to simplify this function and reduce its arguments. (3) further reduce ramoops_get_next_prz() arguments by passing record Both the id and type fields of a pstore_record are set by ramoops_get_next_prz(). So we can just pass a pointer to the pstore_record instead of passing individual elements. This results in cleaner more readable code and fewer lines. In addition lets also remove the 'update' argument since we can detect that. Changes are squashed into a single patch to reduce fixup conflicts. Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org> Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent f0f23e5 commit b05c950

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

fs/pstore/ram.c

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,17 @@ static int ramoops_pstore_open(struct pstore_info *psi)
124124
}
125125

126126
static struct persistent_ram_zone *
127-
ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
128-
u64 *id,
129-
enum pstore_type_id *typep, enum pstore_type_id type,
130-
bool update)
127+
ramoops_get_next_prz(struct persistent_ram_zone *przs[], int id,
128+
struct pstore_record *record)
131129
{
132130
struct persistent_ram_zone *prz;
133-
int i = (*c)++;
131+
bool update = (record->type == PSTORE_TYPE_DMESG);
134132

135133
/* Give up if we never existed or have hit the end. */
136-
if (!przs || i >= max)
134+
if (!przs)
137135
return NULL;
138136

139-
prz = przs[i];
137+
prz = przs[id];
140138
if (!prz)
141139
return NULL;
142140

@@ -147,8 +145,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
147145
if (!persistent_ram_old_size(prz))
148146
return NULL;
149147

150-
*typep = type;
151-
*id = i;
148+
record->type = prz->type;
149+
record->id = id;
152150

153151
return prz;
154152
}
@@ -255,10 +253,8 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
255253

256254
/* Find the next valid persistent_ram_zone for DMESG */
257255
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
258-
prz = ramoops_get_next_prz(cxt->dprzs, &cxt->dump_read_cnt,
259-
cxt->max_dump_cnt, &record->id,
260-
&record->type,
261-
PSTORE_TYPE_DMESG, 1);
256+
prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
257+
record);
262258
if (!prz_ok(prz))
263259
continue;
264260
header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
@@ -272,22 +268,18 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
272268
}
273269
}
274270

275-
if (!prz_ok(prz))
276-
prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
277-
1, &record->id, &record->type,
278-
PSTORE_TYPE_CONSOLE, 0);
271+
if (!prz_ok(prz) && !cxt->console_read_cnt++)
272+
prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record);
279273

280-
if (!prz_ok(prz))
281-
prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,
282-
1, &record->id, &record->type,
283-
PSTORE_TYPE_PMSG, 0);
274+
if (!prz_ok(prz) && !cxt->pmsg_read_cnt++)
275+
prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record);
284276

285277
/* ftrace is last since it may want to dynamically allocate memory. */
286278
if (!prz_ok(prz)) {
287-
if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) {
288-
prz = ramoops_get_next_prz(cxt->fprzs,
289-
&cxt->ftrace_read_cnt, 1, &record->id,
290-
&record->type, PSTORE_TYPE_FTRACE, 0);
279+
if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) &&
280+
!cxt->ftrace_read_cnt++) {
281+
prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */,
282+
record);
291283
} else {
292284
/*
293285
* Build a new dummy record which combines all the
@@ -303,11 +295,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
303295

304296
while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) {
305297
prz_next = ramoops_get_next_prz(cxt->fprzs,
306-
&cxt->ftrace_read_cnt,
307-
cxt->max_ftrace_cnt,
308-
&record->id,
309-
&record->type,
310-
PSTORE_TYPE_FTRACE, 0);
298+
cxt->ftrace_read_cnt++, record);
311299

312300
if (!prz_ok(prz_next))
313301
continue;

0 commit comments

Comments
 (0)