soc/fsl/guts: Add a NULL check for devm_kasprintf()

Message ID 1515244954-8374-1-git-send-email-festevam@gmail.com
State Not Applicable
Headers show
Series
  • soc/fsl/guts: Add a NULL check for devm_kasprintf()
Related show

Commit Message

Fabio Estevam Jan. 6, 2018, 1:22 p.m.
From: Fabio Estevam <fabio.estevam@nxp.com>

devm_kasprintf() may fail, so we should better add a NULL check
and propagate an error on failure.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
 drivers/soc/fsl/guts.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Y.b. Lu Jan. 8, 2018, 3:06 a.m. | #1
> -----Original Message-----

> From: Fabio Estevam [mailto:festevam@gmail.com]

> Sent: 2018年1月6日 21:23

> To: Leo Li <leoyang.li@nxp.com>

> Cc: linuxppc-dev@lists.ozlabs.org; Y.b. Lu <yangbo.lu@nxp.com>; Fabio

> Estevam <fabio.estevam@nxp.com>

> Subject: [PATCH] soc/fsl/guts: Add a NULL check for devm_kasprintf()

> 

> From: Fabio Estevam <fabio.estevam@nxp.com>

> 

> devm_kasprintf() may fail, so we should better add a NULL check and

> propagate an error on failure.

> 

> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>


[Y.b. Lu] It makes sense. 
Acked-by: Yangbo Lu <yangbo.lu@nxp.com>


> ---

>  drivers/soc/fsl/guts.c | 6 ++++++

>  1 file changed, 6 insertions(+)

> 

> diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c index

> d89a6a8..82251b4 100644

> --- a/drivers/soc/fsl/guts.c

> +++ b/drivers/soc/fsl/guts.c

> @@ -167,10 +167,16 @@ static int fsl_guts_probe(struct platform_device

> *pdev)

>  	} else {

>  		soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");

>  	}

> +	if (!soc_dev_attr.family)

> +		return -ENOMEM;

>  	soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,

>  					     "svr:0x%08x", svr);

> +	if (!soc_dev_attr.soc_id)

> +		return -ENOMEM;

>  	soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",

>  					       (svr >>  4) & 0xf, svr & 0xf);

> +	if (!soc_dev_attr.revision)

> +		return -ENOMEM;

> 

>  	soc_dev = soc_device_register(&soc_dev_attr);

>  	if (IS_ERR(soc_dev))

> --

> 2.7.4
Leo Li Jan. 10, 2018, 10:48 p.m. | #2
On Sun, Jan 7, 2018 at 9:06 PM, Y.b. Lu <yangbo.lu@nxp.com> wrote:
>> -----Original Message-----
>> From: Fabio Estevam [mailto:festevam@gmail.com]
>> Sent: 2018年1月6日 21:23
>> To: Leo Li <leoyang.li@nxp.com>
>> Cc: linuxppc-dev@lists.ozlabs.org; Y.b. Lu <yangbo.lu@nxp.com>; Fabio
>> Estevam <fabio.estevam@nxp.com>
>> Subject: [PATCH] soc/fsl/guts: Add a NULL check for devm_kasprintf()
>>
>> From: Fabio Estevam <fabio.estevam@nxp.com>
>>
>> devm_kasprintf() may fail, so we should better add a NULL check and
>> propagate an error on failure.
>>
>> Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
>
> [Y.b. Lu] It makes sense.
> Acked-by: Yangbo Lu <yangbo.lu@nxp.com>

Merged.  Thanks.

>
>> ---
>>  drivers/soc/fsl/guts.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c index
>> d89a6a8..82251b4 100644
>> --- a/drivers/soc/fsl/guts.c
>> +++ b/drivers/soc/fsl/guts.c
>> @@ -167,10 +167,16 @@ static int fsl_guts_probe(struct platform_device
>> *pdev)
>>       } else {
>>               soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
>>       }
>> +     if (!soc_dev_attr.family)
>> +             return -ENOMEM;
>>       soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
>>                                            "svr:0x%08x", svr);
>> +     if (!soc_dev_attr.soc_id)
>> +             return -ENOMEM;
>>       soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
>>                                              (svr >>  4) & 0xf, svr & 0xf);
>> +     if (!soc_dev_attr.revision)
>> +             return -ENOMEM;
>>
>>       soc_dev = soc_device_register(&soc_dev_attr);
>>       if (IS_ERR(soc_dev))
>> --
>> 2.7.4
>

Patch

diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c
index d89a6a8..82251b4 100644
--- a/drivers/soc/fsl/guts.c
+++ b/drivers/soc/fsl/guts.c
@@ -167,10 +167,16 @@  static int fsl_guts_probe(struct platform_device *pdev)
 	} else {
 		soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
 	}
+	if (!soc_dev_attr.family)
+		return -ENOMEM;
 	soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
 					     "svr:0x%08x", svr);
+	if (!soc_dev_attr.soc_id)
+		return -ENOMEM;
 	soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
 					       (svr >>  4) & 0xf, svr & 0xf);
+	if (!soc_dev_attr.revision)
+		return -ENOMEM;
 
 	soc_dev = soc_device_register(&soc_dev_attr);
 	if (IS_ERR(soc_dev))