* [PATCH 1/2] string: make kmemdup_nul take and return void*, not char*
@ 2018-09-07 7:46 Rasmus Villemoes
2018-09-07 7:46 ` [PATCH 2/2] rxrpc: use kmemdup_nul in rxrpc_krb5_decode_principal Rasmus Villemoes
2018-09-18 7:15 ` [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2018-09-07 7:46 UTC (permalink / raw)
To: David Howells; +Cc: linux-kernel, Andrew Morton, Rasmus Villemoes
This allows kmemdup_nul to be used in cases where the source pointer is
not a char* or const char*, but the result should nevertheless have a
nul char after the memcpy'ed data.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/string.h | 2 +-
mm/util.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 4a5a0eb7df51..b44a2254bc6b 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -169,7 +169,7 @@ extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
extern const char *kstrdup_const(const char *s, gfp_t gfp);
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
-extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
+extern void *kmemdup_nul(const void *s, size_t len, gfp_t gfp);
extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
extern void argv_free(char **argv);
diff --git a/mm/util.c b/mm/util.c
index 9e3ebd2ef65f..15ef23f1176e 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -128,7 +128,7 @@ EXPORT_SYMBOL(kmemdup);
* @len: The size of the data
* @gfp: the GFP mask used in the kmalloc() call when allocating memory
*/
-char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
+void *kmemdup_nul(const void *s, size_t len, gfp_t gfp)
{
char *buf;
--
2.16.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] rxrpc: use kmemdup_nul in rxrpc_krb5_decode_principal
2018-09-07 7:46 [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
@ 2018-09-07 7:46 ` Rasmus Villemoes
2018-09-18 7:15 ` [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2018-09-07 7:46 UTC (permalink / raw)
To: David Howells; +Cc: linux-kernel, Andrew Morton, Rasmus Villemoes
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
This depends on patch 1/2.
net/rxrpc/key.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index e7f6b8823eb6..42f0ca9265c2 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -252,11 +252,9 @@ static int rxrpc_krb5_decode_principal(struct krb5_principal *princ,
paddedlen = (tmp + 3) & ~3;
if (paddedlen > toklen)
return -EINVAL;
- princ->name_parts[loop] = kmalloc(tmp + 1, GFP_KERNEL);
+ princ->name_parts[loop] = kmemdup_nul(xdr, tmp, GFP_KERNEL);
if (!princ->name_parts[loop])
return -ENOMEM;
- memcpy(princ->name_parts[loop], xdr, tmp);
- princ->name_parts[loop][tmp] = 0;
toklen -= paddedlen;
xdr += paddedlen >> 2;
}
@@ -270,11 +268,9 @@ static int rxrpc_krb5_decode_principal(struct krb5_principal *princ,
paddedlen = (tmp + 3) & ~3;
if (paddedlen > toklen)
return -EINVAL;
- princ->realm = kmalloc(tmp + 1, GFP_KERNEL);
+ princ->realm = kmemdup_nul(xdr, tmp, GFP_KERNEL);
if (!princ->realm)
return -ENOMEM;
- memcpy(princ->realm, xdr, tmp);
- princ->realm[tmp] = 0;
toklen -= paddedlen;
xdr += paddedlen >> 2;
--
2.16.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] string: make kmemdup_nul take and return void*, not char*
2018-09-07 7:46 [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
2018-09-07 7:46 ` [PATCH 2/2] rxrpc: use kmemdup_nul in rxrpc_krb5_decode_principal Rasmus Villemoes
@ 2018-09-18 7:15 ` Rasmus Villemoes
1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2018-09-18 7:15 UTC (permalink / raw)
To: David Howells; +Cc: linux-kernel, Andrew Morton, Rasmus Villemoes
On 7 September 2018 at 09:46, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
> This allows kmemdup_nul to be used in cases where the source pointer is
> not a char* or const char*, but the result should nevertheless have a
> nul char after the memcpy'ed data.
ping
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-18 7:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07 7:46 [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
2018-09-07 7:46 ` [PATCH 2/2] rxrpc: use kmemdup_nul in rxrpc_krb5_decode_principal Rasmus Villemoes
2018-09-18 7:15 ` [PATCH 1/2] string: make kmemdup_nul take and return void*, not char* Rasmus Villemoes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).