[PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions

Markus Elfring posted 1 patch 3 months, 1 week ago
arch/alpha/kernel/smp.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by Markus Elfring 3 months, 1 week ago
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 30 Oct 2025 17:24:27 +0100

A pointer was assigned to a variable in two function implementations.
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/alpha/kernel/smp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/alpha/kernel/smp.c b/arch/alpha/kernel/smp.c
index ed06367ece57..8c7bc3ea7612 100644
--- a/arch/alpha/kernel/smp.c
+++ b/arch/alpha/kernel/smp.c
@@ -214,8 +214,7 @@ send_secondary_console_msg(char *str, int cpuid)
 	cp2 = str;
 	len = strlen(cp2);
 	*(unsigned int *)&cpu->ipc_buffer[0] = len;
-	cp1 = (char *) &cpu->ipc_buffer[1];
-	memcpy(cp1, cp2, len);
+	cp1 = memcpy(&cpu->ipc_buffer[1], cp2, len);
 
 	/* atomic test and set */
 	wmb();
@@ -265,8 +264,7 @@ recv_secondary_console_msg(void)
 			strcpy(buf, "<<< BOGUS MSG >>>");
 		else {
 			cp1 = (char *) &cpu->ipc_buffer[1];
-			cp2 = buf;
-			memcpy(cp2, cp1, cnt);
+			cp2 = memcpy(buf, cp1, cnt);
 			cp2[cnt] = '\0';
 			
 			while ((cp2 = strchr(cp2, '\r')) != 0) {
-- 
2.51.1
Re: [PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by Magnus Lindholm 2 months, 1 week ago
Hi Markus,

I noticed that the kernel test bot complained about some build issues,
are you planning on putting out a v2 of this patch?

Regards

Magnus
Re: [PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by Dan Carpenter 2 months, 1 week ago
On Sat, Nov 29, 2025 at 02:46:36PM +0100, Magnus Lindholm wrote:
> Hi Markus,
> 
> I noticed that the kernel test bot complained about some build issues,
> are you planning on putting out a v2 of this patch?
> 

I feel like generally we decided we didn't like the p = memcpy() patches.

regards,
dan carpenter
Re: [PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by Magnus Lindholm 2 months, 1 week ago
>
> I feel like generally we decided we didn't like the p = memcpy() patches.
>

Thanks, yes.

Regards

Magnus
Re: alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by Markus Elfring 2 months, 1 week ago
> I noticed that the kernel test bot complained about some build issues,

Implementation details can eventually be adjusted also according to
the message “warning: variable '…' set but not used”.


> are you planning on putting out a v2 of this patch?

I would appreciate corresponding constructive patch reviews if any parts of
the proposed source code transformation have got a chance for integration at all.

Regards,
Markus
Re: [PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
Posted by kernel test robot 3 months, 1 week ago
Hi Markus,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on mattst88-alpha/for-linus v6.18-rc3 next-20251031]
[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/Markus-Elfring/alpha-Use-pointers-from-memcpy-calls-for-assignments-in-two-functions/20251031-003938
base:   linus/master
patch link:    https://lore.kernel.org/r/1605dd43-5e95-46eb-a0c6-78ff8b4d51b3%40web.de
patch subject: [PATCH] alpha: Use pointers from memcpy() calls for assignments in two functions
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20251031/202510312008.rLcaBIfL-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251031/202510312008.rLcaBIfL-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510312008.rLcaBIfL-lkp@intel.com/

All warnings (new ones prefixed by >>):

   arch/alpha/kernel/smp.c: In function 'send_secondary_console_msg':
>> arch/alpha/kernel/smp.c:201:24: warning: variable 'cp1' set but not used [-Wunused-but-set-variable]
     201 |         register char *cp1, *cp2;
         |                        ^~~
   arch/alpha/kernel/smp.c: In function 'recv_secondary_console_msg':
   arch/alpha/kernel/smp.c:237:13: warning: variable 'mycpu' set but not used [-Wunused-but-set-variable]
     237 |         int mycpu, i, cnt;
         |             ^~~~~


vim +/cp1 +201 arch/alpha/kernel/smp.c

^1da177e4c3f415 Linus Torvalds 2005-04-16  192  
^1da177e4c3f415 Linus Torvalds 2005-04-16  193  /*
^1da177e4c3f415 Linus Torvalds 2005-04-16  194   * Send a message to a secondary's console.  "START" is one such
^1da177e4c3f415 Linus Torvalds 2005-04-16  195   * interesting message.  ;-)
^1da177e4c3f415 Linus Torvalds 2005-04-16  196   */
ab39c77c3246f84 Paul Gortmaker 2013-06-17  197  static void
^1da177e4c3f415 Linus Torvalds 2005-04-16  198  send_secondary_console_msg(char *str, int cpuid)
^1da177e4c3f415 Linus Torvalds 2005-04-16  199  {
^1da177e4c3f415 Linus Torvalds 2005-04-16  200  	struct percpu_struct *cpu;
^1da177e4c3f415 Linus Torvalds 2005-04-16 @201  	register char *cp1, *cp2;
^1da177e4c3f415 Linus Torvalds 2005-04-16  202  	unsigned long cpumask;
^1da177e4c3f415 Linus Torvalds 2005-04-16  203  	size_t len;
^1da177e4c3f415 Linus Torvalds 2005-04-16  204  
^1da177e4c3f415 Linus Torvalds 2005-04-16  205  	cpu = (struct percpu_struct *)
^1da177e4c3f415 Linus Torvalds 2005-04-16  206  		((char*)hwrpb
^1da177e4c3f415 Linus Torvalds 2005-04-16  207  		 + hwrpb->processor_offset
^1da177e4c3f415 Linus Torvalds 2005-04-16  208  		 + cpuid * hwrpb->processor_size);
^1da177e4c3f415 Linus Torvalds 2005-04-16  209  
^1da177e4c3f415 Linus Torvalds 2005-04-16  210  	cpumask = (1UL << cpuid);
^1da177e4c3f415 Linus Torvalds 2005-04-16  211  	if (wait_for_txrdy(cpumask))
^1da177e4c3f415 Linus Torvalds 2005-04-16  212  		goto timeout;
^1da177e4c3f415 Linus Torvalds 2005-04-16  213  
^1da177e4c3f415 Linus Torvalds 2005-04-16  214  	cp2 = str;
^1da177e4c3f415 Linus Torvalds 2005-04-16  215  	len = strlen(cp2);
^1da177e4c3f415 Linus Torvalds 2005-04-16  216  	*(unsigned int *)&cpu->ipc_buffer[0] = len;
c37a29a96dcfc93 Markus Elfring 2025-10-30  217  	cp1 = memcpy(&cpu->ipc_buffer[1], cp2, len);
^1da177e4c3f415 Linus Torvalds 2005-04-16  218  
^1da177e4c3f415 Linus Torvalds 2005-04-16  219  	/* atomic test and set */
^1da177e4c3f415 Linus Torvalds 2005-04-16  220  	wmb();
^1da177e4c3f415 Linus Torvalds 2005-04-16  221  	set_bit(cpuid, &hwrpb->rxrdy);
^1da177e4c3f415 Linus Torvalds 2005-04-16  222  
^1da177e4c3f415 Linus Torvalds 2005-04-16  223  	if (wait_for_txrdy(cpumask))
^1da177e4c3f415 Linus Torvalds 2005-04-16  224  		goto timeout;
^1da177e4c3f415 Linus Torvalds 2005-04-16  225  	return;
^1da177e4c3f415 Linus Torvalds 2005-04-16  226  
^1da177e4c3f415 Linus Torvalds 2005-04-16  227   timeout:
^1da177e4c3f415 Linus Torvalds 2005-04-16  228  	printk("Processor %x not ready\n", cpuid);
^1da177e4c3f415 Linus Torvalds 2005-04-16  229  }
^1da177e4c3f415 Linus Torvalds 2005-04-16  230  

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