mfd: tps6594: Add null pointer check to tps6594_device_init

Message ID 20231205095426.2532572-1-chentao@kylinos.cn
State New
Headers
Series mfd: tps6594: Add null pointer check to tps6594_device_init |

Commit Message

Kunwu Chan Dec. 5, 2023, 9:54 a.m. UTC
  devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 325bec7157b3 ("mfd: tps6594: Add driver for TI TPS6594 PMIC")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/mfd/tps6594-core.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Lee Jones Dec. 7, 2023, 4:10 p.m. UTC | #1
On Tue, 05 Dec 2023, Kunwu Chan wrote:

> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> 
> Fixes: 325bec7157b3 ("mfd: tps6594: Add driver for TI TPS6594 PMIC")
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
>  drivers/mfd/tps6594-core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/mfd/tps6594-core.c b/drivers/mfd/tps6594-core.c
> index 0fb9c5cf213a..6403c1063de9 100644
> --- a/drivers/mfd/tps6594-core.c
> +++ b/drivers/mfd/tps6594-core.c
> @@ -433,6 +433,9 @@ int tps6594_device_init(struct tps6594 *tps, bool enable_crc)
>  	tps6594_irq_chip.name = devm_kasprintf(dev, GFP_KERNEL, "%s-%ld-0x%02x",
>  					       dev->driver->name, tps->chip_id, tps->reg);
>  
> +	if (!tps6594_irq_chip.name)
> +		return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n");
> +

The check is fine, but the use of dev_err_probe() is not.

Simply:

	return -ENOMEM;

>  	ret = devm_regmap_add_irq_chip(dev, tps->regmap, tps->irq, IRQF_SHARED | IRQF_ONESHOT,
>  				       0, &tps6594_irq_chip, &tps->irq_data);
>  	if (ret)
> -- 
> 2.34.1
>
  
Kunwu Chan Dec. 8, 2023, 3:24 a.m. UTC | #2
Thanks for your reply.
I'll update the v2 patch:
1. When 'tps6594_irq_chip.name' is null,just return -ENOMEM.

Thanks again,
Kunwu

On 2023/12/8 00:10, Lee Jones wrote:
> On Tue, 05 Dec 2023, Kunwu Chan wrote:
> 
>> devm_kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure.
>>
>> Fixes: 325bec7157b3 ("mfd: tps6594: Add driver for TI TPS6594 PMIC")
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> ---
>>   drivers/mfd/tps6594-core.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/mfd/tps6594-core.c b/drivers/mfd/tps6594-core.c
>> index 0fb9c5cf213a..6403c1063de9 100644
>> --- a/drivers/mfd/tps6594-core.c
>> +++ b/drivers/mfd/tps6594-core.c
>> @@ -433,6 +433,9 @@ int tps6594_device_init(struct tps6594 *tps, bool enable_crc)
>>   	tps6594_irq_chip.name = devm_kasprintf(dev, GFP_KERNEL, "%s-%ld-0x%02x",
>>   					       dev->driver->name, tps->chip_id, tps->reg);
>>   
>> +	if (!tps6594_irq_chip.name)
>> +		return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n");
>> +
> 
> The check is fine, but the use of dev_err_probe() is not.
> 
> Simply:
> 
> 	return -ENOMEM;
> 
>>   	ret = devm_regmap_add_irq_chip(dev, tps->regmap, tps->irq, IRQF_SHARED | IRQF_ONESHOT,
>>   				       0, &tps6594_irq_chip, &tps->irq_data);
>>   	if (ret)
>> -- 
>> 2.34.1
>>
>
  

Patch

diff --git a/drivers/mfd/tps6594-core.c b/drivers/mfd/tps6594-core.c
index 0fb9c5cf213a..6403c1063de9 100644
--- a/drivers/mfd/tps6594-core.c
+++ b/drivers/mfd/tps6594-core.c
@@ -433,6 +433,9 @@  int tps6594_device_init(struct tps6594 *tps, bool enable_crc)
 	tps6594_irq_chip.name = devm_kasprintf(dev, GFP_KERNEL, "%s-%ld-0x%02x",
 					       dev->driver->name, tps->chip_id, tps->reg);
 
+	if (!tps6594_irq_chip.name)
+		return dev_err_probe(dev, -ENOMEM, "Failed to allocate memory\n");
+
 	ret = devm_regmap_add_irq_chip(dev, tps->regmap, tps->irq, IRQF_SHARED | IRQF_ONESHOT,
 				       0, &tps6594_irq_chip, &tps->irq_data);
 	if (ret)