2023-10-29 09:47:38

by José Pekkarinen

[permalink] [raw]
Subject: [PATCH] KVM: x86: cleanup unused variables

Reported by coccinelle, the following patch will remove some
redundant variables. This patch will address the following
warnings:

arch/x86/kvm/emulate.c:1315:5-7: Unneeded variable: "rc". Return "X86EMUL_CONTINUE" on line 1330
arch/x86/kvm/emulate.c:4557:5-7: Unneeded variable: "rc". Return "X86EMUL_CONTINUE" on line 4591
arch/x86/kvm/emulate.c:1180:5-7: Unneeded variable: "rc". Return "X86EMUL_CONTINUE" on line 1202

Signed-off-by: José Pekkarinen <[email protected]>
---
arch/x86/kvm/emulate.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2673cd5c46cb..c4bb03a88dfe 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1177,7 +1177,6 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
{
u8 sib;
int index_reg, base_reg, scale;
- int rc = X86EMUL_CONTINUE;
ulong modrm_ea = 0;

ctxt->modrm_reg = ((ctxt->rex_prefix << 1) & 8); /* REX.R */
@@ -1199,16 +1198,16 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
op->bytes = 16;
op->addr.xmm = ctxt->modrm_rm;
kvm_read_sse_reg(ctxt->modrm_rm, &op->vec_val);
- return rc;
+ return X86EMUL_CONTINUE;
}
if (ctxt->d & Mmx) {
op->type = OP_MM;
op->bytes = 8;
op->addr.mm = ctxt->modrm_rm & 7;
- return rc;
+ return X86EMUL_CONTINUE;
}
fetch_register_operand(op);
- return rc;
+ return X86EMUL_CONTINUE;
}

op->type = OP_MEM;
@@ -1306,14 +1305,12 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
ctxt->memop.addr.mem.ea = (u32)ctxt->memop.addr.mem.ea;

done:
- return rc;
+ return X86EMUL_CONTINUE;
}

static int decode_abs(struct x86_emulate_ctxt *ctxt,
struct operand *op)
{
- int rc = X86EMUL_CONTINUE;
-
op->type = OP_MEM;
switch (ctxt->ad_bytes) {
case 2:
@@ -1327,7 +1324,7 @@ static int decode_abs(struct x86_emulate_ctxt *ctxt,
break;
}
done:
- return rc;
+ return X86EMUL_CONTINUE;
}

static void fetch_bit_operand(struct x86_emulate_ctxt *ctxt)
@@ -4554,8 +4551,6 @@ static unsigned imm_size(struct x86_emulate_ctxt *ctxt)
static int decode_imm(struct x86_emulate_ctxt *ctxt, struct operand *op,
unsigned size, bool sign_extension)
{
- int rc = X86EMUL_CONTINUE;
-
op->type = OP_IMM;
op->bytes = size;
op->addr.mem.ea = ctxt->_eip;
@@ -4588,7 +4583,7 @@ static int decode_imm(struct x86_emulate_ctxt *ctxt, struct operand *op,
}
}
done:
- return rc;
+ return X86EMUL_CONTINUE;
}

static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op,
--
2.39.2


2023-10-29 13:09:52

by José Pekkarinen

[permalink] [raw]
Subject: Re: [PATCH] KVM: x86: cleanup unused variables

On 2023-10-29 11:38, José Pekkarinen wrote:
> Reported by coccinelle, the following patch will remove some
> redundant variables. This patch will address the following
> warnings:
>
> arch/x86/kvm/emulate.c:1315:5-7: Unneeded variable: "rc". Return
> "X86EMUL_CONTINUE" on line 1330
> arch/x86/kvm/emulate.c:4557:5-7: Unneeded variable: "rc". Return
> "X86EMUL_CONTINUE" on line 4591
> arch/x86/kvm/emulate.c:1180:5-7: Unneeded variable: "rc". Return
> "X86EMUL_CONTINUE" on line 1202
>
> Signed-off-by: José Pekkarinen <[email protected]>
> ---
> arch/x86/kvm/emulate.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 2673cd5c46cb..c4bb03a88dfe 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -1177,7 +1177,6 @@ static int decode_modrm(struct x86_emulate_ctxt
> *ctxt,
> {
> u8 sib;
> int index_reg, base_reg, scale;
> - int rc = X86EMUL_CONTINUE;
> ulong modrm_ea = 0;
>
> ctxt->modrm_reg = ((ctxt->rex_prefix << 1) & 8); /* REX.R */
> @@ -1199,16 +1198,16 @@ static int decode_modrm(struct x86_emulate_ctxt
> *ctxt,
> op->bytes = 16;
> op->addr.xmm = ctxt->modrm_rm;
> kvm_read_sse_reg(ctxt->modrm_rm, &op->vec_val);
> - return rc;
> + return X86EMUL_CONTINUE;
> }
> if (ctxt->d & Mmx) {
> op->type = OP_MM;
> op->bytes = 8;
> op->addr.mm = ctxt->modrm_rm & 7;
> - return rc;
> + return X86EMUL_CONTINUE;
> }
> fetch_register_operand(op);
> - return rc;
> + return X86EMUL_CONTINUE;
> }
>
> op->type = OP_MEM;
> @@ -1306,14 +1305,12 @@ static int decode_modrm(struct x86_emulate_ctxt
> *ctxt,
> ctxt->memop.addr.mem.ea = (u32)ctxt->memop.addr.mem.ea;
>
> done:
> - return rc;
> + return X86EMUL_CONTINUE;
> }
>
> static int decode_abs(struct x86_emulate_ctxt *ctxt,
> struct operand *op)
> {
> - int rc = X86EMUL_CONTINUE;
> -
> op->type = OP_MEM;
> switch (ctxt->ad_bytes) {
> case 2:
> @@ -1327,7 +1324,7 @@ static int decode_abs(struct x86_emulate_ctxt
> *ctxt,
> break;
> }
> done:
> - return rc;
> + return X86EMUL_CONTINUE;
> }
>
> static void fetch_bit_operand(struct x86_emulate_ctxt *ctxt)
> @@ -4554,8 +4551,6 @@ static unsigned imm_size(struct x86_emulate_ctxt
> *ctxt)
> static int decode_imm(struct x86_emulate_ctxt *ctxt, struct operand
> *op,
> unsigned size, bool sign_extension)
> {
> - int rc = X86EMUL_CONTINUE;
> -
> op->type = OP_IMM;
> op->bytes = size;
> op->addr.mem.ea = ctxt->_eip;
> @@ -4588,7 +4583,7 @@ static int decode_imm(struct x86_emulate_ctxt
> *ctxt, struct operand *op,
> }
> }
> done:
> - return rc;
> + return X86EMUL_CONTINUE;
> }
>
> static int decode_operand(struct x86_emulate_ctxt *ctxt, struct
> operand *op,

Sorry, this is a false positive, please skip it.

José.

2023-10-29 18:42:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] KVM: x86: cleanup unused variables

Hi Jos?,

kernel test robot noticed the following build errors:

[auto build test ERROR on kvm/queue]
[also build test ERROR on linus/master v6.6-rc7 next-20231027]
[cannot apply to kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Jos-Pekkarinen/KVM-x86-cleanup-unused-variables/20231029-174855
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
patch link: https://lore.kernel.org/r/20231029093859.138442-1-jose.pekkarinen%40foxhound.fi
patch subject: [PATCH] KVM: x86: cleanup unused variables
config: i386-buildonly-randconfig-006-20231030 (https://download.01.org/0day-ci/archive/20231030/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231030/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

arch/x86/kvm/emulate.c: In function 'decode_modrm':
>> arch/x86/kvm/emulate.c:950:9: error: 'rc' undeclared (first use in this function); did you mean 'rq'?
950 | rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \
| ^~
arch/x86/kvm/emulate.c:1225:45: note: in expansion of macro 'insn_fetch'
1225 | modrm_ea += insn_fetch(u16, ctxt);
| ^~~~~~~~~~
arch/x86/kvm/emulate.c:950:9: note: each undeclared identifier is reported only once for each function it appears in
950 | rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \
| ^~
arch/x86/kvm/emulate.c:1225:45: note: in expansion of macro 'insn_fetch'
1225 | modrm_ea += insn_fetch(u16, ctxt);
| ^~~~~~~~~~
arch/x86/kvm/emulate.c: In function 'decode_abs':
>> arch/x86/kvm/emulate.c:950:9: error: 'rc' undeclared (first use in this function); did you mean 'rq'?
950 | rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \
| ^~
arch/x86/kvm/emulate.c:1317:35: note: in expansion of macro 'insn_fetch'
1317 | op->addr.mem.ea = insn_fetch(u16, ctxt);
| ^~~~~~~~~~
arch/x86/kvm/emulate.c: In function 'decode_imm':
>> arch/x86/kvm/emulate.c:950:9: error: 'rc' undeclared (first use in this function); did you mean 'rq'?
950 | rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \
| ^~
arch/x86/kvm/emulate.c:4560:27: note: in expansion of macro 'insn_fetch'
4560 | op->val = insn_fetch(s8, ctxt);
| ^~~~~~~~~~


vim +950 arch/x86/kvm/emulate.c

6226686954c4cc drivers/kvm/x86_emulate.c Avi Kivity 2007-11-20 945
67cbc90db5c0f0 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-05-15 946 /* Fetch next part of the instruction being emulated. */
e85a10852c26d7 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-07-30 947 #define insn_fetch(_type, _ctxt) \
9506d57de3bc82 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 948 ({ _type _x; \
9506d57de3bc82 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 949 \
9506d57de3bc82 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 @950 rc = do_insn_fetch_bytes(_ctxt, sizeof(_type)); \
67cbc90db5c0f0 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-05-15 951 if (rc != X86EMUL_CONTINUE) \
67cbc90db5c0f0 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-05-15 952 goto done; \
9506d57de3bc82 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 953 ctxt->_eip += sizeof(_type); \
8616abc2537933 arch/x86/kvm/emulate.c Nick Desaulniers 2017-06-27 954 memcpy(&_x, ctxt->fetch.ptr, sizeof(_type)); \
17052f16a51af6 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 955 ctxt->fetch.ptr += sizeof(_type); \
9506d57de3bc82 arch/x86/kvm/emulate.c Paolo Bonzini 2014-05-06 956 _x; \
67cbc90db5c0f0 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-05-15 957 })
67cbc90db5c0f0 arch/x86/kvm/emulate.c Takuya Yoshikawa 2011-05-15 958

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki