Skip to contentSkip to conversation

riscv,kvm: remove another strerrorname_np()

PATCH Superseded Daniel Henrique Barboza 3 participants 10 messages Apr 24, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover riscv,kvm: remove another strerrorname_np()

Hi,

strerrorname_np() was removed last December due to problems with musl libc builds. And then I ended up adding another instance during the 9.0 cycle (commit ).

So here I am removing the newly added instance and, this time, patching checkpatch.pl to forbid this function from showing up again.

Michael, patch 1 is qemu-stable material.

Daniel Henrique Barboza (2):
target/riscv/kvm: remove sneaky strerrorname_np() instance checkpatch.pl: forbid strerrorname_np()

 scripts/checkpatch.pl      | 4 ++++
 target/riscv/kvm/kvm-cpu.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/2 target/riscv/kvm: remove sneaky strerrorname_np() instance

Commit d424db2354 excluded some strerrorname_np() instances because they break musl libc builds. Another instance happened to slip by via commit d4ff3da8f4.

Remove it before it causes trouble again.

Fixes d4ff3da8f4 (target/riscv/kvm: initialize 'vlenb' via get-reg-list)
---
 target/riscv/kvm/kvm-cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/kvm/kvm-cpu.c +2 -2
index 6a6c6cae80..ee69ea9785 100644
@@ -1054,8 +1054,8 @@ static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
 
         ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
         if (ret != 0) {
-            error_report("Unable to read vlenb register, error code: %s",
-                         strerrorname_np(errno));
+            error_report("Unable to read vlenb register, error code: %d",
+                         errno);
             exit(EXIT_FAILURE);
         }
 
Signature · 1 line
2.44.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] target/riscv/kvm: remove sneaky strerrorname_np() instance

Quoted 17 lines · Daniel Henrique Barboza

Commit d424db2354 excluded some strerrorname_np() instances because they break musl libc builds. Another instance happened to slip by via commit d4ff3da8f4.

Remove it before it causes trouble again.

Fixes d4ff3da8f4 (target/riscv/kvm: initialize 'vlenb' via get-reg-list)
---
  target/riscv/kvm/kvm-cpu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/kvm/kvm-cpu.c +0 -0
index 6a6c6cae80..ee69ea9785 100644

target/riscv/kvm/kvm-cpu.c static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, · line 1061

Quoted 10 lines
target/riscv/kvm/kvm-cpu.c +2 -2
@@ -1054,8 +1054,8 @@ static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
 
          ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
          if (ret != 0) {
-            error_report("Unable to read vlenb register, error code: %s",
-                         strerrorname_np(errno));
+            error_report("Unable to read vlenb register, error code: %d",
+                         errno);
              exit(EXIT_FAILURE);
          }
 
#3 lore raw

Re: [PATCH 1/2] target/riscv/kvm: remove sneaky strerrorname_np() instance

In reply to Daniel Henrique Barboza
Quoted 17 lines · Daniel Henrique Barboza

Commit d424db2354 excluded some strerrorname_np() instances because they break musl libc builds. Another instance happened to slip by via commit d4ff3da8f4.

Remove it before it causes trouble again.

Fixes d4ff3da8f4 (target/riscv/kvm: initialize 'vlenb' via get-reg-list)
---
  target/riscv/kvm/kvm-cpu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/kvm/kvm-cpu.c +0 -0
index 6a6c6cae80..ee69ea9785 100644

target/riscv/kvm/kvm-cpu.c static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, · line 1058

Quoted 7 lines
target/riscv/kvm/kvm-cpu.c +2 -2
@@ -1054,8 +1054,8 @@ static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
 
          ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
          if (ret != 0) {
-            error_report("Unable to read vlenb register, error code: %s",
-                         strerrorname_np(errno));
+            error_report("Unable to read vlenb register, error code: %d",
+                         errno);

Why not use "%s" strerror(errno)?

Quoted 3 lines
target/riscv/kvm/kvm-cpu.c +0 -0
              exit(EXIT_FAILURE);
          }
 
#4 lore raw

Re: [PATCH 1/2] target/riscv/kvm: remove sneaky strerrorname_np() instance

Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Daniel Henrique Barboza

Commit d424db2354 excluded some strerrorname_np() instances because they break musl libc builds. Another instance happened to slip by via commit d4ff3da8f4.

Remove it before it causes trouble again.

Fixes d4ff3da8f4 (target/riscv/kvm: initialize 'vlenb' via get-reg-list)

---
  target/riscv/kvm/kvm-cpu.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

target/riscv/kvm/kvm-cpu.c static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, · line 1057

Quoted 11 lines
target/riscv/kvm/kvm-cpu.c +2 -2
index 6a6c6cae80..ee69ea9785 100644
@@ -1054,8 +1054,8 @@ static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
           ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
           if (ret != 0) {
-            error_report("Unable to read vlenb register, error code: %s",
-                         strerrorname_np(errno));
+            error_report("Unable to read vlenb register, error code: %d",
+                         errno);

Why not use "%s" strerror(errno)?

It's not exactly the same. For errno = 2 strerrorname_np() gives "ENOENT", and sterror() gives "No such file or directory". In this particular context I think just printing a "error code -2" is clearer because we're not mentioning files and dirs in a KVM reg context.

But in the end I don't mind changing to strerror() if you feel strong about it. It's fine either way.

Thanks,

Daniel

Quoted 4 lines
Quoted 3 lines
target/riscv/kvm/kvm-cpu.c +0 -0
               exit(EXIT_FAILURE);
           }
#5 lore raw

Re: [PATCH 1/2] target/riscv/kvm: remove sneaky strerrorname_np() instance

Quoted 31 lines · Daniel Henrique Barboza
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Daniel Henrique Barboza

Commit d424db2354 excluded some strerrorname_np() instances because they break musl libc builds. Another instance happened to slip by via commit d4ff3da8f4.

Remove it before it causes trouble again.

Fixes d4ff3da8f4 (target/riscv/kvm: initialize 'vlenb' via get-reg-list)

---
  target/riscv/kvm/kvm-cpu.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 5 lines
target/riscv/kvm/kvm-cpu.c +0 -0
index 6a6c6cae80..ee69ea9785 100644

target/riscv/kvm/kvm-cpu.c static void kvm_riscv_read_vlenb(RISCVCPU *cpu, · line 1060

Quoted 9 lines
target/riscv/kvm/kvm-cpu.c +2 -2
@@ -1054,8 +1054,8 @@ static void kvm_riscv_read_vlenb(RISCVCPU *cpu, 
 KVMScratchCPU *kvmcpu,
           ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, &reg);
           if (ret != 0) {
-            error_report("Unable to read vlenb register, error code: 
 %s",
-                         strerrorname_np(errno));
+            error_report("Unable to read vlenb register, error code: 
 %d",
+                         errno);

Why not use "%s" strerror(errno)?

Quoted 7 lines

It's not exactly the same. For errno = 2 strerrorname_np() gives "ENOENT", and sterror() gives "No such file or directory". In this particular context I think just printing a "error code -2" is clearer because we're not mentioning files and dirs in a KVM reg context.

But in the end I don't mind changing to strerror() if you feel strong about it. It's fine either way.

I'm fine with "error code -2" ;)

Regards,

Phil.

#6 lore raw

PATCH 2/2 checkpatch.pl: forbid strerrorname_np()

In reply to Daniel Henrique Barboza

Commit d424db2354 removed an instance of strerrorname_np() because it was breaking building with musl libc. A recent RISC-V patch ended up re-introducing it again by accident.

Put this function in the baddies list in checkpatch.pl to avoid this situation again. This is what it will look like next time:

 $ ./scripts/checkpatch.pl 0001-temp-test.patch
 ERROR: use strerror() instead of strerrorname_np()
 #22: FILE: target/riscv/kvm/kvm-cpu.c:1058:
 +                         strerrorname_np(errno));

total: 1 errors, 0 warnings, 10 lines checked

---
 scripts/checkpatch.pl | 4 ++++
 1 file changed, 4 insertions(+)
scripts/checkpatch.pl +4 -0
index 7026895074..be0982246d 100755
@@ -3056,6 +3056,10 @@ sub process {
 		}
 	}
 
+	if ($line =~ /\bstrerrorname_np\(/) {
+		ERROR("use strerror() instead of strerrorname_np()\n" . $herecurr);
+	}
+
 # check for non-portable libc calls that have portable alternatives in QEMU
 		if ($line =~ /\bffs\(/) {
 			ERROR("use ctz32() instead of ffs()\n" . $herecurr);
Signature · 1 line
2.44.0
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] checkpatch.pl: forbid strerrorname_np()

Quoted 24 lines · Daniel Henrique Barboza

Commit d424db2354 removed an instance of strerrorname_np() because it was breaking building with musl libc. A recent RISC-V patch ended up re-introducing it again by accident.

Put this function in the baddies list in checkpatch.pl to avoid this situation again. This is what it will look like next time:

  $ ./scripts/checkpatch.pl 0001-temp-test.patch
  ERROR: use strerror() instead of strerrorname_np()
  #22: FILE: target/riscv/kvm/kvm-cpu.c:1058:
  +                         strerrorname_np(errno));

total: 1 errors, 0 warnings, 10 lines checked

---
  scripts/checkpatch.pl | 4 ++++
  1 file changed, 4 insertions(+)
scripts/checkpatch.pl +0 -0
index 7026895074..be0982246d 100755

scripts/checkpatch.pl sub process { · line 3065

Quoted 10 lines
scripts/checkpatch.pl +4 -0
@@ -3056,6 +3056,10 @@ sub process {
  		}
  	}
 
+	if ($line =~ /\bstrerrorname_np\(/) {
+		ERROR("use strerror() instead of strerrorname_np()\n" . $herecurr);
+	}
+
  # check for non-portable libc calls that have portable alternatives in QEMU
  		if ($line =~ /\bffs\(/) {
  			ERROR("use ctz32() instead of ffs()\n" . $herecurr);
#8 lore raw

Re: [PATCH 2/2] checkpatch.pl: forbid strerrorname_np()

In reply to Daniel Henrique Barboza
Quoted 24 lines · Daniel Henrique Barboza

Commit d424db2354 removed an instance of strerrorname_np() because it was breaking building with musl libc. A recent RISC-V patch ended up re-introducing it again by accident.

Put this function in the baddies list in checkpatch.pl to avoid this situation again. This is what it will look like next time:

  $ ./scripts/checkpatch.pl 0001-temp-test.patch
  ERROR: use strerror() instead of strerrorname_np()
  #22: FILE: target/riscv/kvm/kvm-cpu.c:1058:
  +                         strerrorname_np(errno));

total: 1 errors, 0 warnings, 10 lines checked

---
  scripts/checkpatch.pl | 4 ++++
  1 file changed, 4 insertions(+)
scripts/checkpatch.pl +0 -0
index 7026895074..be0982246d 100755

scripts/checkpatch.pl sub process { · line 3063

Quoted 8 lines
scripts/checkpatch.pl +4 -0
@@ -3056,6 +3056,10 @@ sub process {
  		}
  	}
 
+	if ($line =~ /\bstrerrorname_np\(/) {
+		ERROR("use strerror() instead of strerrorname_np()\n" . $herecurr);
+	}
+
  # check for non-portable libc calls that have portable alternatives in QEMU

This should be added here in the "non-portable libc calls" section.

Quoted 2 lines
scripts/checkpatch.pl +0 -0
  		if ($line =~ /\bffs\(/) {
  			ERROR("use ctz32() instead of ffs()\n" . $herecurr);