diff mbox

ASoC: simple-card: Add a NULL pointer check in asoc_simple_card_dai_link_of

Message ID 20150303132900.GA22246@vishal (mailing list archive)
State Accepted
Commit 0004defd4e44d81966b0c4164c2ee01f20ab357b
Headers show

Commit Message

Vishal Thanki March 3, 2015, 1:29 p.m. UTC
Make sure devm_kzalloc() succeeds.

Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
---
 sound/soc/generic/simple-card.c |    5 +++++
 1 file changed, 5 insertions(+)

Comments

Mark Brown March 3, 2015, 2:25 p.m. UTC | #1
On Tue, Mar 03, 2015 at 06:59:00PM +0530, Vishal Thanki wrote:
> Make sure devm_kzalloc() succeeds.

Applied, thanks.
Walter Harms March 4, 2015, 8:29 p.m. UTC | #2
Am 03.03.2015 14:29, schrieb Vishal Thanki:
> Make sure devm_kzalloc() succeeds.
> 
> Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
> ---
>  sound/soc/generic/simple-card.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index f7c6734..fb550b5 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -372,6 +372,11 @@ static int asoc_simple_card_dai_link_of(struct device_node *node,
>  			    strlen(dai_link->cpu_dai_name)   +
>  			    strlen(dai_link->codec_dai_name) + 2,
>  			    GFP_KERNEL);
> +	if (!name) {
> +		ret = -ENOMEM;
> +		goto dai_link_of_err;
> +	}
> +
>  	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
>  				dai_link->codec_dai_name);
>  	dai_link->name = dai_link->stream_name = name;


maybe it is more simple to use kasprintf here ?

just my 2 cents,
wh
Vishal Thanki March 5, 2015, 10:45 a.m. UTC | #3
I am new to kasprintf. I think we need to make sure of freeing memory
allocated using kasprintf.

On Thu, Mar 5, 2015 at 1:59 AM, walter harms <wharms@bfs.de> wrote:

>
>
> Am 03.03.2015 14:29, schrieb Vishal Thanki:
> > Make sure devm_kzalloc() succeeds.
> >
> > Signed-off-by: Vishal Thanki <vishalthanki@gmail.com>
> > ---
> >  sound/soc/generic/simple-card.c |    5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/sound/soc/generic/simple-card.c
> b/sound/soc/generic/simple-card.c
> > index f7c6734..fb550b5 100644
> > --- a/sound/soc/generic/simple-card.c
> > +++ b/sound/soc/generic/simple-card.c
> > @@ -372,6 +372,11 @@ static int asoc_simple_card_dai_link_of(struct
> device_node *node,
> >                           strlen(dai_link->cpu_dai_name)   +
> >                           strlen(dai_link->codec_dai_name) + 2,
> >                           GFP_KERNEL);
> > +     if (!name) {
> > +             ret = -ENOMEM;
> > +             goto dai_link_of_err;
> > +     }
> > +
> >       sprintf(name, "%s-%s", dai_link->cpu_dai_name,
> >                               dai_link->codec_dai_name);
> >       dai_link->name = dai_link->stream_name = name;
>
>
> maybe it is more simple to use kasprintf here ?
>
> just my 2 cents,
> wh
>
>
Lars-Peter Clausen March 5, 2015, 12:03 p.m. UTC | #4
On 03/05/2015 11:45 AM, Vishal Thanki wrote:
> I am new to kasprintf. I think we need to make sure of freeing memory
> allocated using kasprintf.

There is also devm_kasprintf().

But these are really two separate things. One thing is the missing NULL 
check, which is a bug fix and is fixed by your patch. The other thing is the 
conversion to kasprintf() which is a code cleanup and should be done in a 
separate patch.

- Lars
Walter Harms March 5, 2015, 7:35 p.m. UTC | #5
Am 05.03.2015 13:03, schrieb Lars-Peter Clausen:
> On 03/05/2015 11:45 AM, Vishal Thanki wrote:
>> I am new to kasprintf. I think we need to make sure of freeing memory
>> allocated using kasprintf.
> 
> There is also devm_kasprintf().
> 
> But these are really two separate things. One thing is the missing NULL
> check, which is a bug fix and is fixed by your patch. The other thing is
> the conversion to kasprintf() which is a code cleanup and should be done
> in a separate patch.
> 

hi,
thx for the hint:
never read about  devm_kasprintf().

ntl my mail was intended as hint about asprintf() not about the patch.

re,
 wh
diff mbox

Patch

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index f7c6734..fb550b5 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -372,6 +372,11 @@  static int asoc_simple_card_dai_link_of(struct device_node *node,
 			    strlen(dai_link->cpu_dai_name)   +
 			    strlen(dai_link->codec_dai_name) + 2,
 			    GFP_KERNEL);
+	if (!name) {
+		ret = -ENOMEM;
+		goto dai_link_of_err;
+	}
+
 	sprintf(name, "%s-%s", dai_link->cpu_dai_name,
 				dai_link->codec_dai_name);
 	dai_link->name = dai_link->stream_name = name;