* [PATCH] KVM: replace ternary operator with min()
@ 2022-11-01 7:25 Bo Liu
2022-11-01 11:16 ` David Laight
0 siblings, 1 reply; 2+ messages in thread
From: Bo Liu @ 2022-11-01 7:25 UTC (permalink / raw)
To: pbonzini; +Cc: kvm, linux-kernel, Bo Liu
Fix the following coccicheck warning:
virt/kvm/kvm_main.c:5289:10-11: WARNING opportunity for min()
virt/kvm/kvm_main.c:5218:10-11: WARNING opportunity for min()
min() macro is defined in include/linux/minmax.h. It avoids
multiple evaluations of the arguments when non-constant and
performs strict type-checking.
Signed-off-by: Bo Liu <liubo03@inspur.com>
---
virt/kvm/kvm_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3f383f27d3d7..45a56a9600e1 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5215,7 +5215,7 @@ int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
if (!bus)
return -ENOMEM;
r = __kvm_io_bus_write(vcpu, bus, &range, val);
- return r < 0 ? r : 0;
+ return min(r, 0);
}
EXPORT_SYMBOL_GPL(kvm_io_bus_write);
@@ -5286,7 +5286,7 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
if (!bus)
return -ENOMEM;
r = __kvm_io_bus_read(vcpu, bus, &range, val);
- return r < 0 ? r : 0;
+ return min(r, 0);
}
/* Caller must hold slots_lock. */
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH] KVM: replace ternary operator with min()
2022-11-01 7:25 [PATCH] KVM: replace ternary operator with min() Bo Liu
@ 2022-11-01 11:16 ` David Laight
0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2022-11-01 11:16 UTC (permalink / raw)
To: 'Bo Liu', pbonzini; +Cc: kvm, linux-kernel
From: Bo Liu
> Sent: 01 November 2022 07:25
>
> Fix the following coccicheck warning:
>
> virt/kvm/kvm_main.c:5289:10-11: WARNING opportunity for min()
...
> - return r < 0 ? r : 0;
> + return min(r, 0);
As has been repeatedly pointer out this is bogus.
min() should only be used for 'sizes'.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-01 11:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 7:25 [PATCH] KVM: replace ternary operator with min() Bo Liu
2022-11-01 11:16 ` David Laight
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.