linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] PM / Hibernate: sysfs resume
@ 2014-01-29 23:48 Sebastian Capella
  2014-01-29 23:48 ` [PATCH v4 1/2] mm: add kstrimdup function Sebastian Capella
  2014-01-29 23:48 ` [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume Sebastian Capella
  0 siblings, 2 replies; 13+ messages in thread
From: Sebastian Capella @ 2014-01-29 23:48 UTC (permalink / raw)
  To: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches

Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - add kstrimdup function which trims and duplicates a string

  Both patches are based on the 3.13 tag.  This was tested on a
  Beaglebone black with partial hibernation support, and compiled for
  x86_64.

[PATCH v4 1/2] mm: add kstrimdup function
  include/linux/string.h |    1 +
  mm/util.c              |   19 +++++++++++++++++++
  2 files changed, 20 insertions(+)

  Adds the kstrimdup function to duplicate and trim whitespace
  from a string.  This is useful for working with user input to
  sysfs.

[PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   33
  +++++++++++++++++----------------
  1 file changed, 17 insertions(+), 16 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v4:
--------------
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--------------
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--------------
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-29 23:48 [PATCH v4 0/2] PM / Hibernate: sysfs resume Sebastian Capella
@ 2014-01-29 23:48 ` Sebastian Capella
  2014-01-30  0:58   ` Mikulas Patocka
  2014-01-31 10:32   ` Pavel Machek
  2014-01-29 23:48 ` [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume Sebastian Capella
  1 sibling, 2 replies; 13+ messages in thread
From: Sebastian Capella @ 2014-01-29 23:48 UTC (permalink / raw)
  To: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches
  Cc: Sebastian Capella, Andrew Morton, Michel Lespinasse, Shaohua Li,
	Jerome Marchand, Mikulas Patocka, Joonsoo Kim

kstrimdup will duplicate and trim spaces from the passed in
null terminated string.  This is useful for strings coming from
sysfs that often include trailing whitespace due to user input.

Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rik van Riel <riel@redhat.com> (commit_signer:5/10=50%)
Cc: Michel Lespinasse <walken@google.com>
Cc: Shaohua Li <shli@kernel.org>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 include/linux/string.h |    1 +
 mm/util.c              |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..f29f9a0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
 
 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 --git a/mm/util.c b/mm/util.c
index a24aa22..da17de5 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -63,6 +63,25 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
 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 *ret = kstrdup(skip_spaces(s), gfp);
+
+	if (ret)
+		strim(ret);
+	return ret;
+}
+EXPORT_SYMBOL(kstrimdup);
+
+/**
  * kmemdup - duplicate region of memory
  *
  * @src: memory region to duplicate
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  2014-01-29 23:48 [PATCH v4 0/2] PM / Hibernate: sysfs resume Sebastian Capella
  2014-01-29 23:48 ` [PATCH v4 1/2] mm: add kstrimdup function Sebastian Capella
@ 2014-01-29 23:48 ` Sebastian Capella
  2014-01-30 18:01   ` Pavel Machek
  1 sibling, 1 reply; 13+ messages in thread
From: Sebastian Capella @ 2014-01-29 23:48 UTC (permalink / raw)
  To: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches
  Cc: Sebastian Capella, Pavel Machek, Len Brown, Rafael J. Wysocki

Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
---
 kernel/power/hibernate.c |   33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 37170d4..b4a3e0b 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -973,26 +973,27 @@ static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
 			    const char *buf, size_t n)
 {
-	unsigned int maj, min;
 	dev_t res;
-	int ret = -EINVAL;
+	char *name = kstrimdup(buf, GFP_KERNEL);
 
-	if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-		goto out;
+	if (name == NULL)
+		return -ENOMEM;
 
-	res = MKDEV(maj,min);
-	if (maj != MAJOR(res) || min != MINOR(res))
-		goto out;
+	res = name_to_dev_t(name);
 
-	lock_system_sleep();
-	swsusp_resume_device = res;
-	unlock_system_sleep();
-	printk(KERN_INFO "PM: Starting manual resume from disk\n");
-	noresume = 0;
-	software_resume();
-	ret = n;
- out:
-	return ret;
+	if (res != 0) {
+		lock_system_sleep();
+		swsusp_resume_device = res;
+		unlock_system_sleep();
+		printk(KERN_INFO "PM: Starting manual resume from disk\n");
+		noresume = 0;
+		software_resume();
+	} else {
+		n = -EINVAL;
+	}
+
+	kfree(name);
+	return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-29 23:48 ` [PATCH v4 1/2] mm: add kstrimdup function Sebastian Capella
@ 2014-01-30  0:58   ` Mikulas Patocka
  2014-01-30  1:02     ` Mikulas Patocka
  2014-01-30  1:24     ` Joe Perches
  2014-01-31 10:32   ` Pavel Machek
  1 sibling, 2 replies; 13+ messages in thread
From: Mikulas Patocka @ 2014-01-30  0:58 UTC (permalink / raw)
  To: Sebastian Capella
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Andrew Morton, Michel Lespinasse, Shaohua Li, Jerome Marchand,
	Joonsoo Kim



On Wed, 29 Jan 2014, Sebastian Capella wrote:

> kstrimdup will duplicate and trim spaces from the passed in
> null terminated string.  This is useful for strings coming from
> sysfs that often include trailing whitespace due to user input.
> 
> Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Rik van Riel <riel@redhat.com> (commit_signer:5/10=50%)
> Cc: Michel Lespinasse <walken@google.com>
> Cc: Shaohua Li <shli@kernel.org>
> Cc: Jerome Marchand <jmarchan@redhat.com>
> Cc: Mikulas Patocka <mpatocka@redhat.com>
> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> ---
>  include/linux/string.h |    1 +
>  mm/util.c              |   19 +++++++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/include/linux/string.h b/include/linux/string.h
> index ac889c5..f29f9a0 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
>  
>  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 --git a/mm/util.c b/mm/util.c
> index a24aa22..da17de5 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -63,6 +63,25 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
>  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.

It doesn't remove leading whitespace. To remove them, you need to do

char *p = strim(ret);
memmove(ret, p, strlen(p) + 1);

Mikulas

> + */
> +char *kstrimdup(const char *s, gfp_t gfp)
> +{
> +	char *ret = kstrdup(skip_spaces(s), gfp);
> +
> +	if (ret)
> +		strim(ret);
> +	return ret;
> +}
> +EXPORT_SYMBOL(kstrimdup);
> +
> +/**
>   * kmemdup - duplicate region of memory
>   *
>   * @src: memory region to duplicate
> -- 
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-30  0:58   ` Mikulas Patocka
@ 2014-01-30  1:02     ` Mikulas Patocka
  2014-01-30  1:24     ` Joe Perches
  1 sibling, 0 replies; 13+ messages in thread
From: Mikulas Patocka @ 2014-01-30  1:02 UTC (permalink / raw)
  To: Sebastian Capella
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Andrew Morton, Michel Lespinasse, Shaohua Li, Jerome Marchand,
	Joonsoo Kim



On Wed, 29 Jan 2014, Mikulas Patocka wrote:

> 
> 
> On Wed, 29 Jan 2014, Sebastian Capella wrote:
> 
> > kstrimdup will duplicate and trim spaces from the passed in
> > null terminated string.  This is useful for strings coming from
> > sysfs that often include trailing whitespace due to user input.
> > 
> > Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Rik van Riel <riel@redhat.com> (commit_signer:5/10=50%)
> > Cc: Michel Lespinasse <walken@google.com>
> > Cc: Shaohua Li <shli@kernel.org>
> > Cc: Jerome Marchand <jmarchan@redhat.com>
> > Cc: Mikulas Patocka <mpatocka@redhat.com>
> > Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> > ---
> >  include/linux/string.h |    1 +
> >  mm/util.c              |   19 +++++++++++++++++++
> >  2 files changed, 20 insertions(+)
> > 
> > diff --git a/include/linux/string.h b/include/linux/string.h
> > index ac889c5..f29f9a0 100644
> > --- a/include/linux/string.h
> > +++ b/include/linux/string.h
> > @@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
> >  
> >  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 --git a/mm/util.c b/mm/util.c
> > index a24aa22..da17de5 100644
> > --- a/mm/util.c
> > +++ b/mm/util.c
> > @@ -63,6 +63,25 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
> >  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.
> 
> It doesn't remove leading whitespace. To remove them, you need to do

I was wrong - I forgot about that skip_spaces in kstrdup.

Mikulas

> > + */
> > +char *kstrimdup(const char *s, gfp_t gfp)
> > +{
> > +	char *ret = kstrdup(skip_spaces(s), gfp);
> > +
> > +	if (ret)
> > +		strim(ret);
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL(kstrimdup);
> > +
> > +/**
> >   * kmemdup - duplicate region of memory
> >   *
> >   * @src: memory region to duplicate
> > -- 
> > 1.7.9.5
> > 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-30  0:58   ` Mikulas Patocka
  2014-01-30  1:02     ` Mikulas Patocka
@ 2014-01-30  1:24     ` Joe Perches
  2014-01-30  3:41       ` Sebastian Capella
  1 sibling, 1 reply; 13+ messages in thread
From: Joe Perches @ 2014-01-30  1:24 UTC (permalink / raw)
  To: Mikulas Patocka
  Cc: Sebastian Capella, linux-kernel, linux-mm, linux-pm,
	linaro-kernel, patches, Andrew Morton, Michel Lespinasse,
	Shaohua Li, Jerome Marchand, Joonsoo Kim

On Wed, 2014-01-29 at 19:58 -0500, Mikulas Patocka wrote:
> On Wed, 29 Jan 2014, Sebastian Capella wrote:
> > kstrimdup will duplicate and trim spaces from the passed in
> > null terminated string.  This is useful for strings coming from
> > sysfs that often include trailing whitespace due to user input. 
[]
> > diff --git a/mm/util.c b/mm/util.c
[]
> >  /**
> > + * 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.
> 
> It doesn't remove leading whitespace. To remove them, you need to do
> 
> char *p = strim(ret);
> memmove(ret, p, strlen(p) + 1);
[]
> > + */
> > +char *kstrimdup(const char *s, gfp_t gfp)
> > +{
> > +	char *ret = kstrdup(skip_spaces(s), gfp);
> > +
> > +	if (ret)
> > +		strim(ret);
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL(kstrimdup);

Why not minimize the malloc length too?

maybe something like:

char *kstrimdup(const char *s, gfp_t gfp)
{
	char *buf;
	const 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;
}



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-30  1:24     ` Joe Perches
@ 2014-01-30  3:41       ` Sebastian Capella
  2014-01-30  3:50         ` Joe Perches
  0 siblings, 1 reply; 13+ messages in thread
From: Sebastian Capella @ 2014-01-30  3:41 UTC (permalink / raw)
  To: Joe Perches, Mikulas Patocka
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Andrew Morton, Michel Lespinasse, Shaohua Li, Jerome Marchand,
	Joonsoo Kim

Quoting Joe Perches (2014-01-29 17:24:28)
> Why not minimize the malloc length too?
> 
> maybe something like:
> 
> char *kstrimdup(const char *s, gfp_t gfp)
> {
>         char *buf;
>         const 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;
> }

I figured it would be mostly for small trimming, but it seems like
it could be and advantage and used more generally this way.

I have a couple of small changes to return NULL in empty string/all ws
cases and fix a buffer underrun.

How does this look?

Thanks,

Sebastian


char *kstrimdup(const char *s, gfp_t gfp)
{                                                                                
        char *buf;                                                               
        const char *begin = skip_spaces(s);                                      
        size_t len = strlen(begin);                                              

        if (len == 0)                                                            
                return NULL;                                                     
                                                                                 
        while (len > 1 && 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;                                                              
}        




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-30  3:41       ` Sebastian Capella
@ 2014-01-30  3:50         ` Joe Perches
  0 siblings, 0 replies; 13+ messages in thread
From: Joe Perches @ 2014-01-30  3:50 UTC (permalink / raw)
  To: Sebastian Capella
  Cc: Mikulas Patocka, linux-kernel, linux-mm, linux-pm, linaro-kernel,
	patches, Andrew Morton, Michel Lespinasse, Shaohua Li,
	Jerome Marchand, Joonsoo Kim

On Wed, 2014-01-29 at 19:41 -0800, Sebastian Capella wrote:
> Quoting Joe Perches (2014-01-29 17:24:28)
> > Why not minimize the malloc length too?
> > 

> I figured it would be mostly for small trimming, but it seems like
> it could be and advantage and used more generally this way.
> 
> I have a couple of small changes to return NULL in empty string/all ws
> cases and fix a buffer underrun.
> 
> How does this look?
[]
> char *kstrimdup(const char *s, gfp_t gfp)
> {                                                                                
>         char *buf;                                                               
>         const char *begin = skip_spaces(s);                                      
>         size_t len = strlen(begin);                                              

removing begin and just using s would work

>         if (len == 0)                                                            
>                 return NULL;                                                     
>                                                                                  
>         while (len > 1 && 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;                                                              
> }

What should the return be to this string?

" "

Should it be "" or " " or NULL?

I don't think it should be NULL.
I don't think it should be " ".

cheers, Joe


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  2014-01-29 23:48 ` [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume Sebastian Capella
@ 2014-01-30 18:01   ` Pavel Machek
  0 siblings, 0 replies; 13+ messages in thread
From: Pavel Machek @ 2014-01-30 18:01 UTC (permalink / raw)
  To: Sebastian Capella
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Len Brown, Rafael J. Wysocki

On Wed 2014-01-29 15:48:24, Sebastian Capella wrote:
> Use the name_to_dev_t call to parse the device name echo'd to
> to /sys/power/resume.  This imitates the method used in hibernate.c
> in software_resume, and allows the resume partition to be specified
> using other equivalent device formats as well.  By allowing
> /sys/debug/resume to accept the same syntax as the resume=device
> parameter, we can parse the resume=device in the init script and
> use the resume device directly from the kernel command line.
> 
> Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org>

Acked-by: Pavel Machek <pavel@ucw.cz>

									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-29 23:48 ` [PATCH v4 1/2] mm: add kstrimdup function Sebastian Capella
  2014-01-30  0:58   ` Mikulas Patocka
@ 2014-01-31 10:32   ` Pavel Machek
  2014-01-31 10:46     ` David Rientjes
  1 sibling, 1 reply; 13+ messages in thread
From: Pavel Machek @ 2014-01-31 10:32 UTC (permalink / raw)
  To: Sebastian Capella
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Andrew Morton, Michel Lespinasse, Shaohua Li, Jerome Marchand,
	Mikulas Patocka, Joonsoo Kim, Rafael J. Wysocki

On Wed 2014-01-29 15:48:23, Sebastian Capella wrote:
> kstrimdup will duplicate and trim spaces from the passed in
> null terminated string.  This is useful for strings coming from
> sysfs that often include trailing whitespace due to user input.

Is it good idea? I mean "\n\n/foo bar baz" is valid filename in
unix. This is kernel interface, it is not meant to be too user
friendly...
									Pavel


> +char *kstrimdup(const char *s, gfp_t gfp)
> +{
> +	char *ret = kstrdup(skip_spaces(s), gfp);
> +
> +	if (ret)
> +		strim(ret);
> +	return ret;
> +}
> +EXPORT_SYMBOL(kstrimdup);
> +
> +/**
>   * kmemdup - duplicate region of memory
>   *
>   * @src: memory region to duplicate

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-31 10:32   ` Pavel Machek
@ 2014-01-31 10:46     ` David Rientjes
  2014-01-31 12:24       ` Pavel Machek
  0 siblings, 1 reply; 13+ messages in thread
From: David Rientjes @ 2014-01-31 10:46 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Sebastian Capella, linux-kernel, linux-mm, linux-pm,
	linaro-kernel, patches, Andrew Morton, Michel Lespinasse,
	Shaohua Li, Jerome Marchand, Mikulas Patocka, Joonsoo Kim,
	Rafael J. Wysocki

On Fri, 31 Jan 2014, Pavel Machek wrote:

> > kstrimdup will duplicate and trim spaces from the passed in
> > null terminated string.  This is useful for strings coming from
> > sysfs that often include trailing whitespace due to user input.
> 
> Is it good idea? I mean "\n\n/foo bar baz" is valid filename in
> unix. This is kernel interface, it is not meant to be too user
> friendly...

v6 of this patchset carries your ack of the patch that uses this for 
/sys/debug/resume, so are you disagreeing we need this support at all or 
that it shouldn't be the generic sysfs write behavior?  If the latter, I 
agree, and the changelog could be improved to specify what writes we 
actually care about.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-31 10:46     ` David Rientjes
@ 2014-01-31 12:24       ` Pavel Machek
  2014-01-31 20:00         ` Sebastian Capella
  0 siblings, 1 reply; 13+ messages in thread
From: Pavel Machek @ 2014-01-31 12:24 UTC (permalink / raw)
  To: David Rientjes
  Cc: Sebastian Capella, linux-kernel, linux-mm, linux-pm,
	linaro-kernel, patches, Andrew Morton, Michel Lespinasse,
	Shaohua Li, Jerome Marchand, Mikulas Patocka, Joonsoo Kim,
	Rafael J. Wysocki

Hi!

On Fri 2014-01-31 02:46:08, David Rientjes wrote:
> On Fri, 31 Jan 2014, Pavel Machek wrote:
> 
> > > kstrimdup will duplicate and trim spaces from the passed in
> > > null terminated string.  This is useful for strings coming from
> > > sysfs that often include trailing whitespace due to user input.
> > 
> > Is it good idea? I mean "\n\n/foo bar baz" is valid filename in
> > unix. This is kernel interface, it is not meant to be too user
> > friendly...
> 
> v6 of this patchset carries your ack of the patch that uses this for 
> /sys/debug/resume, so are you disagreeing we need this support at
> all or 

/sys/power/resume, no?


> that it shouldn't be the generic sysfs write behavior?  If the latter, I 
> agree, and the changelog could be improved to specify what writes we 
> actually care about.

Well, your /sys/power/resume patch would be nice cleanup, but it
changs behaviour, too... which is unnice. Stripping trailing "\n" is
probably neccessary, because we did it before. (It probably was a
mistake). But kernel is not right place to second-guess what the user
meant. Just return -EINVAL. This is kernel ABI, after all, not user
facing shell.

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 1/2] mm: add kstrimdup function
  2014-01-31 12:24       ` Pavel Machek
@ 2014-01-31 20:00         ` Sebastian Capella
  0 siblings, 0 replies; 13+ messages in thread
From: Sebastian Capella @ 2014-01-31 20:00 UTC (permalink / raw)
  To: Pavel Machek, David Rientjes
  Cc: linux-kernel, linux-mm, linux-pm, linaro-kernel, patches,
	Andrew Morton, Michel Lespinasse, Shaohua Li, Jerome Marchand,
	Mikulas Patocka, Joonsoo Kim, Rafael J. Wysocki

Quoting Pavel Machek (2014-01-31 04:24:21)
> Well, your /sys/power/resume patch would be nice cleanup, but it
> changs behaviour, too... which is unnice. Stripping trailing "\n" is
> probably neccessary, because we did it before. (It probably was a
> mistake). But kernel is not right place to second-guess what the user
> meant. Just return -EINVAL. This is kernel ABI, after all, not user
> facing shell.

Thanks guys!  I hadn't thought of these cases.

It sounds like we're really back to stripping one trailing \n to match
the sysfs behavior to which people have become accustomed, and leave
the rest of the string untouched in case the whitespace is intentional.

Should a user intentionally have input ending in a newline, then they
should add an additional newline, expecting it to be stripped, but
otherwise, their string is taken as entered.

Does this sound right?

Meanwhile, I'll try a test to see how name_to_dev_t handles files with
spaces in them.

Thanks,

Sebastian


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-01-31 20:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-29 23:48 [PATCH v4 0/2] PM / Hibernate: sysfs resume Sebastian Capella
2014-01-29 23:48 ` [PATCH v4 1/2] mm: add kstrimdup function Sebastian Capella
2014-01-30  0:58   ` Mikulas Patocka
2014-01-30  1:02     ` Mikulas Patocka
2014-01-30  1:24     ` Joe Perches
2014-01-30  3:41       ` Sebastian Capella
2014-01-30  3:50         ` Joe Perches
2014-01-31 10:32   ` Pavel Machek
2014-01-31 10:46     ` David Rientjes
2014-01-31 12:24       ` Pavel Machek
2014-01-31 20:00         ` Sebastian Capella
2014-01-29 23:48 ` [PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume Sebastian Capella
2014-01-30 18:01   ` Pavel Machek

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).