All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Girdwood <liam.r.girdwood@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>, "Jin, Yao" <yao.jin@linux.intel.com>
Cc: Vinod Koul <vinod.koul@intel.com>,
	alsa-devel@alsa-project.org, Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH v2 07/13] topology: Add private data parser
Date: Wed, 08 Jul 2015 09:57:32 +0100	[thread overview]
Message-ID: <1436345852.2474.10.camel@loki> (raw)
In-Reply-To: <s5h7fqchrde.wl-tiwai@suse.de>

On Tue, 2015-07-07 at 18:19 +0200, Takashi Iwai wrote:
> On Tue, 07 Jul 2015 17:54:02 +0200,
> Liam Girdwood wrote:
> > 
> > On Wed, 2015-07-01 at 18:20 +0200, Takashi Iwai wrote:
> > 
> > > 
> > > > +static int get_hex_num(const char *str)
> > > > +{
> > > > +	char *tmp, *s = NULL;
> > > > +	int i = 0;
> > > > +
> > > > +	tmp = strdup(str);
> > > > +	if (tmp == NULL)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	s = strtok(tmp, ",");
> > > > +	while (s != NULL) {
> > > > +		s = strtok(NULL, ",");
> > > > +		i++;
> > > > +	}
> > > > +
> > > > +	free(tmp);
> > > > +	return i;
> > > 
> > > Hmm, this just counts the number of comma + 1, so you don't need to
> > > duplicate the string?
> > > 
> > 
> > The string here is duplicated since strtok is destructive (it overwrites
> > the delimiters with NULL) and the string is being used later on by the
> > calling function.
> 
> Yes, but what I meant is something like below:
> 
> static int get_hex_num(const char *str)
> {
> 	int i = 0;
> 
> 	if (!*str)
> 		return 0;
> 	for (;;) {
> 		i++;
> 		str = strchr(str, ',');
> 		if (!str)
> 			return i;
> 		str++;
> 	}
> }
> 
> ... so that it works without strdup().
> 
> But it seems that strtok() skips the starting delimiter or handles
> multiple delimiters as a single, so the result will become
> inconsistent.  That is, all the following strings will give "a" and
> "b" via strtok():
> 	a,b
> 	a,,b
> 	,a,b
> 	a,b,
> 
> I guess you don't want to have an empty list element, right?
> 

Lets ask the author :) but IMO an empty list should be skipped here.

Yao, what's your rational behind this code ?

Liam

  reply	other threads:[~2015-07-08  8:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 13:44 [PATCH v2 01/13] topology: uapi: Add UAPI headers for topology ABI Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 02/13] conf: topology: Add topology file for broadwell audio DSP Liam Girdwood
2015-07-01 15:47   ` Takashi Iwai
2015-07-01 16:16     ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 03/13] topology: Add topology core parser Liam Girdwood
2015-07-01 16:00   ` Takashi Iwai
2015-07-01 13:44 ` [PATCH v2 04/13] topology: Add text section parser Liam Girdwood
2015-07-01 16:03   ` Takashi Iwai
2015-07-01 13:44 ` [PATCH v2 05/13] topology: Add PCM parser Liam Girdwood
2015-07-01 16:14   ` Takashi Iwai
2015-07-01 16:20     ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 06/13] topology: Add operations parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 07/13] topology: Add private data parser Liam Girdwood
2015-07-01 16:20   ` Takashi Iwai
2015-07-07 15:54     ` Liam Girdwood
2015-07-07 16:19       ` Takashi Iwai
2015-07-08  8:57         ` Liam Girdwood [this message]
2015-07-08 13:31           ` Jin, Yao
2015-07-08 14:14             ` Takashi Iwai
2015-07-08 14:21               ` Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 08/13] topology: Add DAPM object parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 09/13] topology: Add CTL parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 10/13] topology: Add Channel map parser Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 11/13] topology: Add binary file builder Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 12/13] topology: autotools: Add build support for topology core Liam Girdwood
2015-07-01 13:44 ` [PATCH v2 13/13] topology: doxygen: Add doxygen " Liam Girdwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436345852.2474.10.camel@loki \
    --to=liam.r.girdwood@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=tiwai@suse.de \
    --cc=vinod.koul@intel.com \
    --cc=yao.jin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.