diff mbox series

kdb: use memmove instead of overlapping memcpy

Message ID 20180202145952.285505-1-arnd@arndb.de
State Accepted
Commit 2cf2f0d5b91fd1b06a6ae260462fc7945ea84add
Headers show
Series kdb: use memmove instead of overlapping memcpy | expand

Commit Message

Arnd Bergmann Feb. 2, 2018, 2:59 p.m. UTC
gcc discovered that the memcpy() arguments in kdbnearsym() overlap, so
we should really use memmove(), which is defined to handle that correctly:

In function 'memcpy',
    inlined from 'kdbnearsym' at /git/arm-soc/kernel/debug/kdb/kdb_support.c:132:4:
/git/arm-soc/include/linux/string.h:353:9: error: '__builtin_memcpy' accessing 792 bytes at offsets 0 and 8 overlaps 784 bytes at offset 8 [-Werror=restrict]
  return __builtin_memcpy(p, q, size);

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 kernel/debug/kdb/kdb_support.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.9.0

Comments

Jason Wessel Feb. 2, 2018, 3:08 p.m. UTC | #1
On 02/02/2018 08:59 AM, Arnd Bergmann wrote:
> gcc discovered that the memcpy() arguments in kdbnearsym() overlap, so

> we should really use memmove(), which is defined to handle that correctly:

> 

> In function 'memcpy',

>      inlined from 'kdbnearsym' at /git/arm-soc/kernel/debug/kdb/kdb_support.c:132:4:

> /git/arm-soc/include/linux/string.h:353:9: error: '__builtin_memcpy' accessing 792 bytes at offsets 0 and 8 overlaps 784 bytes at offset 8 [-Werror=restrict]

>    return __builtin_memcpy(p, q, size);

> 

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

> ---

>   kernel/debug/kdb/kdb_support.c | 4 ++--

>   1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c

> index 5d8ef3a07ecd..1ad4370ccbf0 100644

> --- a/kernel/debug/kdb/kdb_support.c

> +++ b/kernel/debug/kdb/kdb_support.c

> @@ -129,13 +129,13 @@ int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)

>   		}

>   		if (i >= ARRAY_SIZE(kdb_name_table)) {

>   			debug_kfree(kdb_name_table[0]);

> -			memcpy(kdb_name_table, kdb_name_table+1,

> +			memmove(kdb_name_table, kdb_name_table+1,

>   			       sizeof(kdb_name_table[0]) *

>   			       (ARRAY_SIZE(kdb_name_table)-1));

>   		} else {

>   			debug_kfree(knt1);

>   			knt1 = kdb_name_table[i];

> -			memcpy(kdb_name_table+i, kdb_name_table+i+1,

> +			memmove(kdb_name_table+i, kdb_name_table+i+1,

>   			       sizeof(kdb_name_table[0]) *

>   			       (ARRAY_SIZE(kdb_name_table)-i-1));

>   		}

> 



That is good by me.   Many thanks!  Added to queue.

Reviewed-by: Jason Wessel <jason.wessel@windriver.com>


Jason.
diff mbox series

Patch

diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
index 5d8ef3a07ecd..1ad4370ccbf0 100644
--- a/kernel/debug/kdb/kdb_support.c
+++ b/kernel/debug/kdb/kdb_support.c
@@ -129,13 +129,13 @@  int kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
 		}
 		if (i >= ARRAY_SIZE(kdb_name_table)) {
 			debug_kfree(kdb_name_table[0]);
-			memcpy(kdb_name_table, kdb_name_table+1,
+			memmove(kdb_name_table, kdb_name_table+1,
 			       sizeof(kdb_name_table[0]) *
 			       (ARRAY_SIZE(kdb_name_table)-1));
 		} else {
 			debug_kfree(knt1);
 			knt1 = kdb_name_table[i];
-			memcpy(kdb_name_table+i, kdb_name_table+i+1,
+			memmove(kdb_name_table+i, kdb_name_table+i+1,
 			       sizeof(kdb_name_table[0]) *
 			       (ARRAY_SIZE(kdb_name_table)-i-1));
 		}