All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: alsa-devel@alsa-project.org, broonie@kernel.org,
	lgirdwood@gmail.com, arthur.she@linaro.org
Subject: Re: [alsa-devel] [PATCH] ASoC: dmaengine: Make the pcm->name equal to pcm->id if the name is not set
Date: Tue, 10 Sep 2019 16:46:04 +0200	[thread overview]
Message-ID: <s5htv9k6wgj.wl-tiwai@suse.de> (raw)
In-Reply-To: <f3ec79a0-e204-c5df-9fc4-e5d0465f678f@ti.com>

On Tue, 10 Sep 2019 16:23:59 +0200,
Peter Ujfalusi wrote:
> 
> 
> 
> On 10/09/2019 15.07, Takashi Iwai wrote:
> > On Fri, 06 Sep 2019 07:55:24 +0200,
> > Peter Ujfalusi wrote:
> >>
> >> Some tools use the snd_pcm_info_get_name() to try to identify PCMs or for
> >> other purposes.
> >>
> >> Currently it is left empty with the dmaengine-pcm, in this case copy the
> >> pcm->id string as pcm->name.
> >>
> >> For example IGT is using this to find the HDMI PCM for testing audio on it.
> >>
> >> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
> >> Reported-by: Arthur She <arthur.she@linaro.org>
> >> ---
> >> Hi,
> >>
> >> this was actually reported for 4.14 kernel with omap-pcm (replaced by sdma-pcm
> >> in v4.18), since then we only use the generic dmaengine PCM but the same issue
> >> applies today.
> >>
> >> Regards,
> >> Peter
> >>
> >>  sound/soc/soc-generic-dmaengine-pcm.c | 6 ++++++
> >>  1 file changed, 6 insertions(+)
> >>
> >> diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
> >> index 748f5f641002..d93db2c2b527 100644
> >> --- a/sound/soc/soc-generic-dmaengine-pcm.c
> >> +++ b/sound/soc/soc-generic-dmaengine-pcm.c
> >> @@ -306,6 +306,12 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
> >>  
> >>  		if (!dmaengine_pcm_can_report_residue(dev, pcm->chan[i]))
> >>  			pcm->flags |= SND_DMAENGINE_PCM_FLAG_NO_RESIDUE;
> >> +
> >> +		if (rtd->pcm->streams[i].pcm->name[0] == '\0') {
> >> +			strncpy(rtd->pcm->streams[i].pcm->name,
> >> +				rtd->pcm->streams[i].pcm->id,
> >> +				sizeof(rtd->pcm->streams[i].pcm->name));
> >> +		}
> > 
> > Any reason to use strncpy() instead of strscpy()?
> > After merging Mark's branch, I got a compile warning like:
> >   sound/soc/soc-generic-dmaengine-pcm.c:311:4: warning: 'strncpy'
> >   accessing 80 bytes at offsets 88 and 24 may overlap up to 0 bytes at
> >   offset [9223372036854775807, -9223372036854775808] [-Wrestrict]
> 
> I have not seen such a warning.
> 'may overlap up to 0 bytes' ?
> snd_pcm_info {
> ...
>         unsigned char id[64];           /* ID (user selectable) */
>         unsigned char name[80];         /* name of this device */
>         unsigned char subname[32];      /* subdevice name */
> ...
> };
> 
> and strncpy() supposed to be something like this:
> char * strncpy(char *dest, const char *src, size_t n)
> {
> 	size_t i;
> 
> 	for (i = 0; i < n && src[i] != '\0'; i++)
> 		dest[i] = src[i];
> 	for ( ; i < n; i++)
> 		dest[i] = '\0';
> 
> 	return dest;
> }
> 
> I can see if I can get my compilers to show the warning and try
> strscpy() if it helps on it.

strncpy() doesn't guarantee the string termination if you pass the
exact buffer size.  Better to use strscpy() in such a case.


thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2019-09-10 14:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06  5:55 [alsa-devel] [PATCH] ASoC: dmaengine: Make the pcm->name equal to pcm->id if the name is not set Peter Ujfalusi
2019-09-09 10:07 ` [alsa-devel] Applied "ASoC: dmaengine: Make the pcm->name equal to pcm->id if the name is not set" to the asoc tree Mark Brown
2019-09-10 12:07 ` [alsa-devel] [PATCH] ASoC: dmaengine: Make the pcm->name equal to pcm->id if the name is not set Takashi Iwai
2019-09-10 14:23   ` Peter Ujfalusi
2019-09-10 14:46     ` Takashi Iwai [this message]
2019-09-10 14:50       ` Takashi Iwai
2019-09-11  7:22   ` Peter Ujfalusi
2019-09-11  7:46     ` Takashi Iwai

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=s5htv9k6wgj.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=arthur.she@linaro.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=peter.ujfalusi@ti.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.