Skip to contentSkip to conversation

fs: binfmt_elf_efpic: fix variable set but not used warning

PATCH Superseded [email protected] 3 participants 4 messages Mar 7, 2025 – Mar 8, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: binfmt_elf_efpic: fix variable set but not used warning

From: sunliming <[email protected]>

Fix below kernel warning:
fs/binfmt_elf_fdpic.c:1024:52: warning: variable 'excess1' set but not used [-Wunused-but-set-variable]

---
 fs/binfmt_elf_fdpic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +5 -2
index e3cf2801cd64..bed13ee8bfec 100644
@@ -1024,8 +1024,11 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 	/* deal with each load segment separately */
 	phdr = params->phdrs;
 	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
 		int prot = 0, flags;
+#ifdef CONFIG_MMU
+		unsigned long excess1;
+#endif
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
@@ -1120,9 +1123,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 		 *   extant in the file
 		 */
 		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
 #ifdef CONFIG_MMU
+		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 		if (excess > excess1) {
 			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
 			unsigned long xmaddr;
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Fri 07-03-25 14:11:28, [email protected] wrote:

From: sunliming <[email protected]>

Fix below kernel warning:
fs/binfmt_elf_fdpic.c:1024:52: warning: variable 'excess1' set but not used [-Wunused-but-set-variable]

The extra ifdef is not pretty but I guess it's better. Feel free to add:

Honza

Quoted 35 lines
---
 fs/binfmt_elf_fdpic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +5 -2
index e3cf2801cd64..bed13ee8bfec 100644
@@ -1024,8 +1024,11 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 	/* deal with each load segment separately */
 	phdr = params->phdrs;
 	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
 		int prot = 0, flags;
+#ifdef CONFIG_MMU
+		unsigned long excess1;
+#endif
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
@@ -1120,9 +1123,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 		 *   extant in the file
 		 */
 		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
 #ifdef CONFIG_MMU
+		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 		if (excess > excess1) {
 			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
 			unsigned long xmaddr;
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer
#2 lore raw
Quoted 7 lines · Jan Kara
Quoted 6 lines · On Fri 07-03-25 14:11:28, [email protected] wrote:

From: sunliming <[email protected]>

Fix below kernel warning:
fs/binfmt_elf_fdpic.c:1024:52: warning: variable 'excess1' set but not used [-Wunused-but-set-variable]

Quoted 6 lines
Quoted 2 lines

The extra ifdef is not pretty but I guess it's better. Feel free to add:

Since we allow loop-scope variable definitions now, perhaps this is a case for defining the variable later within the #ifdef, like this?

fs/binfmt_elf_fdpic.c +3 -2
index e3cf2801cd64..b0ef71238328 100644
@@ -1024,7 +1024,7 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 	/* deal with each load segment separately */
 	phdr = params->phdrs;
 	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
 		int prot = 0, flags;
 
 		if (phdr->p_type != PT_LOAD)
@@ -1120,9 +1120,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 		 *   extant in the file
 		 */
 		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
 #ifdef CONFIG_MMU
+		const unsigned long excess1 =
+			PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 		if (excess > excess1) {
 			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
 			unsigned long xmaddr;
Quoted 41 lines

Honza

Quoted 35 lines
---
 fs/binfmt_elf_fdpic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +5 -2
index e3cf2801cd64..bed13ee8bfec 100644
@@ -1024,8 +1024,11 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 	/* deal with each load segment separately */
 	phdr = params->phdrs;
 	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
 		int prot = 0, flags;
+#ifdef CONFIG_MMU
+		unsigned long excess1;
+#endif
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
@@ -1120,9 +1123,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
 		 *   extant in the file
 		 */
 		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
 #ifdef CONFIG_MMU
+		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 		if (excess > excess1) {
 			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
 			unsigned long xmaddr;
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Signature · 1 line
Kees Cook
author
#3 lore raw
Quoted 32 lines · Kees Cook
Quoted 7 lines · Jan Kara
Quoted 6 lines · On Fri 07-03-25 14:11:28, [email protected] wrote:

From: sunliming <[email protected]>

Fix below kernel warning:
fs/binfmt_elf_fdpic.c:1024:52: warning: variable 'excess1' set but not used [-Wunused-but-set-variable]

Quoted 5 lines
Quoted 2 lines

The extra ifdef is not pretty but I guess it's better. Feel free to add:

Since we allow loop-scope variable definitions now, perhaps this is a case for defining the variable later within the #ifdef, like this?

fs/binfmt_elf_fdpic.c +1 -1
index e3cf2801cd64..b0ef71238328 100644
@@ -1024,7 +1024,7 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
  	/* deal with each load segment separately */
  	phdr = params->phdrs;
  	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
  		int prot = 0, flags;
 
  		if (phdr->p_type != PT_LOAD)
@@ -1120,9 +1120,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
  		 *   extant in the file

fs/binfmt_elf_fdpic.c static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, · line 1129

Quoted 10 lines
fs/binfmt_elf_fdpic.c +2 -1
  		 */
  		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
  #ifdef CONFIG_MMU
+		const unsigned long excess1 =
+			PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
  		if (excess > excess1) {
  			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
  			unsigned long xmaddr;

I think this is a good idea. I will resend this patch in this way,thanks.

Quoted 40 lines
Quoted 40 lines

Honza

Quoted 35 lines
---
  fs/binfmt_elf_fdpic.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
fs/binfmt_elf_fdpic.c +5 -2
index e3cf2801cd64..bed13ee8bfec 100644
@@ -1024,8 +1024,11 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
  	/* deal with each load segment separately */
  	phdr = params->phdrs;
  	for (loop = 0; loop < params->hdr.e_phnum; loop++, phdr++) {
-		unsigned long maddr, disp, excess, excess1;
+		unsigned long maddr, disp, excess;
  		int prot = 0, flags;
+#ifdef CONFIG_MMU
+		unsigned long excess1;
+#endif
 
  		if (phdr->p_type != PT_LOAD)
  			continue;
@@ -1120,9 +1123,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
  		 *   extant in the file
  		 */
  		excess = phdr->p_memsz - phdr->p_filesz;
-		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
 
  #ifdef CONFIG_MMU
+		excess1 = PAGE_SIZE - ((maddr + phdr->p_filesz) & ~PAGE_MASK);
  		if (excess > excess1) {
  			unsigned long xaddr = maddr + phdr->p_filesz + excess1;
  			unsigned long xmaddr;
Signature · 1 line
2.25.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR