* + mm-utilc-add-kstrimdup.patch added to -mm tree
@ 2014-01-31 21:45 akpm
2014-02-03 9:58 ` Alexey Dobriyan
0 siblings, 1 reply; 6+ messages in thread
From: akpm @ 2014-01-31 21:45 UTC (permalink / raw)
To: mm-commits, rientjes, joe, sebastian.capella
Subject: + mm-utilc-add-kstrimdup.patch added to -mm tree
To: sebastian.capella@linaro.org,joe@perches.com,rientjes@google.com
From: akpm@linux-foundation.org
Date: Fri, 31 Jan 2014 13:45:02 -0800
The patch titled
Subject: mm/util.c: add kstrimdup()
has been added to the -mm tree. Its filename is
mm-utilc-add-kstrimdup.patch
This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mm-utilc-add-kstrimdup.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mm-utilc-add-kstrimdup.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/SubmitChecklist when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Sebastian Capella <sebastian.capella@linaro.org>
Subject: mm/util.c: add kstrimdup()
kstrimdup() creates a whitespace-trimmed duplicate of the passed in
null-terminated string. This is useful for strings coming from sysfs that
often include trailing whitespace due to user input.
Thanks to Joe Perches for this implementation.
Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>
Cc: Joe Perches <joe@perches.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/string.h | 1 +
mm/util.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff -puN include/linux/string.h~mm-utilc-add-kstrimdup include/linux/string.h
--- a/include/linux/string.h~mm-utilc-add-kstrimdup
+++ a/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, s
extern char *kstrdup(const char *s, gfp_t gfp);
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+extern char *kstrimdup(const char *s, gfp_t gfp);
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
diff -puN mm/util.c~mm-utilc-add-kstrimdup mm/util.c
--- a/mm/util.c~mm-utilc-add-kstrimdup
+++ a/mm/util.c
@@ -1,6 +1,7 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/string.h>
+#include <linux/ctype.h>
#include <linux/export.h>
#include <linux/err.h>
#include <linux/sched.h>
@@ -63,6 +64,35 @@ char *kstrndup(const char *s, size_t max
EXPORT_SYMBOL(kstrndup);
/**
+ * kstrimdup - Trim and copy a %NUL terminated string.
+ * @s: the string to trim and duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Returns an address, which the caller must kfree, containing
+ * a duplicate of the passed string with leading and/or trailing
+ * whitespace (as defined by isspace) removed.
+ */
+char *kstrimdup(const char *s, gfp_t gfp)
+{
+ char *buf;
+ char *begin = skip_spaces(s);
+ size_t len = strlen(begin);
+
+ while (len && isspace(begin[len - 1]))
+ len--;
+
+ buf = kmalloc_track_caller(len + 1, gfp);
+ if (!buf)
+ return NULL;
+
+ memcpy(buf, begin, len);
+ buf[len] = '\0';
+
+ return buf;
+}
+EXPORT_SYMBOL(kstrimdup);
+
+/**
* kmemdup - duplicate region of memory
*
* @src: memory region to duplicate
_
Patches currently in -mm which might be from sebastian.capella@linaro.org are
mm-utilc-add-kstrimdup.patch
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: + mm-utilc-add-kstrimdup.patch added to -mm tree
2014-01-31 21:45 + mm-utilc-add-kstrimdup.patch added to -mm tree akpm
@ 2014-02-03 9:58 ` Alexey Dobriyan
2014-02-04 1:05 ` David Rientjes
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2014-02-03 9:58 UTC (permalink / raw)
To: Linux Kernel; +Cc: mm-commits, David Rientjes, Joe Perches, sebastian.capella
On Sat, Feb 1, 2014 at 12:45 AM, <akpm@linux-foundation.org> wrote:
> kstrimdup() creates a whitespace-trimmed duplicate of the passed in
> null-terminated string. This is useful for strings coming from sysfs that
> often include trailing whitespace due to user input.
I think kernel should be strict in what it accepts, otherwise
case-insensivity and
what not will be added some day.
Shell will trim whitespace for you.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: + mm-utilc-add-kstrimdup.patch added to -mm tree
2014-02-03 9:58 ` Alexey Dobriyan
@ 2014-02-04 1:05 ` David Rientjes
2014-02-04 1:28 ` Sebastian Capella
0 siblings, 1 reply; 6+ messages in thread
From: David Rientjes @ 2014-02-04 1:05 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: Linux Kernel, mm-commits, Joe Perches, sebastian.capella
On Mon, 3 Feb 2014, Alexey Dobriyan wrote:
> > kstrimdup() creates a whitespace-trimmed duplicate of the passed in
> > null-terminated string. This is useful for strings coming from sysfs that
> > often include trailing whitespace due to user input.
>
> I think kernel should be strict in what it accepts, otherwise
> case-insensivity and
> what not will be added some day.
>
> Shell will trim whitespace for you.
>
The last we heard, I think Sebastian is looking to redo this series and
this patch is no longer needed. Sebastian?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: + mm-utilc-add-kstrimdup.patch added to -mm tree
2014-02-04 1:05 ` David Rientjes
@ 2014-02-04 1:28 ` Sebastian Capella
2014-02-04 1:32 ` David Rientjes
2014-02-04 2:42 ` Andrew Morton
0 siblings, 2 replies; 6+ messages in thread
From: Sebastian Capella @ 2014-02-04 1:28 UTC (permalink / raw)
To: David Rientjes, Alexey Dobriyan; +Cc: Linux Kernel, mm-commits, Joe Perches
Quoting David Rientjes (2014-02-03 17:05:04)
> The last we heard, I think Sebastian is looking to redo this series and
> this patch is no longer needed. Sebastian?
Hi David, Alexey,
I am in the process of reworking the patches. I'm not sure if Andrew
was just interested in having the kstrimdup utility function available.
Isn't it too late to impose userspace trimming of newlines for sysfs?
It seems already fairly common and expected for the kernel to eat the
trailing whitespace, or at least ignore it. If we change this won't we
be breaking userspace / tools / instructions / etc?
I'll try to post the new patches soon.
Thanks,
Sebastian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: + mm-utilc-add-kstrimdup.patch added to -mm tree
2014-02-04 1:28 ` Sebastian Capella
@ 2014-02-04 1:32 ` David Rientjes
2014-02-04 2:42 ` Andrew Morton
1 sibling, 0 replies; 6+ messages in thread
From: David Rientjes @ 2014-02-04 1:32 UTC (permalink / raw)
To: Sebastian Capella; +Cc: Alexey Dobriyan, Linux Kernel, mm-commits, Joe Perches
On Mon, 3 Feb 2014, Sebastian Capella wrote:
> I am in the process of reworking the patches. I'm not sure if Andrew
> was just interested in having the kstrimdup utility function available.
>
I think the point Alexey is making is that whitespace is already stripped
by the shell unless quoted; it seemed that you may have had a usecase
where the string to be written would not be stripped by the shell for
whatever reason and there was no convenient way to do it specifically for
the file you were modifying?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: + mm-utilc-add-kstrimdup.patch added to -mm tree
2014-02-04 1:28 ` Sebastian Capella
2014-02-04 1:32 ` David Rientjes
@ 2014-02-04 2:42 ` Andrew Morton
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2014-02-04 2:42 UTC (permalink / raw)
To: Sebastian Capella
Cc: David Rientjes, Alexey Dobriyan, Linux Kernel, mm-commits,
Joe Perches
On Mon, 03 Feb 2014 17:28:16 -0800 Sebastian Capella <sebastian.capella@linaro.org> wrote:
> Quoting David Rientjes (2014-02-03 17:05:04)
> > The last we heard, I think Sebastian is looking to redo this series and
> > this patch is no longer needed. Sebastian?
> Hi David, Alexey,
>
> I am in the process of reworking the patches. I'm not sure if Andrew
> was just interested in having the kstrimdup utility function available.
>
> Isn't it too late to impose userspace trimming of newlines for sysfs?
> It seems already fairly common and expected for the kernel to eat the
> trailing whitespace, or at least ignore it. If we change this won't we
> be breaking userspace / tools / instructions / etc?
>
We have quite a lot of codesites which open-code the newline trimming.
Providing a library function to do this will result in goodness.
That being said, I don't plan to merge kstrimdup() until it has some users.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-02-04 2:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-31 21:45 + mm-utilc-add-kstrimdup.patch added to -mm tree akpm
2014-02-03 9:58 ` Alexey Dobriyan
2014-02-04 1:05 ` David Rientjes
2014-02-04 1:28 ` Sebastian Capella
2014-02-04 1:32 ` David Rientjes
2014-02-04 2:42 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.