Skip to content

Commit

Permalink
s390/kexec: fix return code handling
Browse files Browse the repository at this point in the history
kexec_file_add_ipl_report ignores that ipl_report_finish may fail and
can return an error pointer instead of a valid pointer.
Fix this and simplify by returning NULL in case of an error and let
the only caller handle this case.

Fixes: 99feaa7 ("s390/kexec_file: Create ipl report and pass to next kernel")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
  • Loading branch information
Heiko Carstens committed Nov 18, 2021
1 parent 3b90954 commit 20c76e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion arch/s390/kernel/ipl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ void *ipl_report_finish(struct ipl_report *report)

buf = vzalloc(report->size);
if (!buf)
return ERR_PTR(-ENOMEM);
goto out;
ptr = buf;

memcpy(ptr, report->ipib, report->ipib->hdr.len);
Expand Down Expand Up @@ -2195,6 +2195,7 @@ void *ipl_report_finish(struct ipl_report *report)
}

BUG_ON(ptr > buf + report->size);
out:
return buf;
}

Expand Down
8 changes: 7 additions & 1 deletion arch/s390/kernel/machine_kexec_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static int kexec_file_add_ipl_report(struct kimage *image,
struct kexec_buf buf;
unsigned long addr;
void *ptr, *end;
int ret;

buf.image = image;

Expand Down Expand Up @@ -199,7 +200,10 @@ static int kexec_file_add_ipl_report(struct kimage *image,
ptr += len;
}

ret = -ENOMEM;
buf.buffer = ipl_report_finish(data->report);
if (!buf.buffer)
goto out;
buf.bufsz = data->report->size;
buf.memsz = buf.bufsz;

Expand All @@ -209,7 +213,9 @@ static int kexec_file_add_ipl_report(struct kimage *image,
data->kernel_buf + offsetof(struct lowcore, ipl_parmblock_ptr);
*lc_ipl_parmblock_ptr = (__u32)buf.mem;

return kexec_add_buffer(&buf);
ret = kexec_add_buffer(&buf);
out:
return ret;
}

void *kexec_file_add_components(struct kimage *image,
Expand Down

0 comments on commit 20c76e2

Please sign in to comment.