mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 04:34:11 +08:00
6e3e37a5a7
After having started writing the coredump, if filesystem reports an error anytime while writing part of the core file, we would leak a memory page when bailing out. Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Roland McGrath <roland@redhat.com> Cc: WANG Cong <amwang@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
46 lines
938 B
C
46 lines
938 B
C
#ifndef _LINUX_COREDUMP_H
|
|
#define _LINUX_COREDUMP_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/fs.h>
|
|
|
|
/*
|
|
* These are the only things you should do on a core-file: use only these
|
|
* functions to write out all the necessary info.
|
|
*/
|
|
static inline int dump_write(struct file *file, const void *addr, int nr)
|
|
{
|
|
return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
|
|
}
|
|
|
|
static inline int dump_seek(struct file *file, loff_t off)
|
|
{
|
|
int ret = 1;
|
|
|
|
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
|
|
if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
|
|
return 0;
|
|
} else {
|
|
char *buf = (char *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
return 0;
|
|
while (off > 0) {
|
|
unsigned long n = off;
|
|
|
|
if (n > PAGE_SIZE)
|
|
n = PAGE_SIZE;
|
|
if (!dump_write(file, buf, n)) {
|
|
ret = 0;
|
|
break;
|
|
}
|
|
off -= n;
|
|
}
|
|
free_page((unsigned long)buf);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#endif /* _LINUX_COREDUMP_H */
|