libnvdimm: fix NULL pointer dereference
PATCH 1/1 libnvdimm: fix NULL pointer dereference
ndd is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after ndd has been properly null checked at line 554: if (!ndd)
Addresses-Coverity-ID: 1472020 ("Dereference before null check")
--- drivers/nvdimm/dimm_devs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvdimm/dimm_devs.c +3 -1
@@ -546,7 +546,7 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region, struct nd_mapping *nd_mapping) {struct nvdimm_drvdata *ndd =to_ndd (nd_mapping); -struct nvdimm_bus *nvdimm_bus =walk_to_nvdimm_bus (ndd->dev); +struct nvdimm_bus *nvdimm_bus;resource_size_t max =0 ;struct resource *res;
@@ -554,6 +554,8 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,if (!ndd)return 0 ; + nvdimm_bus =walk_to_nvdimm_bus (ndd->dev); +if (reserve_free_pmem (nvdimm_bus, nd_mapping))return 0 ;for_each_dpa_resource (ndd, res) {
Signature · 6 lines
2.7.4 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 5 lines · Gustavo A. R. Silva
ndd is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after ndd has been properly null checked at line 554: if (!ndd)
I'll fold this into v4 of the patch since Vishal found an issue when a DIMM has multiple regions.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm