libnvdimm: Add check for nd_dax_alloc

Message ID 20221122023350.29128-1-jiasheng@iscas.ac.cn
State New
Headers
Series libnvdimm: Add check for nd_dax_alloc |

Commit Message

Jiasheng Jiang Nov. 22, 2022, 2:33 a.m. UTC
  As the nd_dax_alloc may return NULL pointer,
it should be better to add check for the return
value, as same as the one in nd_dax_create().

Fixes: c5ed9268643c ("libnvdimm, dax: autodetect support")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/nvdimm/dax_devs.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Christophe JAILLET Nov. 22, 2022, 6:07 p.m. UTC | #1
Le 22/11/2022 à 03:33, Jiasheng Jiang a écrit :
> As the nd_dax_alloc may return NULL pointer,
> it should be better to add check for the return
> value, as same as the one in nd_dax_create().
> 
> Fixes: c5ed9268643c ("libnvdimm, dax: autodetect support")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>   drivers/nvdimm/dax_devs.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
> index 7f4a9d28b670..9efe62b95dd8 100644
> --- a/drivers/nvdimm/dax_devs.c
> +++ b/drivers/nvdimm/dax_devs.c
> @@ -106,6 +106,8 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
>   
>   	nvdimm_bus_lock(&ndns->dev);
>   	nd_dax = nd_dax_alloc(nd_region);
> +	if (!nd_dax)
> +		return -ENOMEM;
>   	nd_pfn = &nd_dax->nd_pfn;
>   	dax_dev = nd_pfn_devinit(nd_pfn, ndns);
>   	nvdimm_bus_unlock(&ndns->dev);

Hi,

Based on 6.1-rc6 ([1]), the error handling is already in place just 
after the nvdimm_bus_unlock() call.

CJ

[1]: 
https://elixir.bootlin.com/linux/v6.1-rc6/source/drivers/nvdimm/dax_devs.c#L112
  

Patch

diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
index 7f4a9d28b670..9efe62b95dd8 100644
--- a/drivers/nvdimm/dax_devs.c
+++ b/drivers/nvdimm/dax_devs.c
@@ -106,6 +106,8 @@  int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
 
 	nvdimm_bus_lock(&ndns->dev);
 	nd_dax = nd_dax_alloc(nd_region);
+	if (!nd_dax)
+		return -ENOMEM;
 	nd_pfn = &nd_dax->nd_pfn;
 	dax_dev = nd_pfn_devinit(nd_pfn, ndns);
 	nvdimm_bus_unlock(&ndns->dev);