Skip to contentSkip to conversation

kexec: Remove unused code in kimage_load_cma_segment()

PATCH Superseded Andy Shevchenko 2 participants 3 messages Sep 15, 2025 – Sep 16, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: Remove unused code in kimage_load_cma_segment()

clang is not happy about set but unused variable:

kernel/kexec_core.c:745:16: error: variable 'maddr' set but not used [-Werror,-Wunused-but-set-variable]
745 | unsigned long maddr;
| ^
1 error generated.

Fix the compilation breakage (make W=1 build) by removing unused variable.

Fixes 07d24902977e ("kexec: enable CMA based contiguous allocation")
---
 kernel/kexec_core.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/kexec_core.c +0 -3
index 5357ed39e9d1..32722926bc7e 100644
@@ -742,7 +742,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 	struct kexec_segment *segment = &image->segment[idx];
 	struct page *cma = image->segment_cma[idx];
 	char *ptr = page_address(cma);
-	unsigned long maddr;
 	size_t ubytes, mbytes;
 	int result = 0;
 	unsigned char __user *buf = NULL;
@@ -754,7 +753,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 		buf = segment->buf;
 	ubytes = segment->bufsz;
 	mbytes = segment->memsz;
-	maddr = segment->mem;
 
 	/* Then copy from source buffer to the CMA one */
 	while (mbytes) {
@@ -782,7 +780,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 		}
 
 		ptr    += mchunk;
-		maddr  += mchunk;
 		mbytes -= mchunk;
 
 		cond_resched();
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Andy,

Quoted 10 lines · Andy Shevchenko

clang is not happy about set but unused variable:

kernel/kexec_core.c:745:16: error: variable 'maddr' set but not used [-Werror,-Wunused-but-set-variable]
745 | unsigned long maddr;
| ^
1 error generated.

Fix the compilation breakage (make W=1 build) by removing unused variable.

Fixes 07d24902977e ("kexec: enable CMA based contiguous allocation")

I don't think this fixes tag is right. maddr definitely looks used in that diff. I think it is a follow up simplification that introduces this.

Fixes f4fecb50d6e1 ("kexec_core: remove superfluous page offset handling in segment loading")
Quoted 2 lines

---

Otherwise, this patch looks correct to me and GCC 16 will warn on this as well.

kernel/kexec_core.c: In function 'kimage_load_cma_segment':
kernel/kexec_core.c:745:23: error: variable 'maddr' set but not used [-Werror=unused-but-set-variable=]

    745 |         unsigned long maddr;
        |                       ^~~~~
Quoted 34 lines
 kernel/kexec_core.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/kexec_core.c +0 -3
index 5357ed39e9d1..32722926bc7e 100644
@@ -742,7 +742,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 	struct kexec_segment *segment = &image->segment[idx];
 	struct page *cma = image->segment_cma[idx];
 	char *ptr = page_address(cma);
-	unsigned long maddr;
 	size_t ubytes, mbytes;
 	int result = 0;
 	unsigned char __user *buf = NULL;
@@ -754,7 +753,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 		buf = segment->buf;
 	ubytes = segment->bufsz;
 	mbytes = segment->memsz;
-	maddr = segment->mem;
 
 	/* Then copy from source buffer to the CMA one */
 	while (mbytes) {
@@ -782,7 +780,6 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
 		}
 
 		ptr    += mchunk;
-		maddr  += mchunk;
 		mbytes -= mchunk;
 
 		cond_resched();
Signature · 1 line
2.50.1
#2 lore raw
Quoted 12 lines · Nathan Chancellor

Hi Andy,

Quoted 9 lines · Andy Shevchenko

clang is not happy about set but unused variable:

kernel/kexec_core.c:745:16: error: variable 'maddr' set but not used [-Werror,-Wunused-but-set-variable]
745 | unsigned long maddr;
| ^
1 error generated.

Fix the compilation breakage (make W=1 build) by removing unused variable.

Quoted 7 lines
Quoted 1 line
Fixes 07d24902977e ("kexec: enable CMA based contiguous allocation")

I don't think this fixes tag is right. maddr definitely looks used in that diff. I think it is a follow up simplification that introduces this.

Fixes f4fecb50d6e1 ("kexec_core: remove superfluous page offset handling in segment loading")

Oh, you are right!

Quoted 7 lines

Otherwise, this patch looks correct to me and GCC 16 will warn on this as well.

kernel/kexec_core.c: In function 'kimage_load_cma_segment':
kernel/kexec_core.c:745:23: error: variable 'maddr' set but not used [-Werror=unused-but-set-variable=]

    745 |         unsigned long maddr;
        |                       ^~~~~

I'll add this as well to the commit message (in shorter form).

Quoted 1 line

Thank you! I'm going to send a v2 soon.

Signature · 2 lines
With Best Regards,
Andy Shevchenko