All of lore.kernel.org
 help / color / mirror / Atom feed
* + parse_integer-convert-sound.patch added to -mm tree
@ 2015-07-20 22:21 akpm
       [not found] ` <s5hlhe6vyq2.wl-tiwai@suse.de>
  0 siblings, 1 reply; 6+ messages in thread
From: akpm @ 2015-07-20 22:21 UTC (permalink / raw)
  To: adobriyan, tiwai, mm-commits


The patch titled
     Subject: parse_integer: convert sound/
has been added to the -mm tree.  Its filename is
     parse_integer-convert-sound.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/parse_integer-convert-sound.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/parse_integer-convert-sound.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: Alexey Dobriyan <adobriyan@gmail.com>
Subject: parse_integer: convert sound/

Convert sound/ directory from deprecated simple_strto*()
to parse_integer()/kstrto*() functions.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 sound/core/oss/mixer_oss.c  |    2 +-
 sound/core/oss/pcm_oss.c    |    4 ++--
 sound/core/pcm.c            |    2 +-
 sound/core/pcm_memory.c     |    3 ++-
 sound/pci/ac97/ac97_codec.c |    8 ++++++--
 sound/soc/soc-core.c        |    9 ++++++---
 6 files changed, 18 insertions(+), 10 deletions(-)

diff -puN sound/core/oss/mixer_oss.c~parse_integer-convert-sound sound/core/oss/mixer_oss.c
--- a/sound/core/oss/mixer_oss.c~parse_integer-convert-sound
+++ a/sound/core/oss/mixer_oss.c
@@ -1200,7 +1200,7 @@ static void snd_mixer_oss_proc_write(str
 			continue;
 		}
 		snd_info_get_str(idxstr, cptr, sizeof(idxstr));
-		idx = simple_strtoul(idxstr, NULL, 10);
+		parse_integer(idxstr, 10, (unsigned int *)&idx);
 		if (idx >= 0x4000) { /* too big */
 			pr_err("ALSA: mixer_oss: invalid index %d\n", idx);
 			continue;
diff -puN sound/core/oss/pcm_oss.c~parse_integer-convert-sound sound/core/oss/pcm_oss.c
--- a/sound/core/oss/pcm_oss.c~parse_integer-convert-sound
+++ a/sound/core/oss/pcm_oss.c
@@ -2892,9 +2892,9 @@ static void snd_pcm_oss_proc_write(struc
 			}
 		}
 		ptr = snd_info_get_str(str, ptr, sizeof(str));
-		template.periods = simple_strtoul(str, NULL, 10);
+		parse_integer(str, 10, &template.periods);
 		ptr = snd_info_get_str(str, ptr, sizeof(str));
-		template.period_size = simple_strtoul(str, NULL, 10);
+		parse_integer(str, 10, &template.period_size);
 		for (idx1 = 31; idx1 >= 0; idx1--)
 			if (template.period_size & (1 << idx1))
 				break;
diff -puN sound/core/pcm.c~parse_integer-convert-sound sound/core/pcm.c
--- a/sound/core/pcm.c~parse_integer-convert-sound
+++ a/sound/core/pcm.c
@@ -507,7 +507,7 @@ static void snd_pcm_xrun_debug_write(str
 	struct snd_pcm_str *pstr = entry->private_data;
 	char line[64];
 	if (!snd_info_get_line(buffer, line, sizeof(line)))
-		pstr->xrun_debug = simple_strtoul(line, NULL, 10);
+		parse_integer(line, 10, &pstr->xrun_debug);
 }
 #endif
 
diff -puN sound/core/pcm_memory.c~parse_integer-convert-sound sound/core/pcm_memory.c
--- a/sound/core/pcm_memory.c~parse_integer-convert-sound
+++ a/sound/core/pcm_memory.c
@@ -167,7 +167,8 @@ static void snd_pcm_lib_preallocate_proc
 	}
 	if (!snd_info_get_line(buffer, line, sizeof(line))) {
 		snd_info_get_str(str, line, sizeof(str));
-		size = simple_strtoul(str, NULL, 10) * 1024;
+		parse_integer(str, 10, &size);
+		size *= 1024;
 		if ((size != 0 && size < 8192) || size > substream->dma_max) {
 			buffer->error = -EINVAL;
 			return;
diff -puN sound/pci/ac97/ac97_codec.c~parse_integer-convert-sound sound/pci/ac97/ac97_codec.c
--- a/sound/pci/ac97/ac97_codec.c~parse_integer-convert-sound
+++ a/sound/pci/ac97/ac97_codec.c
@@ -2884,8 +2884,12 @@ static int apply_quirk_str(struct snd_ac
 			return apply_quirk(ac97, i);
 	}
 	/* for compatibility, accept the numbers, too */
-	if (*typestr >= '0' && *typestr <= '9')
-		return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
+	if (*typestr >= '0' && *typestr <= '9') {
+		int type;
+
+		parse_integer(typestr, 10, &type);
+		return apply_quirk(ac97, type);
+	}
 	return -EINVAL;
 }
 
diff -puN sound/soc/soc-core.c~parse_integer-convert-sound sound/soc/soc-core.c
--- a/sound/soc/soc-core.c~parse_integer-convert-sound
+++ a/sound/soc/soc-core.c
@@ -250,7 +250,7 @@ static ssize_t codec_reg_write_file(stru
 	char buf[32];
 	size_t buf_size;
 	char *start = buf;
-	unsigned long reg, value;
+	unsigned int reg, value;
 	struct snd_soc_codec *codec = file->private_data;
 	int ret;
 
@@ -261,10 +261,13 @@ static ssize_t codec_reg_write_file(stru
 
 	while (*start == ' ')
 		start++;
-	reg = simple_strtoul(start, &start, 16);
+	ret = parse_integer(start, 16, &reg);
+	if (ret < 0)
+		return ret;
+	start += ret;
 	while (*start == ' ')
 		start++;
-	ret = kstrtoul(start, 16, &value);
+	ret = kstrtouint(start, 16, &value);
 	if (ret)
 		return ret;
 
_

Patches currently in -mm which might be from adobriyan@gmail.com are

kstrto-accept-0-for-signed-conversion.patch
add-parse_integer-replacement-for-simple_strto.patch
parse_integer-add-runtime-testsuite.patch
parse-integer-rewrite-kstrto.patch
parse_integer-convert-scanf.patch
scanf-fix-type-range-overflow.patch
parse_integer-convert-lib.patch
parse_integer-convert-mm.patch
parse_integer-convert-mm-fix.patch
parse_integer-convert-fs.patch
parse_integer-convert-fs-cachefiles.patch
parse_integer-convert-ext2-ext3-ext4.patch
parse_integer-convert-fs-ocfs2.patch
parse_integer-convert-fs-9p.patch
parse_integer-convert-fs-exofs.patch
parse_integer-convert-sound.patch
parse_integer-add-checkpatchpl-notice.patch


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

* [PATCH -mm v2] sound: convert to parse_integer()
       [not found] ` <s5hlhe6vyq2.wl-tiwai@suse.de>
@ 2015-07-27 21:03   ` Alexey Dobriyan
  2015-07-28 21:06     ` Andrew Morton
  2015-07-29  6:55     ` Takashi Iwai
  2015-07-27 21:07   ` + parse_integer-convert-sound.patch added to -mm tree Alexey Dobriyan
  1 sibling, 2 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2015-07-27 21:03 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: akpm, linux-kernel

Convert away from deprecated simple_strto*() interfaces to
parse_integer() and kstrto*().

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 sound/core/oss/mixer_oss.c  |    7 ++++---
 sound/core/oss/pcm_oss.c    |   13 +++++++++++--
 sound/core/pcm.c            |   13 +++++++++++--
 sound/core/pcm_memory.c     |   11 +++++++++--
 sound/pci/ac97/ac97_codec.c |    9 ++++++---
 sound/soc/soc-core.c        |    9 ++++++---
 6 files changed, 47 insertions(+), 15 deletions(-)

--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1180,6 +1180,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
 	int ch, idx;
 	struct snd_mixer_oss_assign_table *tbl;
 	struct slot *slot;
+	int rv;
 
 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
 		cptr = snd_info_get_str(str, line, sizeof(str));
@@ -1200,9 +1201,9 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
 			continue;
 		}
 		snd_info_get_str(idxstr, cptr, sizeof(idxstr));
-		idx = simple_strtoul(idxstr, NULL, 10);
-		if (idx >= 0x4000) { /* too big */
-			pr_err("ALSA: mixer_oss: invalid index %d\n", idx);
+		rv = parse_integer(idxstr, 10, (unsigned int *)&idx);
+		if (rv < 0 || idxstr[rv] || idx >= 0x4000) { /* too big */
+			pr_err("ALSA: mixer_oss: invalid index %s\n", idxstr);
 			continue;
 		}
 		mutex_lock(&mixer->reg_mutex);
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -2875,6 +2875,7 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
 	const char *ptr;
 	int idx1;
 	struct snd_pcm_oss_setup *setup, *setup1, template;
+	int rv;
 
 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
 		mutex_lock(&pstr->oss.setup_mutex);
@@ -2892,9 +2893,17 @@ static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
 			}
 		}
 		ptr = snd_info_get_str(str, ptr, sizeof(str));
-		template.periods = simple_strtoul(str, NULL, 10);
+		rv = parse_integer(str, 10, &template.periods);
+		if (rv < 0 || str[rv]) {
+			mutex_unlock(&pstr->oss.setup_mutex);
+			continue;
+		}
 		ptr = snd_info_get_str(str, ptr, sizeof(str));
-		template.period_size = simple_strtoul(str, NULL, 10);
+		rv = parse_integer(str, 10, &template.period_size);
+		if (rv < 0 || str[rv]) {
+			mutex_unlock(&pstr->oss.setup_mutex);
+			continue;
+		}
 		for (idx1 = 31; idx1 >= 0; idx1--)
 			if (template.period_size & (1 << idx1))
 				break;
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -506,8 +506,17 @@ static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry,
 {
 	struct snd_pcm_str *pstr = entry->private_data;
 	char line[64];
-	if (!snd_info_get_line(buffer, line, sizeof(line)))
-		pstr->xrun_debug = simple_strtoul(line, NULL, 10);
+	int rv;
+
+	if (!snd_info_get_line(buffer, line, sizeof(line))) {
+		rv = parse_integer(line, 10, &pstr->xrun_debug);
+		if (rv >= 0 && line[rv])
+			rv = -EINVAL;
+		if (rv < 0) {
+			buffer->error = rv;
+			return;
+		}
+	}
 }
 #endif
 
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -160,6 +160,7 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
 	char line[64], str[64];
 	size_t size;
 	struct snd_dma_buffer new_dmab;
+	int rv;
 
 	if (substream->runtime) {
 		buffer->error = -EBUSY;
@@ -167,8 +168,14 @@ static void snd_pcm_lib_preallocate_proc_write(struct snd_info_entry *entry,
 	}
 	if (!snd_info_get_line(buffer, line, sizeof(line))) {
 		snd_info_get_str(str, line, sizeof(str));
-		size = simple_strtoul(str, NULL, 10) * 1024;
-		if ((size != 0 && size < 8192) || size > substream->dma_max) {
+		rv = parse_integer(str, 10, &size);
+		if (rv < 0) {
+			buffer->error = rv;
+			return;
+		}
+		size *= 1024;
+		if (str[rv] ||
+		    (size != 0 && size < 8192) || size > substream->dma_max) {
 			buffer->error = -EINVAL;
 			return;
 		}
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -2877,6 +2877,8 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
 {
 	int i;
 	struct quirk_table *q;
+	unsigned int type;
+	int rv;
 
 	for (i = 0; i < ARRAY_SIZE(applicable_quirks); i++) {
 		q = &applicable_quirks[i];
@@ -2884,9 +2886,10 @@ static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
 			return apply_quirk(ac97, i);
 	}
 	/* for compatibility, accept the numbers, too */
-	if (*typestr >= '0' && *typestr <= '9')
-		return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
-	return -EINVAL;
+	rv = parse_integer(typestr, 10, &type);
+	if (rv < 0)
+		return rv;
+	return apply_quirk(ac97, type);
 }
 
 /**
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -250,7 +250,7 @@ static ssize_t codec_reg_write_file(struct file *file,
 	char buf[32];
 	size_t buf_size;
 	char *start = buf;
-	unsigned long reg, value;
+	unsigned int reg, value;
 	struct snd_soc_codec *codec = file->private_data;
 	int ret;
 
@@ -261,10 +261,13 @@ static ssize_t codec_reg_write_file(struct file *file,
 
 	while (*start == ' ')
 		start++;
-	reg = simple_strtoul(start, &start, 16);
+	ret = parse_integer(start, 16, &reg);
+	if (ret < 0)
+		return ret;
+	start += ret;
 	while (*start == ' ')
 		start++;
-	ret = kstrtoul(start, 16, &value);
+	ret = kstrtouint(start, 16, &value);
 	if (ret)
 		return ret;
 

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

* Re: + parse_integer-convert-sound.patch added to -mm tree
       [not found] ` <s5hlhe6vyq2.wl-tiwai@suse.de>
  2015-07-27 21:03   ` [PATCH -mm v2] sound: convert to parse_integer() Alexey Dobriyan
@ 2015-07-27 21:07   ` Alexey Dobriyan
  1 sibling, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2015-07-27 21:07 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: akpm, linux-kernel

On Fri, Jul 24, 2015 at 08:47:17AM +0200, Takashi Iwai wrote:
> BTW, we may add __deprecated flag to simple_*() to let developers to
> fix the callers.  By replacing with parse_integer(), however, this
> won't work.

I have some more patches pending and there are still ~650 users.
Probably too early to formally deprecate.

	Alexey

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

* Re: [PATCH -mm v2] sound: convert to parse_integer()
  2015-07-27 21:03   ` [PATCH -mm v2] sound: convert to parse_integer() Alexey Dobriyan
@ 2015-07-28 21:06     ` Andrew Morton
  2015-07-29  6:49       ` Takashi Iwai
  2015-07-29  6:55     ` Takashi Iwai
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2015-07-28 21:06 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Takashi Iwai, linux-kernel

On Tue, 28 Jul 2015 00:03:01 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:

> Convert away from deprecated simple_strto*() interfaces to
> parse_integer() and kstrto*().

The patch does a lot more than this!  It also adds lots of handling of
previously-ignored errors.

And it thereby introduces possible back-compatibility issues.  Someone
who is doing "echo 42foo > wherever" will now get an error, whereas
they previously got 42.

So hm.  Probably a good patch and I'll stick it in -mm for testing, but
this should go upstream via tiwai, please.


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

* Re: [PATCH -mm v2] sound: convert to parse_integer()
  2015-07-28 21:06     ` Andrew Morton
@ 2015-07-29  6:49       ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-07-29  6:49 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alexey Dobriyan, linux-kernel

On Tue, 28 Jul 2015 23:06:15 +0200,
Andrew Morton wrote:
> 
> On Tue, 28 Jul 2015 00:03:01 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > Convert away from deprecated simple_strto*() interfaces to
> > parse_integer() and kstrto*().
> 
> The patch does a lot more than this!  It also adds lots of handling of
> previously-ignored errors.

Yes, please give more description.

> And it thereby introduces possible back-compatibility issues.  Someone
> who is doing "echo 42foo > wherever" will now get an error, whereas
> they previously got 42.

Right, many strings don't care about spaces, i.e. it contains trailing
spaces, so the patch seems doing way too strict.  I think it's better
to omit the word termination check in each place.

> So hm.  Probably a good patch and I'll stick it in -mm for testing, but
> this should go upstream via tiwai, please.

Well, but parse_integer() isn't upstreamed yet, so it has to be after
mm tree, right?


thanks,

Takashi

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

* Re: [PATCH -mm v2] sound: convert to parse_integer()
  2015-07-27 21:03   ` [PATCH -mm v2] sound: convert to parse_integer() Alexey Dobriyan
  2015-07-28 21:06     ` Andrew Morton
@ 2015-07-29  6:55     ` Takashi Iwai
  1 sibling, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2015-07-29  6:55 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel

On Mon, 27 Jul 2015 23:03:01 +0200,
Alexey Dobriyan wrote:
> 
> Convert away from deprecated simple_strto*() interfaces to
> parse_integer() and kstrto*().
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>

The error handling looks good to me.  In addition to Andrew's
suggestion and the removal of word termination check, some nitpicking
below:

> --- a/sound/core/oss/mixer_oss.c
> +++ b/sound/core/oss/mixer_oss.c
> @@ -1180,6 +1180,7 @@ static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
>  	int ch, idx;
>  	struct snd_mixer_oss_assign_table *tbl;
>  	struct slot *slot;
> +	int rv;

A more common variable name is err or ret for such a purpose.

> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -250,7 +250,7 @@ static ssize_t codec_reg_write_file(struct file *file,
>  	char buf[32];
>  	size_t buf_size;
>  	char *start = buf;
> -	unsigned long reg, value;
> +	unsigned int reg, value;
>  	struct snd_soc_codec *codec = file->private_data;
>  	int ret;
>  
> @@ -261,10 +261,13 @@ static ssize_t codec_reg_write_file(struct file *file,
>  
>  	while (*start == ' ')
>  		start++;
> -	reg = simple_strtoul(start, &start, 16);
> +	ret = parse_integer(start, 16, &reg);
> +	if (ret < 0)
> +		return ret;
> +	start += ret;
>  	while (*start == ' ')
>  		start++;
> -	ret = kstrtoul(start, 16, &value);
> +	ret = kstrtouint(start, 16, &value);
>  	if (ret)
>  		return ret;

This looks inconsistent, the first one uses parse_integer() while the
second kstrtouint().  Better to stick with one API.


thanks,

Takashi

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

end of thread, other threads:[~2015-07-29  6:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-20 22:21 + parse_integer-convert-sound.patch added to -mm tree akpm
     [not found] ` <s5hlhe6vyq2.wl-tiwai@suse.de>
2015-07-27 21:03   ` [PATCH -mm v2] sound: convert to parse_integer() Alexey Dobriyan
2015-07-28 21:06     ` Andrew Morton
2015-07-29  6:49       ` Takashi Iwai
2015-07-29  6:55     ` Takashi Iwai
2015-07-27 21:07   ` + parse_integer-convert-sound.patch added to -mm tree Alexey Dobriyan

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.