linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: jack: Check the return value of kstrdup()
@ 2021-12-11 17:13 xkernel
  2021-12-12  5:44 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: xkernel @ 2021-12-11 17:13 UTC (permalink / raw)
  To: perex, tiwai; +Cc: alsa-devel, linux-kernel, xkernel

kstrdup() can return NULL, it is better to check the return value of it.

Signed-off-by: xkernel <xkernel.wang@foxmail.com>
---
 sound/core/jack.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/core/jack.c b/sound/core/jack.c
index 32350c6..5fd9954 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -509,6 +509,8 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 		return -ENOMEM;
 
 	jack->id = kstrdup(id, GFP_KERNEL);
+	if (jack->id == NULL)
+		return -ENOMEM;
 
 	/* don't creat input device for phantom jack */
 	if (!phantom_jack) {
-- 


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

* Re: [PATCH] ALSA: jack: Check the return value of kstrdup()
  2021-12-11 17:13 [PATCH] ALSA: jack: Check the return value of kstrdup() xkernel
@ 2021-12-12  5:44 ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2021-12-12  5:44 UTC (permalink / raw)
  To: xkernel, perex, tiwai; +Cc: alsa-devel, linux-kernel

On Sun, 2021-12-12 at 01:13 +0800, xkernel wrote:
> kstrdup() can return NULL, it is better to check the return value of it.
[]
> diff --git a/sound/core/jack.c b/sound/core/jack.c
[]
> @@ -509,6 +509,8 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>  		return -ENOMEM;
>  
>  	jack->id = kstrdup(id, GFP_KERNEL);
> +	if (jack->id == NULL)
> +		return -ENOMEM;

jack should be freed too.

	if (!jack->id) {
		kfree(jack);
		return -ENOMEM;
	}

>  
>  	/* don't creat input device for phantom jack */
>  	if (!phantom_jack) {



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

* Re: [PATCH] ALSA: jack: Check the return value of kstrdup()
  2021-12-13  7:39 Xiaoke Wang
@ 2021-12-13  9:40 ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-12-13  9:40 UTC (permalink / raw)
  To: Xiaoke Wang; +Cc: joe, perex, tiwai, alsa-devel, linux-kernel

On Mon, 13 Dec 2021 08:39:31 +0100,
Xiaoke Wang wrote:
> 
> kstrdup() can return NULL, it is better to check the return value of it.
> Fix: free jack and use my full name.
> 
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>

Thanks, applied now with Cc-to-stable.

BTW, when you submit a revised patch, please put 'v2' or such to the
patch subject prefix, e.g.
  [PATCH v2] ALSA: jack: ...

Also you can put the note about the changes between revisions as

  v1->v2: Fix something more....

and this could be put after the first '---' line (around the diffstat)
if it's not necessarily to be included in the final commit log.


Takashi

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

* Re: [PATCH] ALSA: jack: Check the return value of kstrdup()
@ 2021-12-13  7:39 Xiaoke Wang
  2021-12-13  9:40 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Xiaoke Wang @ 2021-12-13  7:39 UTC (permalink / raw)
  To: joe, perex, tiwai; +Cc: alsa-devel, linux-kernel, Xiaoke Wang

kstrdup() can return NULL, it is better to check the return value of it.
Fix: free jack and use my full name.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 sound/core/jack.c | 4 ++
 1 file changed, 4 insertions(+)

diff --git a/sound/core/jack.c b/sound/core/jack.c
index 32350c6..5fd9954 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -509,6 +509,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 		return -ENOMEM;
 
 	jack->id = kstrdup(id, GFP_KERNEL);
+	if (jack->id == NULL) {
+		kfree(jack);
+		return -ENOMEM;
+	}
 
 	/* don't creat input device for phantom jack */
 	if (!phantom_jack) {
-- 


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

end of thread, other threads:[~2021-12-13  9:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11 17:13 [PATCH] ALSA: jack: Check the return value of kstrdup() xkernel
2021-12-12  5:44 ` Joe Perches
2021-12-13  7:39 Xiaoke Wang
2021-12-13  9:40 ` Takashi Iwai

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