From patchwork Fri Dec 10 13:36:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 12669565 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 427EEC433F5 for ; Fri, 10 Dec 2021 13:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238841AbhLJNkR (ORCPT ); Fri, 10 Dec 2021 08:40:17 -0500 Received: from mail.loongson.cn ([114.242.206.163]:59972 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S242038AbhLJNjv (ORCPT ); Fri, 10 Dec 2021 08:39:51 -0500 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxusjBV7Nh3OEFAA--.12281S3; Fri, 10 Dec 2021 21:36:02 +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 1/2] kdump: vmcore: move copy_to() from vmcore.c to uaccess.h Date: Fri, 10 Dec 2021 21:36:00 +0800 Message-Id: <1639143361-17773-2-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--.12281S3 X-Coremail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YxBIdaVFxhVjvjDU0xZFpf9x07jD fHUUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In arch/*/kernel/crash_dump*.c, there exist similar code about copy_oldmem_page(), move copy_to() from vmcore.c to uaccess.h, and then we can use copy_to() to simplify the related code. Signed-off-by: Tiezhu Yang --- fs/proc/vmcore.c | 14 -------------- include/linux/uaccess.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 509f851..c5976a8 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -238,20 +238,6 @@ copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, return copy_oldmem_page(pfn, buf, csize, offset, userbuf); } -/* - * Copy to either kernel or user space - */ -static int copy_to(void *target, void *src, size_t size, int userbuf) -{ - if (userbuf) { - if (copy_to_user((char __user *) target, src, size)) - return -EFAULT; - } else { - memcpy(target, src, size); - } - return 0; -} - #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP static int vmcoredd_copy_dumps(void *dst, u64 start, size_t size, int userbuf) { diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index ac03940..4a6c3e4 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -201,6 +201,20 @@ copy_to_user(void __user *to, const void *from, unsigned long n) return n; } +/* + * Copy to either kernel or user space + */ +static inline int copy_to(void *target, void *src, size_t size, int userbuf) +{ + if (userbuf) { + if (copy_to_user((char __user *) target, src, size)) + return -EFAULT; + } else { + memcpy(target, src, size); + } + return 0; +} + #ifndef copy_mc_to_kernel /* * Without arch opt-in this generic copy_mc_to_kernel() will not handle