mtd: lpddr2_nvm: i2c: mux: reg: Fix possible null-ptr-deref

Message ID 20221114020141.28138-1-tanghui20@huawei.com
State New
Headers
Series mtd: lpddr2_nvm: i2c: mux: reg: Fix possible null-ptr-deref |

Commit Message

Hui Tang Nov. 14, 2022, 2:01 a.m. UTC
  It will cause null-ptr-deref when resource_size(add_range) invoked,
if platform_get_resource() returns NULL.

Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
Signed-off-by: Hui Tang <tanghui20@huawei.com>
---
 drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Miquel Raynal Nov. 14, 2022, 8:04 a.m. UTC | #1
Hi Hui,

tanghui20@huawei.com wrote on Mon, 14 Nov 2022 10:01:41 +0800:

> It will cause null-ptr-deref when resource_size(add_range) invoked,
> if platform_get_resource() returns NULL.
> 
> Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
> Signed-off-by: Hui Tang <tanghui20@huawei.com>
> ---
>  drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
> index 367e2d906de0..cf8e86eb4b2c 100644
> --- a/drivers/mtd/lpddr/lpddr2_nvm.c
> +++ b/drivers/mtd/lpddr/lpddr2_nvm.c
> @@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
>  
>  	/* lpddr2_nvm address range */
>  	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (IS_ERR(add_range))

platform_get_resource() just returns NULL upon error.

> +		return -ENODEV;
>  
>  	/* Populate map_info data structure */
>  	*map = (struct map_info) {


Thanks,
Miquèl
  
Hui Tang Nov. 14, 2022, 8:30 a.m. UTC | #2
On 2022/11/14 16:04, Miquel Raynal wrote:
> Hi Hui,
>
> tanghui20@huawei.com wrote on Mon, 14 Nov 2022 10:01:41 +0800:
>
>> It will cause null-ptr-deref when resource_size(add_range) invoked,
>> if platform_get_resource() returns NULL.
>>
>> Fixes: 96ba9dd65788 ("mtd: lpddr: add driver for LPDDR2-NVM PCM memories")
>> Signed-off-by: Hui Tang <tanghui20@huawei.com>
>> ---
>>  drivers/mtd/lpddr/lpddr2_nvm.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
>> index 367e2d906de0..cf8e86eb4b2c 100644
>> --- a/drivers/mtd/lpddr/lpddr2_nvm.c
>> +++ b/drivers/mtd/lpddr/lpddr2_nvm.c
>> @@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
>>
>>  	/* lpddr2_nvm address range */
>>  	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> +	if (IS_ERR(add_range))
>
> platform_get_resource() just returns NULL upon error.

Thanks

>
  

Patch

diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
index 367e2d906de0..cf8e86eb4b2c 100644
--- a/drivers/mtd/lpddr/lpddr2_nvm.c
+++ b/drivers/mtd/lpddr/lpddr2_nvm.c
@@ -433,6 +433,8 @@  static int lpddr2_nvm_probe(struct platform_device *pdev)
 
 	/* lpddr2_nvm address range */
 	add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (IS_ERR(add_range))
+		return -ENODEV;
 
 	/* Populate map_info data structure */
 	*map = (struct map_info) {