From patchwork Fri Oct 14 01:59:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 2461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp573397wrs; Thu, 13 Oct 2022 19:05:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7l4wslkLQJOgv7oh/JCU2UzX3WGEBMybYgLnrVvY+eY0MVXcu/5gRvnUPez8uDtZEeWY6D X-Received: by 2002:a17:907:9627:b0:78d:a7d8:9407 with SMTP id gb39-20020a170907962700b0078da7d89407mr1773524ejc.675.1665713101794; Thu, 13 Oct 2022 19:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665713101; cv=none; d=google.com; s=arc-20160816; b=xELK/3kydfNnlaGHFfRCHt4rehkhtRnXA7vClzhGL/alvtQB7t5yYcqZCE3A9nxk7t OF3z0jYpI4AvMdyVYm60HTYRo8PQUdMEVwjxYKBu3XK8l77jcMvq2LnrrR66DNaBgrl2 dgYvtd9+YzmlVIligs/vW67s0HIswhLx4XzZXmnekYTJO8pYB1VadGJgkY3A47xBRxt3 g40oc5jlbagqBznTQXaZpD8nP2R3fQY/b+H4n1vmKInDXzXFHszNBjCI+/EWIZBv3NuE /VqeCxRcqeIcVgx2cT0NTWS7toXgvDTIBQFN7JTZho4eQw4myPUyuJrKr3sfTUppyY85 D2mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2WUUvaxfWFdKFuavy84D58WJMWa+7KZ1pEld0CUJVB4=; b=dQNrBcTH0ayzUlqpOKus8ysunzkECp9QWImHYRDjjWLwBQ7+EswAQNHR0Zd0Tt1TE3 f7CrKHHcMMC3y/5Yz3bWui1PLVRM5y6pu2M7Ul1Tji8DkuYDAzLYDsEGRQ/feTJf09ry cCFfKnHTBj0rbVU9+ne4OAcK1gJm6qepy+k1yz77ekcc+5Y2urY5FvEPVMPYULF77Gj/ V0T8n0SZn9JkJ+te3a47okL7jleBYDK1SJzC0f9WrZCxrmzb+QQ8goIebewl4qDZm/Kx ViUsuPEcsIIp7LOqhLEn0gwg65epy/D1EqkBIgT44PBlWEBFyjp2hoiUKaVFtggCxhDG XEyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq29-20020a1709073f1d00b0073866c0672asi1356617ejc.73.2022.10.13.19.04.35; Thu, 13 Oct 2022 19:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbiJNCAz (ORCPT + 99 others); Thu, 13 Oct 2022 22:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbiJNCAr (ORCPT ); Thu, 13 Oct 2022 22:00:47 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196B87CE37 for ; Thu, 13 Oct 2022 19:00:45 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MpTzb3Q87zpVwV; Fri, 14 Oct 2022 09:57:31 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 14 Oct 2022 10:00:44 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 14 Oct 2022 10:00:43 +0800 From: Zhen Lei To: Russell King , Ard Biesheuvel , , CC: Zhen Lei Subject: [PATCH v3 2/3] ARM: Refactor dump_instr() Date: Fri, 14 Oct 2022 09:59:55 +0800 Message-ID: <20221014015956.2006-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20221014015956.2006-1-thunder.leizhen@huawei.com> References: <20221014015956.2006-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746626781405445246?= X-GMAIL-MSGID: =?utf-8?q?1746626781405445246?= 1. Rename local variable 'val16' to 'tmp'. So that the processing statements of thumb and arm can be aligned. 2. Prepare for the next patch to avoid repeated judgment. Before: if (!user_mode(regs)) { if (thumb) else } else { if (thumb) else } After: if (thumb) { if (user_mode(regs)) else } else { if (user_mode(regs)) else } Signed-off-by: Zhen Lei --- arch/arm/kernel/traps.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index d455c97237e2079..182469a5b28a394 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -178,19 +178,20 @@ static void dump_instr(const char *lvl, struct pt_regs *regs) for (i = -4; i < 1 + !!thumb; i++) { unsigned int val, bad; - if (!user_mode(regs)) { - if (thumb) { - u16 val16; - bad = get_kernel_nofault(val16, &((u16 *)addr)[i]); - val = val16; - } else { - bad = get_kernel_nofault(val, &((u32 *)addr)[i]); - } - } else { - if (thumb) - bad = get_user(val, &((u16 __user *)addr)[i]); + if (thumb) { + u16 tmp; + + if (user_mode(regs)) + bad = get_user(tmp, &((u16 __user *)addr)[i]); else + bad = get_kernel_nofault(tmp, &((u16 *)addr)[i]); + + val = tmp; + } else { + if (user_mode(regs)) bad = get_user(val, &((u32 __user *)addr)[i]); + else + bad = get_kernel_nofault(val, &((u32 *)addr)[i]); } if (!bad)