dump_emit() and dump_emit_page() open-code the same flush of the
accumulated cprm->to_skip. Move it into a helper.

No functional change.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 fs/coredump.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index e5463e3b3f4b..6de18bc49925 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1249,13 +1249,21 @@ static int __dump_skip(struct coredump_params *cprm, 
size_t nr)
        return __dump_emit(cprm, zeroes, nr);
 }
 
-int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
+/* Flush the accumulated hole before writing data. */
+static int dump_flush(struct coredump_params *cprm)
 {
        if (cprm->to_skip) {
                if (!__dump_skip(cprm, cprm->to_skip))
                        return 0;
                cprm->to_skip = 0;
        }
+       return 1;
+}
+
+int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
+{
+       if (!dump_flush(cprm))
+               return 0;
        return __dump_emit(cprm, addr, nr);
 }
 EXPORT_SYMBOL(dump_emit);
@@ -1284,11 +1292,8 @@ static int dump_emit_page(struct coredump_params *cprm, 
struct page *page)
        if (!page)
                return 0;
 
-       if (cprm->to_skip) {
-               if (!__dump_skip(cprm, cprm->to_skip))
-                       return 0;
-               cprm->to_skip = 0;
-       }
+       if (!dump_flush(cprm))
+               return 0;
        if (cprm->written + PAGE_SIZE > cprm->limit)
                return 0;
        if (dump_interrupted())

-- 
2.53.0


Reply via email to