From patchwork Wed Nov 27 14:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13887087 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 99E9AD6ACDD for ; Wed, 27 Nov 2024 14:25:41 +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=cDtIhM3fa4dq8Wr3efNQJsRJXk+GIbqSlCZA2d1UsqU=; b=ZdYXEU7azt74Q4 MqPO9PJaAA/bcJ+N9IdfvcM4GPlRMdjuwtZRcrJNDF+P6XOcn/4mfn18ZEYK/AAeixmuLNz+FyG21 pj/V/buU+OX/wd7N/6JNfM83PlZJWzwUxZmUMfNRVYQ+KiU+NN7UBlZYF/p8YP8kU1HQDYQsUpYlO YAY7/RiYaCfQ1j3Qkdp9xGxOHGd2qEOXx9S7aBpSBZ9Wi5f2eZoDQaTVeLZ56ToCB15imTuadAo/c NW2SIJxWI1PnkXBLUZkwBCESj6Dvp0o+kcny6i66RBNeOmFcnwNMnAKRALeIBICFEj4fcMxKT/qtN ygCuQPult10RLZ4ybaoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGIz1-0000000DMg7-21h2; Wed, 27 Nov 2024 14:25:35 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGIyz-0000000DMfh-0Oll for linux-riscv@lists.infradead.org; Wed, 27 Nov 2024 14:25:34 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-53de5ec22adso4046490e87.3 for ; Wed, 27 Nov 2024 06:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732717531; x=1733322331; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=M9vG//8ehMp4lOpZgUGc6H5kOfF24HtjuZe7yPe7sl4=; b=uuiJXkRQRPbL6kS04DNgpgVJT8D6BUbyz09/ZWIUaFCaQmum4yZDOa8sTckvVbqMHd PdCtcETqBJl9FclDaiiwoZvp1MecTyyMWdLxvDjMMa1C1ss8JV/IJCTxJajV0RVCkY6M lwUXxVctE+p+gPwHvIuaYPAm0RMxtIUxnn4hmeh6ceLjgEOst1BP6sIgu8dTzAXzjH5K T0SJ8RimZa0nUIGejuFGc/PNJS9Tbr70jfZxpLGdm9+V8DYa0+7XsnfJCIKEpz3Iiibg KvnBrw435rdi/m1CyWFTPT880+NZ3H/+M18aZrUVACbik1kNLQ3GZug2ANG5cLvGlhP0 KGfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732717531; x=1733322331; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M9vG//8ehMp4lOpZgUGc6H5kOfF24HtjuZe7yPe7sl4=; b=UkkfeLyBkIauYVQ26ArwFufrvLmwYOQlg3JtpVoTenH7ie1qBbLd3DXmc5HdDEn4SK 7ClePfKzaZTa405vUeg3y2+QsjHVhh6Ehvy6zO+Qc/gJHlE5KMDis3NeIgkGxP6qtMbs dfABJopA8dOd08BVOedzBHnhiABYVPKO3VB/pdqTlph8zwvtoZOSZHFKUJtspVCIBYgO FqBAJiH96iTM3gQ1XhRYd52GOml6A6A5FwcYwsIjaeui5YMFP9Ev9IA7Yb1KCJNIGLaU lN1vRoVQ5TvAcv+TpJfk0qXAsJuS0Miee/vh9880xKAMaf8I8VQP7lc7o3CPVqExXbtQ p+hg== X-Forwarded-Encrypted: i=1; AJvYcCVtYMjCPTVRDeeeVHutVT1nQ51VsD/G1TpCFbJ/Wb68xpDbZDtnr+Wc1DPxZINNRbYk63ahrAYrGVmnyw==@lists.infradead.org X-Gm-Message-State: AOJu0Yw3DJSGzj2t9zL9W1ic1S0JCGEM23ETj4DpBL/+u6yeAz1KToQo 0TZb5jgbc6EFuEE3/VeqNv5v4CULpMAsZGMaicDbmMXDEP6lt2NYO4zVhjTlkSc= X-Gm-Gg: ASbGncuep91eJC/MAx33j1j9S+mRp5vfmtupRfjpcFGxZLyB3u1wfYCZsVy9nkq7CEM 6MtmlMobjJWALxDhPXD3hheCkz52l3m1Yru07ZQ5gCFZAPCW7FnrJWvWGI+m71tnc51SGbKA6GF 0RAia9u+lzSwVLPY5rQmjaPyPh7xTg4IGqAcvoSPVfKfKHhwDzH65NqF/EDkxC7t4KeLJut2oIV cYaPhs2h9kC0CyfJRbO+9jVMc5Abg7FABU9XWGZ1urws2utP60= X-Google-Smtp-Source: AGHT+IEq0o9PJ9NLeVH70cbpvzcAJwyOpE7QpuGsdHSdB/UiJnox4e1NTf1b0VEcLfTBl4+Lz2uo5w== X-Received: by 2002:a05:6512:2244:b0:53d:ed66:e070 with SMTP id 2adb3069b0e04-53df010ea48mr1692848e87.47.1732717530883; Wed, 27 Nov 2024 06:25:30 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fb53858sm16389913f8f.62.2024.11.27.06.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 06:25:30 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Charlie Jenkins , Kai Zhang , Andrew Jones Subject: [PATCH v2] riscv: module: use a plain variable for list_head instead of a pointer Date: Wed, 27 Nov 2024 15:25:17 +0100 Message-ID: <20241127142519.3038691-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_062533_140682_1B26A20B X-CRM114-Status: GOOD ( 13.07 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org rel_head's list_head member, rel_entry, doesn't need to be allocated, its storage can just be part of the allocated rel_head. Remove the pointer which allows to get rid of the allocation as well as an existing memory leak found by Kai Zang using kmemleak. Reported-by: Kai Zhang Signed-off-by: Clément Léger Reviewed-by: Andrew Jones Reviewed-by: Charlie Jenkins Tested-by: Charlie Jenkins --- V2: - Add Kai Reported-by - Reword the commit description (Andrew) --- arch/riscv/kernel/module.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 1cd461f3d872..47d0ebeec93c 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -23,7 +23,7 @@ struct used_bucket { struct relocation_head { struct hlist_node node; - struct list_head *rel_entry; + struct list_head rel_entry; void *location; }; @@ -634,7 +634,7 @@ process_accumulated_relocations(struct module *me, location = rel_head_iter->location; list_for_each_entry_safe(rel_entry_iter, rel_entry_iter_tmp, - rel_head_iter->rel_entry, + &rel_head_iter->rel_entry, head) { curr_type = rel_entry_iter->type; reloc_handlers[curr_type].reloc_handler( @@ -704,16 +704,7 @@ static int add_relocation_to_accumulate(struct module *me, int type, return -ENOMEM; } - rel_head->rel_entry = - kmalloc(sizeof(struct list_head), GFP_KERNEL); - - if (!rel_head->rel_entry) { - kfree(entry); - kfree(rel_head); - return -ENOMEM; - } - - INIT_LIST_HEAD(rel_head->rel_entry); + INIT_LIST_HEAD(&rel_head->rel_entry); rel_head->location = location; INIT_HLIST_NODE(&rel_head->node); if (!current_head->first) { @@ -722,7 +713,6 @@ static int add_relocation_to_accumulate(struct module *me, int type, if (!bucket) { kfree(entry); - kfree(rel_head->rel_entry); kfree(rel_head); return -ENOMEM; } @@ -735,7 +725,7 @@ static int add_relocation_to_accumulate(struct module *me, int type, } /* Add relocation to head of discovered rel_head */ - list_add_tail(&entry->head, rel_head->rel_entry); + list_add_tail(&entry->head, &rel_head->rel_entry); return 0; }