From patchwork Fri Dec 10 13:36:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 12669573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13623C433EF for ; Fri, 10 Dec 2021 13:36:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242329AbhLJNkY (ORCPT ); Fri, 10 Dec 2021 08:40:24 -0500 Received: from mail.loongson.cn ([114.242.206.163]:59978 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S242123AbhLJNjw (ORCPT ); Fri, 10 Dec 2021 08:39:52 -0500 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxusjBV7Nh3OEFAA--.12281S4; Fri, 10 Dec 2021 21:36:03 +0800 (CST) From: Tiezhu Yang To: Dave Young , Baoquan He , Vivek Goyal , Andrew Morton Cc: linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kdump: crashdump: use copy_to() to simplify the related code Date: Fri, 10 Dec 2021 21:36:01 +0800 Message-Id: <1639143361-17773-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1639143361-17773-1-git-send-email-yangtiezhu@loongson.cn> References: <1639143361-17773-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf9AxusjBV7Nh3OEFAA--.12281S4 X-Coremail-Antispam: 1U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r4UJbIYCTnIWIevJa73UjIFyTuYvjxU yuWlDUUUU X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Use copy_to() to simplify the related code about copy_oldmem_page() in arch/*/kernel/crash_dump*.c files. Signed-off-by: Tiezhu Yang --- arch/arm/kernel/crash_dump.c | 10 ++-------- arch/arm64/kernel/crash_dump.c | 10 ++-------- arch/ia64/kernel/crash_dump.c | 10 ++++------ arch/mips/kernel/crash_dump.c | 9 ++------- arch/powerpc/kernel/crash_dump.c | 7 ++----- arch/riscv/kernel/crash_dump.c | 9 ++------- arch/sh/kernel/crash_dump.c | 9 ++------- arch/x86/kernel/crash_dump_32.c | 9 ++------- arch/x86/kernel/crash_dump_64.c | 9 ++------- 9 files changed, 20 insertions(+), 62 deletions(-) diff --git a/arch/arm/kernel/crash_dump.c b/arch/arm/kernel/crash_dump.c index 53cb924..6491f1d 100644 --- a/arch/arm/kernel/crash_dump.c +++ b/arch/arm/kernel/crash_dump.c @@ -40,14 +40,8 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user(buf, vaddr + offset, csize)) { - iounmap(vaddr); - return -EFAULT; - } - } else { - memcpy(buf, vaddr + offset, csize); - } + if (copy_to(buf, vaddr + offset, csize, userbuf)) + csize = -EFAULT; iounmap(vaddr); return csize; diff --git a/arch/arm64/kernel/crash_dump.c b/arch/arm64/kernel/crash_dump.c index 58303a9..496e6a5 100644 --- a/arch/arm64/kernel/crash_dump.c +++ b/arch/arm64/kernel/crash_dump.c @@ -38,14 +38,8 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user((char __user *)buf, vaddr + offset, csize)) { - memunmap(vaddr); - return -EFAULT; - } - } else { - memcpy(buf, vaddr + offset, csize); - } + if (copy_to(buf, vaddr + offset, csize, userbuf)) + csize = -EFAULT; memunmap(vaddr); diff --git a/arch/ia64/kernel/crash_dump.c b/arch/ia64/kernel/crash_dump.c index 0ed3c3d..20f4c4e 100644 --- a/arch/ia64/kernel/crash_dump.c +++ b/arch/ia64/kernel/crash_dump.c @@ -39,13 +39,11 @@ copy_oldmem_page(unsigned long pfn, char *buf, if (!csize) return 0; + vaddr = __va(pfn<