diff mbox series

[v5,6/8] device-dax: use struct_size()

Message ID 20211112150824.11028-7-joao.m.martins@oracle.com (mailing list archive)
State New
Headers show
Series mm, dax: Introduce compound pages in devmap | expand

Commit Message

Joao Martins Nov. 12, 2021, 3:08 p.m. UTC
Use the struct_size() helper for the size of a struct with variable array
member at the end, rather than manually calculating it.

Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 drivers/dax/device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Nov. 17, 2021, 9:37 a.m. UTC | #1
> +		pgmap = devm_kzalloc(
> +                       dev, struct_size(pgmap, ranges, dev_dax->nr_range - 1),
> +                       GFP_KERNEL);

Keeping the dev argument on the previous line would not only make this
much more readable but also avoid the overly long line.
Joao Martins Nov. 17, 2021, 10:15 a.m. UTC | #2
On 11/17/21 10:37, Christoph Hellwig wrote:
>> +		pgmap = devm_kzalloc(
>> +                       dev, struct_size(pgmap, ranges, dev_dax->nr_range - 1),
>> +                       GFP_KERNEL);
> 
> Keeping the dev argument on the previous line would not only make this
> much more readable but also avoid the overly long line.
> 
Fixed.
diff mbox series

Patch

diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 0b82159b3564..d6796a3115a6 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -404,8 +404,9 @@  int dev_dax_probe(struct dev_dax *dev_dax)
 		return -EINVAL;
 
 	if (!pgmap) {
-		pgmap = devm_kzalloc(dev, sizeof(*pgmap) + sizeof(struct range)
-				* (dev_dax->nr_range - 1), GFP_KERNEL);
+		pgmap = devm_kzalloc(
+                       dev, struct_size(pgmap, ranges, dev_dax->nr_range - 1),
+                       GFP_KERNEL);
 		if (!pgmap)
 			return -ENOMEM;
 		pgmap->nr_range = dev_dax->nr_range;