From patchwork Tue May 30 18:03:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13260860 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 556B0C77B73 for ; Tue, 30 May 2023 18:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=oCizr5NfJN8o7zQQF9F7gC3ZVW/BZTZuLwTyZXflxk8=; b=0ybPfYe1aWApi3 8tsBi+1i8Ro767fDO6TcU4AIq0yYR74ADq/m+Df842HMFhLXuMCKRVHqZNG5wikGU8SD7Sl2GcwKJ 5QQ3UZGcs4IZ1Wii+SnDNrb/o6gTR9IBmHyJOcTp1h8VWo1HEEvr8Ekhd3vcdRPtXbOHj3vlJqdKK BvabaCINdqC0ufMlc70rJ3TDfxEdFOrgzerBcOw+JecuVB5oAx4U96iMkXgzlHt756rrXWb0fVB1h MAfVStJ8DrVdTGbaiIu7mk0AeTukpylLDlK5YRgz848jtFJjimByNVwE98y7jdhBa3+cAz8PJHDJF 00RkMPuYxwSXdLnSZ6CA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q43gs-00EpkG-3B; Tue, 30 May 2023 18:03:26 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q43gq-00EpjH-0Z for linux-arm-kernel@lists.infradead.org; Tue, 30 May 2023 18:03:25 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A756762B27; Tue, 30 May 2023 18:03:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBB31C4339B; Tue, 30 May 2023 18:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685469803; bh=rRFiekp/e4p9IosGOeiClcA0ZQRFHAsurfVAIwKYtNA=; h=From:To:Cc:Subject:Date:From; b=kfKhO+115F+K6AN+J8c3KwpDdC0A/fljxKFJOwFNZTrsM0wqJ47qSC4SmyDG/ywQa rpWpiB6ciiDy+op+OmmhgwSRoI3V7MI0SkNvepDwfBp02IZq1cX02k1ZXMOVDTtsg4 abXf+RQ9Hl4Enio2jc8gYZ85+o1svPLjfQ3Exim4U7LMa+rj/fl61MfnwhFhXhZrGv jHw/nlB7deHg/gajRIxZidsczL0WIRfX0lnwPgKL8RR2ZIZTpEeVnxr+/1GRq2lNza oASt27IP2SarlOpnEDJt5txd4KdxEMyg0xE8jYiyCHqhpElaemCQkpW/B5ESBXJGSr A+haUxRPOhcfw== From: Masahiro Yamada To: patches@armlinux.org.uk Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Masahiro Yamada , Russell King Subject: [PATCH] ARM: module: use sign_extend32() to extend the signedness Date: Wed, 31 May 2023 03:03:08 +0900 Message-Id: <20230530180308.112297-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230530_110324_256144_E768A579 X-CRM114-Status: GOOD ( 11.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The function name clarifies the intention. Signed-off-by: Masahiro Yamada --- KernelVersion: v6.4-rc1 arch/arm/kernel/module.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index d59c36dc0494..e74d84f58b77 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -169,8 +169,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, offset = __mem_to_opcode_arm(*(u32 *)loc); offset = (offset & 0x00ffffff) << 2; - if (offset & 0x02000000) - offset -= 0x04000000; + offset = sign_extend32(offset, 25); offset += sym->st_value - loc; @@ -236,7 +235,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, case R_ARM_MOVT_PREL: offset = tmp = __mem_to_opcode_arm(*(u32 *)loc); offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); - offset = (offset ^ 0x8000) - 0x8000; + offset = sign_extend32(offset, 15); offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_PREL || @@ -344,8 +343,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ((~(j2 ^ sign) & 1) << 22) | ((upper & 0x03ff) << 12) | ((lower & 0x07ff) << 1); - if (offset & 0x01000000) - offset -= 0x02000000; + offset = sign_extend32(offset, 24); offset += sym->st_value - loc; /* @@ -401,7 +399,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, offset = ((upper & 0x000f) << 12) | ((upper & 0x0400) << 1) | ((lower & 0x7000) >> 4) | (lower & 0x00ff); - offset = (offset ^ 0x8000) - 0x8000; + offset = sign_extend32(offset, 15); offset += sym->st_value; if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_PREL ||