Skip to contentSkip to conversation

x86/umip: Use pointer from memcpy() call for assignment in fixup_umip_exception()

PATCH New Markus Elfring 2 participants 2 messages Oct 31, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/umip: Use pointer from memcpy() call for assignment in fixup_umip_exception()

From: Markus Elfring <[email protected]>
Date: Fri, 31 Oct 2025 10:10:44 +0100

A pointer was assigned to a variable. The same pointer was used for the destination parameter of a memcpy() call.
This function is documented in the way that the same value is returned. Thus convert two separate statements into a direct variable assignment for the return value from a memory copy action.

The source code was transformed by using the Coccinelle software.

---
 arch/x86/kernel/umip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/umip.c +2 -2
index d432f3824f0c..693905a363eb 100644
@@ -398,8 +398,8 @@ bool fixup_umip_exception(struct pt_regs *regs)
 		if (reg_offset < 0)
 			return false;
 
-		reg_addr = (unsigned long *)((unsigned long)regs + reg_offset);
-		memcpy(reg_addr, dummy_data, dummy_data_size);
+		reg_addr = memcpy((unsigned long *)((unsigned long)regs + reg_offset),
+				  dummy_data, dummy_data_size);
 	} else {
 		uaddr = insn_get_addr_ref(&insn, regs);
 		if ((unsigned long)uaddr == -1L)
Signature · 1 line
2.51.1
#1 lore raw
All warnings (new ones prefixed by >>):

All warnings (new ones prefixed by >>):

arch/x86/kernel/umip.c: In function 'fixup_umip_exception':

>> arch/x86/kernel/umip.c:353:24: warning: variable 'reg_addr' set but not used [-Wunused-but-set-variable]
     353 |         unsigned long *reg_addr;
         |                        ^~~~~~~~

vim +/reg_addr +353 arch/x86/kernel/umip.c

c6a960bbf6a365 Ricardo Neri   2017-11-05  328  
1e5db223696afa Ricardo Neri   2017-11-05  329  /**
1e5db223696afa Ricardo Neri   2017-11-05  330   * fixup_umip_exception() - Fixup a general protection fault caused by UMIP
1e5db223696afa Ricardo Neri   2017-11-05  331   * @regs:	Registers as saved when entering the #GP handler
1e5db223696afa Ricardo Neri   2017-11-05  332   *
e86c2c8b938044 Brendan Shanks 2019-09-05  333   * The instructions SGDT, SIDT, STR, SMSW and SLDT cause a general protection
e86c2c8b938044 Brendan Shanks 2019-09-05  334   * fault if executed with CPL > 0 (i.e., from user space). This function fixes
e86c2c8b938044 Brendan Shanks 2019-09-05  335   * the exception up and provides dummy results for SGDT, SIDT and SMSW; STR
e86c2c8b938044 Brendan Shanks 2019-09-05  336   * and SLDT are not fixed up.
1e5db223696afa Ricardo Neri   2017-11-05  337   *
1e5db223696afa Ricardo Neri   2017-11-05  338   * If operands are memory addresses, results are copied to user-space memory as
1e5db223696afa Ricardo Neri   2017-11-05  339   * indicated by the instruction pointed by eIP using the registers indicated in
1e5db223696afa Ricardo Neri   2017-11-05  340   * the instruction operands. If operands are registers, results are copied into
1e5db223696afa Ricardo Neri   2017-11-05  341   * the context that was saved when entering kernel mode.
1e5db223696afa Ricardo Neri   2017-11-05  342   *
1e5db223696afa Ricardo Neri   2017-11-05  343   * Returns:
1e5db223696afa Ricardo Neri   2017-11-05  344   *
1e5db223696afa Ricardo Neri   2017-11-05  345   * True if emulation was successful; false if not.
1e5db223696afa Ricardo Neri   2017-11-05  346   */
1e5db223696afa Ricardo Neri   2017-11-05  347  bool fixup_umip_exception(struct pt_regs *regs)
1e5db223696afa Ricardo Neri   2017-11-05  348  {
172b75e56b0884 Joerg Roedel   2020-09-07  349  	int nr_copied, reg_offset, dummy_data_size, umip_inst;
1e5db223696afa Ricardo Neri   2017-11-05  350  	/* 10 bytes is the maximum size of the result of UMIP instructions */
1e5db223696afa Ricardo Neri   2017-11-05  351  	unsigned char dummy_data[10] = { 0 };
1e5db223696afa Ricardo Neri   2017-11-05  352  	unsigned char buf[MAX_INSN_SIZE];

172b75e56b0884 Joerg Roedel 2020-09-07 @353 unsigned long *reg_addr;

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