diff mbox series

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

Message ID 20240424094700.453356-2-dbarboza@ventanamicro.com (mailing list archive)
State New, archived
Headers show
Series riscv,kvm: remove another strerrorname_np() | expand

Commit Message

Daniel Henrique Barboza April 24, 2024, 9:46 a.m. UTC
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)
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 target/riscv/kvm/kvm-cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Thomas Huth April 24, 2024, 9:51 a.m. UTC | #1
On 24/04/2024 11.46, Daniel Henrique Barboza wrote:
> 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)
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>   target/riscv/kvm/kvm-cpu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 6a6c6cae80..ee69ea9785 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -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);
>           }
>   

Reviewed-by: Thomas Huth <thuth@redhat.com>
Philippe Mathieu-Daudé April 24, 2024, 9:55 a.m. UTC | #2
On 24/4/24 11:46, Daniel Henrique Barboza wrote:
> 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)
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>   target/riscv/kvm/kvm-cpu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 6a6c6cae80..ee69ea9785 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -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)?

>               exit(EXIT_FAILURE);
>           }
>
Daniel Henrique Barboza April 24, 2024, 5:18 p.m. UTC | #3
On 4/24/24 06:55, Philippe Mathieu-Daudé wrote:
> On 24/4/24 11:46, Daniel Henrique Barboza wrote:
>> 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)
>> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
>> ---
>>   target/riscv/kvm/kvm-cpu.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
>> index 6a6c6cae80..ee69ea9785 100644
>> --- a/target/riscv/kvm/kvm-cpu.c
>> +++ b/target/riscv/kvm/kvm-cpu.c
>> @@ -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

> 
>>               exit(EXIT_FAILURE);
>>           }
>
Philippe Mathieu-Daudé April 24, 2024, 5:54 p.m. UTC | #4
On 24/4/24 19:18, Daniel Henrique Barboza wrote:
> On 4/24/24 06:55, Philippe Mathieu-Daudé wrote:
>> On 24/4/24 11:46, Daniel Henrique Barboza wrote:
>>> 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)
>>> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
>>> ---
>>>   target/riscv/kvm/kvm-cpu.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
>>> index 6a6c6cae80..ee69ea9785 100644
>>> --- a/target/riscv/kvm/kvm-cpu.c
>>> +++ b/target/riscv/kvm/kvm-cpu.c
>>> @@ -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.

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

Regards,

Phil.
diff mbox series

Patch

diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 6a6c6cae80..ee69ea9785 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -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);
         }