mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bo Liu <liubo03@inspur.com>
To: <pbonzini@redhat.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Bo Liu <liubo03@inspur.com>
Subject: [PATCH] KVM: replace ternary operator with min()
Date: Tue, 1 Nov 2022 03:25:13 -0400	[thread overview]
Message-ID: <20221101072513.7364-1-liubo03@inspur.com> (raw)

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


             reply	other threads:[~2022-11-01  7:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01  7:25 Bo Liu [this message]
2022-11-01 11:16 ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221101072513.7364-1-liubo03@inspur.com \
    --to=liubo03@inspur.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®