nvdimm: use struct_size for allocation
PATCH 1/1 nvdimm: use struct_size for allocation
Signed-off-by Rosen Penev <[email protected]>
--- drivers/nvdimm/region_devs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/nvdimm/region_devs.c +3 -4
@@ -104,7 +104,7 @@ static int nd_region_invalidate_memregion(struct nd_region *nd_region)static int get_flush_data (struct nd_region *nd_region,size_t *size,int *num_flush) { -size_t flush_data_size =sizeof (void *); +size_t flush_data_size =0 ;int _num_flush =0 ;int i;
@@ -117,11 +117,10 @@ static int get_flush_data(struct nd_region *nd_region, size_t *size, int *num_flreturn -EBUSY ;/* at least one null hint slot per-dimm for the "no-hint" case */ - flush_data_size +=sizeof (void *); _num_flush =min_not_zero (_num_flush, nvdimm->num_flush);if (!nvdimm->num_flush)continue ; - flush_data_size += nvdimm->num_flush *sizeof (void *); + flush_data_size += nvdimm->num_flush; } *size = flush_data_size;
@@ -145,7 +144,7 @@ int nd_region_activate(struct nd_region *nd_region)if (rc)return rc; - ndrd =devm_kzalloc (dev,sizeof (*ndrd) + flush_data_size,GFP_KERNEL ); + ndrd =devm_kzalloc (dev,struct_size (ndrd, flush_wpq, flush_data_size),GFP_KERNEL );if (!ndrd)return -ENOMEM ;dev_set_drvdata (dev, ndrd);
Signature · 1 line
2.53.0
Alison Schofield
maintainerQuoted 1 line · Rosen Penev
Signed-off-by Rosen Penev <[email protected]>
This is not a mechanical struct_size() conversion. It changes the allocation math for flush_wpq but there is no commit log explanation of why that change is correct or safe. There's no commit log at all.
This code in not just counting bytes. It encodes assumptions about the no-hint case and the per-DIMM indexing model. If you intend to change that, please study those paths and explain why the new math preserves correctness across all topologies.
Quoted 43 lines
--- drivers/nvdimm/region_devs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/nvdimm/region_devs.c +3
-4@@ -104,7 +104,7 @@ static int nd_region_invalidate_memregion(struct nd_region *nd_region)static int get_flush_data (struct nd_region *nd_region,size_t *size,int *num_flush) { -size_t flush_data_size =sizeof (void *); +size_t flush_data_size =0 ;int _num_flush =0 ;int i;@@ -117,11 +117,10 @@ static int get_flush_data(struct nd_region *nd_region, size_t *size, int *num_flreturn -EBUSY ;/* at least one null hint slot per-dimm for the "no-hint" case */ - flush_data_size +=sizeof (void *); _num_flush =min_not_zero (_num_flush, nvdimm->num_flush);if (!nvdimm->num_flush)continue ; - flush_data_size += nvdimm->num_flush *sizeof (void *); + flush_data_size += nvdimm->num_flush; } *size = flush_data_size;@@ -145,7 +144,7 @@ int nd_region_activate(struct nd_region *nd_region)if (rc)return rc; - ndrd =devm_kzalloc (dev,sizeof (*ndrd) + flush_data_size,GFP_KERNEL ); + ndrd =devm_kzalloc (dev,struct_size (ndrd, flush_wpq, flush_data_size),GFP_KERNEL );if (!ndrd)return -ENOMEM ;dev_set_drvdata (dev, ndrd);Signature · 1 line
2.53.0