Skip to contentSkip to conversation

mm/memory_hotplug.c:2222:47-53: ERROR: reference preceded by free on line 2227 (fwd)

PATCH New Julia Lawall 1 participant 1 message Oct 17, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 9/10 mm/memory_hotplug.c:2222:47-53: ERROR: reference preceded by free on line 2227 (fwd)

Hello,

On line 2222 there is a reference to altmap. It is not clear to me that the variable altmap has been defined on the current iteration of the loop. If it comes from the previous iteration, it might have been freed. Maybe there is an if or a return that is missing?

julia

---------- Forwarded message ----------
Date: Wed, 18 Oct 2023 00:06:08 +0800
From: kernel test robot <[email protected]>
To: [email protected]
Cc: [email protected], Julia Lawall <[email protected]>
Subject: [vishal:vv/kmem_memmap 9/10] mm/memory_hotplug.c:2222:47-53: ERROR:
reference preceded by free on line 2227

BCC: [email protected]
CC: [email protected]
TO: Vishal Verma <[email protected]>
CC: Dan Williams <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vishal/linux.git vv/kmem_memmap
head:   f5df6ac59f4892cfe6652e6ea6ed4a215c876167
commit: 9ee1af799da9d50227164305de8427a973e6c9dc [9/10] mm/memory_hotplug: split memmap_on_memory requests across memblocks

:::::: branch date: 11 hours ago
:::::: commit date: 22 hours ago
config: x86_64-randconfig-103-20231017 (https://download.01.org/0day-ci/archive/20231017/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231017/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Julia Lawall <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

mm/memory_hotplug.c:2222:47-53: ERROR: reference preceded by free on line 2227

vim +2222 mm/memory_hotplug.c

60a5a19e7419ba0 Tang Chen         2013-02-22  2189
9ee1af799da9d50 Vishal Verma      2023-08-01  2190  static void __ref remove_memory_blocks_and_altmaps(u64 start, u64 size)
bbc76be67c2c0c1 Wen Congyang      2013-02-22  2191  {
9ee1af799da9d50 Vishal Verma      2023-08-01  2192  	unsigned long memblock_size = memory_block_size_bytes();
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2193  	struct vmem_altmap *altmap = NULL;
9ee1af799da9d50 Vishal Verma      2023-08-01  2194  	struct memory_block *mem;
9ee1af799da9d50 Vishal Verma      2023-08-01  2195  	u64 cur_start;
9ee1af799da9d50 Vishal Verma      2023-08-01  2196  	int rc;
6677e3eaf4d78ab Yasuaki Ishimatsu 2013-02-22  2197
a08a2ae3461383c Oscar Salvador    2021-05-04  2198  	/*
9ee1af799da9d50 Vishal Verma      2023-08-01  2199  	 * For memmap_on_memory, the altmaps could have been added on
9ee1af799da9d50 Vishal Verma      2023-08-01  2200  	 * a per-memblock basis. Loop through the entire range if so,
9ee1af799da9d50 Vishal Verma      2023-08-01  2201  	 * and remove each memblock and its altmap.
a08a2ae3461383c Oscar Salvador    2021-05-04  2202  	 */
9ee1af799da9d50 Vishal Verma      2023-08-01  2203  	for (cur_start = start; cur_start < start + size;
9ee1af799da9d50 Vishal Verma      2023-08-01  2204  	     cur_start += memblock_size) {
9ee1af799da9d50 Vishal Verma      2023-08-01  2205  		rc = walk_memory_blocks(cur_start, memblock_size, &mem,
9ee1af799da9d50 Vishal Verma      2023-08-01  2206  					test_has_altmap_cb);
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2207  		if (rc) {
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2208  			altmap = mem->altmap;
a08a2ae3461383c Oscar Salvador    2021-05-04  2209  			/*
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2210  			 * Mark altmap NULL so that we can add a debug
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2211  			 * check on memblock free.
a08a2ae3461383c Oscar Salvador    2021-05-04  2212  			 */
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2213  			mem->altmap = NULL;
a08a2ae3461383c Oscar Salvador    2021-05-04  2214  		}
4c4b7f9ba9486c5 David Hildenbrand 2019-07-18  2215
f1037ec0cc8ac1a Dan Williams      2020-01-30  2216  		/*
f1037ec0cc8ac1a Dan Williams      2020-01-30  2217  		 * Memory block device removal under the device_hotplug_lock is
f1037ec0cc8ac1a Dan Williams      2020-01-30  2218  		 * a barrier against racing online attempts.
f1037ec0cc8ac1a Dan Williams      2020-01-30  2219  		 */
9ee1af799da9d50 Vishal Verma      2023-08-01  2220  		remove_memory_block_devices(cur_start, memblock_size);
f1037ec0cc8ac1a Dan Williams      2020-01-30  2221
9ee1af799da9d50 Vishal Verma      2023-08-01 @2222  		arch_remove_memory(cur_start, memblock_size, altmap);
52219aeaf2dc6f7 David Hildenbrand 2020-06-04  2223
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2224  		/* Verify that all vmemmap pages have actually been freed. */
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2225  		if (altmap) {
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2226  			WARN(altmap->alloc, "Altmap not fully unmapped");
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08 @2227  			kfree(altmap);
25b5b1a0646c3d3 Aneesh Kumar K.V  2023-08-08  2228  		}
9ee1af799da9d50 Vishal Verma      2023-08-01  2229  	}
9ee1af799da9d50 Vishal Verma      2023-08-01  2230  }
9ee1af799da9d50 Vishal Verma      2023-08-01  2231
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki