From: Paolo Bonzini <pbonzini@redhat.com>
To: "SF Markus Elfring" <elfring@users.sourceforge.net>,
kvm@vger.kernel.org, kvm-ppc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, "Alexander Graf" <agraf@suse.com>,
"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write()
Date: Mon, 23 Jan 2017 15:12:55 +0100 [thread overview]
Message-ID: <7e09721f-2785-4c34-cfe8-593acafc455e@redhat.com> (raw)
In-Reply-To: <51bcdd72-467c-8afb-94cb-fd756b3d63a7@users.sourceforge.net>
On 20/01/2017 19:19, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 19 Jan 2017 22:45:56 +0100
>
> * A local variable was set to an error code in five cases
> before a concrete error situation was detected.
> Thus move the corresponding assignments into
> if branches to indicate a software failure there.
>
> This issue was detected by using the Coccinelle software.
>
> * Delete two zero assignments which became unnecessary with
> this refactoring.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
NACK, current code uses consistent style.
> ---
> arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index b795dd1ac2ef..dc34729e4ad0 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1399,22 +1399,23 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
>
> err = 0;
> for (nb = 0; nb + sizeof(hdr) <= count; ) {
> - err = -EFAULT;
> - if (__copy_from_user(&hdr, buf, sizeof(hdr)))
> + if (__copy_from_user(&hdr, buf, sizeof(hdr))) {
> + err = -EFAULT;
> break;
> + }
>
> - err = 0;
> if (nb + hdr.n_valid * HPTE_SIZE > count)
> break;
>
> nb += sizeof(hdr);
> buf += sizeof(hdr);
>
> - err = -EINVAL;
> i = hdr.index;
> if (i >= kvm->arch.hpt_npte ||
> - i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte)
> + i + hdr.n_valid + hdr.n_invalid > kvm->arch.hpt_npte) {
> + err = -EINVAL;
> break;
> + }
>
> hptp = (__be64 *)(kvm->arch.hpt_virt + (i * HPTE_SIZE));
> lbuf = (unsigned long __user *)buf;
> @@ -1422,26 +1423,28 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
> __be64 hpte_v;
> __be64 hpte_r;
>
> - err = -EFAULT;
> if (__get_user(hpte_v, lbuf) ||
> - __get_user(hpte_r, lbuf + 1))
> + __get_user(hpte_r, lbuf + 1)) {
> + err = -EFAULT;
> goto out;
> + }
> v = be64_to_cpu(hpte_v);
> r = be64_to_cpu(hpte_r);
> - err = -EINVAL;
> - if (!(v & HPTE_V_VALID))
> + if (!(v & HPTE_V_VALID)) {
> + err = -EINVAL;
> goto out;
> + }
> lbuf += 2;
> nb += HPTE_SIZE;
>
> if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT))
> kvmppc_do_h_remove(kvm, 0, i, 0, tmp);
> - err = -EIO;
> ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r,
> tmp);
> if (ret != H_SUCCESS) {
> pr_err("kvm_htab_write ret %ld i=%ld v=%lx "
> "r=%lx\n", ret, i, v, r);
> + err = -EIO;
> goto out;
> }
> if (!hpte_setup && is_vrma_hpte(v)) {
> @@ -1465,7 +1468,6 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
> ++i;
> hptp += 2;
> }
> - err = 0;
> }
>
> out:
>
next prev parent reply other threads:[~2017-01-23 14:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-20 18:18 [PATCH 00/11] PowerPC-KVM: Fine-tuning for some function implementations SF Markus Elfring
2017-01-20 18:19 ` [PATCH 01/11] KVM: PPC: Book3S HV: Move assignments for the variable "err" in kvm_htab_write() SF Markus Elfring
2017-01-23 14:12 ` Paolo Bonzini [this message]
2017-01-20 18:20 ` [PATCH 02/11] KVM: PPC: Book3S HV: Improve a size determination in kvmppc_alloc_hpt() SF Markus Elfring
2017-01-20 18:21 ` [PATCH 03/11] KVM: PPC: Book3S HV: Move error code assignments in two functions SF Markus Elfring
2017-01-23 14:13 ` Paolo Bonzini
2017-01-20 18:22 ` [PATCH 04/11] KVM: PPC: Book3S HV: Use common error handling code in kvmppc_clr_passthru_irq() SF Markus Elfring
2017-01-20 18:23 ` [PATCH 05/11] KVM: PPC: Book3S HV: Adjust nine checks for null pointers SF Markus Elfring
2017-01-23 19:22 ` Thomas Huth
2017-01-20 18:24 ` [PATCH 06/11] KVM: PPC: Book3S HV: Use kcalloc() in kvmppc_alloc_host_rm_ops() SF Markus Elfring
2017-01-20 18:25 ` [PATCH 07/11] KVM: PPC: Book3S HV: Improve size determinations in five functions SF Markus Elfring
2017-01-20 18:26 ` [PATCH 08/11] KVM: PPC: Book3S: Use seq_puts() in xics_debug_show() SF Markus Elfring
2017-01-20 18:27 ` [PATCH 09/11] KVM: PPC: Book3S: Improve a size determination in two functions SF Markus Elfring
2017-01-21 6:24 ` kbuild test robot
2017-01-21 6:37 ` kbuild test robot
2017-01-20 18:28 ` [PATCH 10/11] KVM: PPC: e500: Use kcalloc() in e500_mmu_host_init() SF Markus Elfring
2017-01-20 18:29 ` [PATCH 11/11] KVM: PPC: Return directly after a failed copy_from_user() in two functions SF Markus Elfring
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=7e09721f-2785-4c34-cfe8-593acafc455e@redhat.com \
--to=pbonzini@redhat.com \
--cc=agraf@suse.com \
--cc=benh@kernel.crashing.org \
--cc=elfring@users.sourceforge.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=rkrcmar@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®