From patchwork Thu Nov 28 08:16:34 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: 13887762 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 7A140D690E9 for ; Thu, 28 Nov 2024 08:16:58 +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=GEYrEagmpxniOToiAYSJDBe+xIavl7z+9nKf8hS/bOw=; b=a2udPBTQcqy9a8 wDN1NXcXXY0ZJII1jNsk3iVF82zGNTxXq6CebPQVu5ji9rvfTOMDPnQGlJF2if11BCd426AkS6vtC 9cGUwTIvCXLdElWbS5KoWuQX5MzfZJ7LPchQTwhXsurF0Xd4hgYS9GNZmfCe/fD+dggGiK4nECAI5 XUn64aF0u4jprlvpg0P0VtGfXQFqOC3O9zyXyGNKwoG3s0AmYMSWrD8NmDk5Vje/IIjWv9ymP7v71 DZcwC17VJTho0QFWGr/eNWuzw7FzM6QTX+jGOGQoRnGV5yldi1FEuJx/7c8qV8HplRvqaPCoMnVI2 0FDJDmOK5Kd1iGI2ML+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGZhk-0000000Extt-3Qpp; Thu, 28 Nov 2024 08:16:52 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGZhi-0000000ExtH-2saI for linux-riscv@lists.infradead.org; Thu, 28 Nov 2024 08:16:52 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-434a2f3bae4so4673845e9.3 for ; Thu, 28 Nov 2024 00:16:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1732781809; x=1733386609; 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=XtkNb7ChcpZKeghQlkhwMDhrbK5ce/xMSti4wIKo4Vk=; b=Oj9mKK05Zhq2E1MhyKWm8Upwv/CEvl3KqYd1vD2u/7UiYfq7gbaOkx0j3SekVnO4J2 MmA18UMjeLfuTULFNlyyLvt6CoragYSE2fPFuofbCM8kU570aAdHWGqS7rdoXnRrF7Xs 7J8t/qeeXRSLqqQNX0MBLz/nA4yL3xC0fBpTZKcV38DOv5qiAnGUQWatWC8w84PLSlVf jWDmm8NqZhQEZwlSLO542G2oBZ+r3XBjzB1P2q8kaMZrMs53l7Tee/DKsFbT7+mp2qDR HkZPWYb87hV7s5h5BS2C6quwOaA0Aa1K+SbkIfzbQYgfWnHThxLztsi7/suyx1/rPNBQ 0OHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732781809; x=1733386609; 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=XtkNb7ChcpZKeghQlkhwMDhrbK5ce/xMSti4wIKo4Vk=; b=RtKw2/CDYKYD4FpByKbzeakzwK44Ld/AY6rcJzNNJ4IGN0kq75t3Lm32vDfZgMcPAv IOY8CJvdqZ+3XoCg6MkYCLYBjZQOLQFDreCRhEvgYtFn+lE6GJM7B/rnOuJKWov7WLXH KocjYipzL4KTShJ8qxKJclKYCxr8qCnXvATX6k1yYHVPRwx3rxLMMFkSoj797aIeU0FN yNG+tA/iukVT8s4nuEQxe5Ng4vFacFP+Hc2F9t0uwgczZaU7/7AYOSTtkXZJYT2HTb8Z cj86IceDyAlYyft0NGzSaxdJCchv4gsgTGVLznQ49CvJ0HYMXrjigucJ5UVYl7tU6ij+ XYgw== X-Forwarded-Encrypted: i=1; AJvYcCWuHsU+PQziwDd+9hbolf917u0tD3QNx6bPXIEum0w/GvLpovRpbzxlgDrRSSuWStmG7znTavw0gERm9Q==@lists.infradead.org X-Gm-Message-State: AOJu0YxEQ71AP/jRBcjhgejjkx6ahzJI1s0Wi9aEJKTfs8QgDkEk6P65 VWxoMKtsFe5zSC1XLL83feAVpzdPzBGBt+2BUU/PeHjoPjEjHmxXFaSRHRTFpt8= X-Gm-Gg: ASbGncsiDk7kNHylyYO/jx2YHUJUnRIg55xthQ2351h1Sfu8x9ITdZEmcWexk/G4kdi qUcqCl3Unq15ovbfyu8LQUHL8I2XgV7Y+rNsNO9FBQVKUDMrHW/9gyfV5rIpnTfiHo++r9d1a/M 9JIFjR65ncxnLnwLYM1A0njQE8LcgLYlIsjK6Zw2JSsVqP9N7z6bvviSsiqIDXLYKN4ZyIEpKMf 7jsZwAL0tKJIg7oYZIv/CQ1cbmxMluuJeKe1C1R8fsEtQC4BlA= X-Google-Smtp-Source: AGHT+IFa2GLouk/rGMVQjtmqkbmXBjVyAfkRwDjDgUh0FP24cjeR4S1FKi1Ih91BYGaVuzDe63g42A== X-Received: by 2002:a05:600c:5490:b0:434:a815:2b5d with SMTP id 5b1f17b1804b1-434a9de43cfmr51318225e9.24.1732781807910; Thu, 28 Nov 2024 00:16:47 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434b0f70cbfsm13945265e9.36.2024.11.28.00.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 00:16:47 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Charlie Jenkins , Kai Zhang , Andrew Jones Subject: [PATCH v3] riscv: module: remove relocation_head rel_entry member allocation Date: Thu, 28 Nov 2024 09:16:34 +0100 Message-ID: <20241128081636.3620468-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-20241128_001650_724328_7BDEE687 X-CRM114-Status: GOOD ( 11.92 ) 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 relocation_head's list_head member, rel_entry, doesn't need to be allocated, its storage can just be part of the allocated relocation_head. Remove the pointer which allows to get rid of the allocation as well as an existing memory leak found by Kai Zhang using kmemleak. Fixes: 8fd6c5142395 ("riscv: Add remaining module relocations") Reported-by: Kai Zhang Signed-off-by: Clément Léger Reviewed-by: Andrew Jones Reviewed-by: Charlie Jenkins Tested-by: Charlie Jenkins --- V3: - Fix Zhang name spelling. - Reword commit title. - Add a 'Fixes:' tag V2: - Add Kai Zhang 'Reported-by:' tag - 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; }