ASoC: two trivial fixes
Subsystems (4)
cover ASoC: two trivial fixes
Just two random fixes spotted by Coverity.
Daniel Mack (2):
ASoC: soc-compress: consolidate two identical branches
ASoC: fsl: use strncpy() to prevent copying of over-long names
sound/soc/fsl/fsl_asrc.c | 2 +- sound/soc/fsl/fsl_esai.c | 2 +- sound/soc/soc-compress.c | 11 ++--------- 3 files changed, 4 insertions(+), 11 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 ASoC: soc-compress: consolidate two identical branches
The actions taken in both branches are identical, so we can simplify the code. Spotted by Coverity.
--- sound/soc/soc-compress.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
sound/soc/soc-compress.c +2 -9
@@ -258,10 +258,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)list_for_each_entry (dpcm, &fe->dpcm[stream].be_clients, list_be) dpcm->state =SND_SOC_DPCM_LINK_STATE_FREE ; -if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) -dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_STOP ); -else -dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_STOP ); +dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_STOP ); fe->dpcm[stream].state =SND_SOC_DPCM_STATE_CLOSE ; fe->dpcm[stream].runtime_update =SND_SOC_DPCM_UPDATE_NO ;
@@ -456,11 +453,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,if (ret <0 ) goto out; -if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) -dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_START ); -else -dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_START ); - +dpcm_dapm_stream_event (fe, stream,SND_SOC_DAPM_STREAM_START ); fe->dpcm[stream].state =SND_SOC_DPCM_STATE_PREPARE ; out:
Signature · 1 line
2.1.0
PATCH 2/2 ASoC: fsl: use strncpy() to prevent copying of over-long names
In reply to Daniel MackUse strncpy() instead of strcpy(). That's not a security issue, as the source buffer is taken from DT nodes, but we should still enforce bound checks. Spotted by Coverity.
--- sound/soc/fsl/fsl_asrc.c | 2 +- sound/soc/fsl/fsl_esai.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_asrc.c +1 -1
@@ -792,7 +792,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)return -ENOMEM ; asrc_priv->pdev = pdev; -strcpy (asrc_priv->name, np->name); +strncpy (asrc_priv->name, np->name,sizeof (asrc_priv->name) -1 );/* Get the addresses and IRQ */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
sound/soc/fsl/fsl_esai.c +1 -1
@@ -729,7 +729,7 @@ static int fsl_esai_probe(struct platform_device *pdev)return -ENOMEM ; esai_priv->pdev = pdev; -strcpy (esai_priv->name, np->name); +strncpy (esai_priv->name, np->name,sizeof (esai_priv->name) -1 );if (of_property_read_bool (np,"big-endian" )) fsl_esai_regmap_config.val_format_endian =REGMAP_ENDIAN_BIG ;
Signature · 1 line
2.1.0
Re: [PATCH 2/2] ASoC: fsl: use strncpy() to prevent copying of over-long names
This hardly improves matters. When the source string is larger than the buffer, the destination may not be nul-terminated. Also, strncpy ALWAYS writes the full buffer so it may be wasting cycles when the destination buffer is large.
I'm sure the kernel offers a better alternative. Even "snprintf" is a better alternative.
Mike.
Quoted 29 lines · Daniel Mack
Use
strncpy()instead ofstrcpy(). That's not a security issue, as the source buffer is taken from DT nodes, but we should still enforce bound checks. Spotted by Coverity.Signed-off-by Daniel Mack <[email protected]>--- sound/soc/fsl/fsl_asrc.c | 2 +- sound/soc/fsl/fsl_esai.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)sound/soc/fsl/fsl_asrc.c +1
-1@@ -792,7 +792,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)return -ENOMEM ; asrc_priv->pdev = pdev; -strcpy (asrc_priv->name, np->name); +strncpy (asrc_priv->name, np->name,sizeof (asrc_priv->name) -1 );/* Get the addresses and IRQ */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );sound/soc/fsl/fsl_esai.c +0
-0
sound/soc/fsl/fsl_esai.c static int fsl_esai_probe(struct platform_device *pdev) · line 735
Quoted 8 lines
sound/soc/fsl/fsl_esai.c +1
-1@@ -729,7 +729,7 @@ static int fsl_esai_probe(struct platform_device *pdev)return -ENOMEM ; esai_priv->pdev = pdev; -strcpy (esai_priv->name, np->name); +strncpy (esai_priv->name, np->name,sizeof (esai_priv->name) -1 );if (of_property_read_bool (np,"big-endian" )) fsl_esai_regmap_config.val_format_endian =REGMAP_ENDIAN_BIG ;
Met vriendelijke groet / kind regards,
Mike Looijmans
TOPIC Embedded Systems Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best
Telefoon: (+31) (0) 499 33 69 79
Telefax: (+31) (0) 499 33 69 70
E-mail: [email protected]
Website: www.topic.nl
Please consider the environment before printing this e-mail
Topic zoekt gedreven (embedded) software specialisten!
http://topic.nl/vacatures/topic-zoekt-software-engineers/
_______________________________________________
Alsa-devel mailing list [email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH 2/2] ASoC: fsl: use strncpy() to prevent copying of over-long names
At Mon, 20 Oct 2014 07:55:22 +0200,
Quoted 5 lines · Mike Looijmans
This hardly improves matters. When the source string is larger than the buffer, the destination may not be nul-terminated.
Also, strncpy ALWAYS writes the full buffer so it may be wasting cycles when the destination buffer is large.
Indeed, strncpy() should be avoided.
Quoted 2 lines
I'm sure the kernel offers a better alternative. Even "snprintf" is a better alternative.
strlcpy() is the best choice.
Takashi
Quoted 59 lines
Mike.
Quoted 29 lines · Daniel Mack
Use
strncpy()instead ofstrcpy(). That's not a security issue, as the source buffer is taken from DT nodes, but we should still enforce bound checks. Spotted by Coverity.Signed-off-by Daniel Mack <[email protected]>--- sound/soc/fsl/fsl_asrc.c | 2 +- sound/soc/fsl/fsl_esai.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)sound/soc/fsl/fsl_asrc.c +1
-1@@ -792,7 +792,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)return -ENOMEM ; asrc_priv->pdev = pdev; -strcpy (asrc_priv->name, np->name); +strncpy (asrc_priv->name, np->name,sizeof (asrc_priv->name) -1 );/* Get the addresses and IRQ */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );sound/soc/fsl/fsl_esai.c +0
-0sound/soc/fsl/fsl_esai.c static int fsl_esai_probe(struct platform_device *pdev) · line 735
Quoted 8 lines
sound/soc/fsl/fsl_esai.c +1
-1@@ -729,7 +729,7 @@ static int fsl_esai_probe(struct platform_device *pdev)return -ENOMEM ; esai_priv->pdev = pdev; -strcpy (esai_priv->name, np->name); +strncpy (esai_priv->name, np->name,sizeof (esai_priv->name) -1 );if (of_property_read_bool (np,"big-endian" )) fsl_esai_regmap_config.val_format_endian =REGMAP_ENDIAN_BIG ;Met vriendelijke groet / kind regards,
Mike Looijmans
TOPIC Embedded Systems
Eindhovenseweg 32-C, NL-5683 KH Best
Postbus 440, NL-5680 AK Best
Telefoon: (+31) (0) 499 33 69 79
Telefax: (+31) (0) 499 33 69 70
E-mail: [email protected]
Website: www.topic.nlPlease consider the environment before printing this e-mail
Quoted 7 lines
Topic zoekt gedreven (embedded) software specialisten!
http://topic.nl/vacatures/topic-zoekt-software-engineers/_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerQuoted 1 line · Daniel Mack
Just two random fixes spotted by Coverity.
Applied both. I'd been holding off on these waiting for the developers of the relevant code to review but I now notice that you didn't CC them which is probably why they didn't respond!