diff mbox series

mtd: powernv_flash: check return value of devm_kasprintf()

Message ID 20231018092728.315071-1-yiyang13@huawei.com
State New
Headers show
Series mtd: powernv_flash: check return value of devm_kasprintf() | expand

Commit Message

Yi Yang Oct. 18, 2023, 9:27 a.m. UTC
The devm_kasprintf() returns a pointer to dynamically allocated memory.
that will return NULL when allocate failed.
Fix it by check return value of devm_kasprintf().

Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/mtd/devices/powernv_flash.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Michael Ellerman Oct. 19, 2023, 1:16 a.m. UTC | #1
Yi Yang <yiyang13@huawei.com> writes:
> The devm_kasprintf() returns a pointer to dynamically allocated memory.
> that will return NULL when allocate failed.
> Fix it by check return value of devm_kasprintf().
>
> Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/mtd/devices/powernv_flash.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
> index 66044f4f5bad..b305e555ddbf 100644
> --- a/drivers/mtd/devices/powernv_flash.c
> +++ b/drivers/mtd/devices/powernv_flash.c
> @@ -207,6 +207,10 @@ static int powernv_flash_set_driver_info(struct device *dev,
>  	 * get them
>  	 */
>  	mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
> +	if (mtd->name) {

That seems like the wrong check?

cheers

> +		dev_err(dev, "failed to allocate mtd->name\n");
> +		return -ENOMEM;
> +	}
>  	mtd->type = MTD_NORFLASH;
>  	mtd->flags = MTD_WRITEABLE;
>  	mtd->size = size;
> -- 
> 2.25.1
Yi Yang Oct. 19, 2023, 1:26 a.m. UTC | #2
On 2023/10/19 9:16, Michael Ellerman wrote:
> Yi Yang <yiyang13@huawei.com> writes:
>> The devm_kasprintf() returns a pointer to dynamically allocated memory.
>> that will return NULL when allocate failed.
>> Fix it by check return value of devm_kasprintf().
>>
>> Fixes: acfe63ec1c59 ("mtd: Convert to using %pOFn instead of device_node.name")
>> Signed-off-by: Yi Yang <yiyang13@huawei.com>
>> ---
>>   drivers/mtd/devices/powernv_flash.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
>> index 66044f4f5bad..b305e555ddbf 100644
>> --- a/drivers/mtd/devices/powernv_flash.c
>> +++ b/drivers/mtd/devices/powernv_flash.c
>> @@ -207,6 +207,10 @@ static int powernv_flash_set_driver_info(struct device *dev,
>>   	 * get them
>>   	 */
>>   	mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
>> +	if (mtd->name) {
> 
> That seems like the wrong check?
> 
> cheers
> 
You're right, I'm fixing this in v2 patch.

Thanks,
Yi Yang

>> +		dev_err(dev, "failed to allocate mtd->name\n");
>> +		return -ENOMEM;
>> +	}
>>   	mtd->type = MTD_NORFLASH;
>>   	mtd->flags = MTD_WRITEABLE;
>>   	mtd->size = size;
>> -- 
>> 2.25.1
> .
>
diff mbox series

Patch

diff --git a/drivers/mtd/devices/powernv_flash.c b/drivers/mtd/devices/powernv_flash.c
index 66044f4f5bad..b305e555ddbf 100644
--- a/drivers/mtd/devices/powernv_flash.c
+++ b/drivers/mtd/devices/powernv_flash.c
@@ -207,6 +207,10 @@  static int powernv_flash_set_driver_info(struct device *dev,
 	 * get them
 	 */
 	mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
+	if (mtd->name) {
+		dev_err(dev, "failed to allocate mtd->name\n");
+		return -ENOMEM;
+	}
 	mtd->type = MTD_NORFLASH;
 	mtd->flags = MTD_WRITEABLE;
 	mtd->size = size;