ioat/dca: Use struct_size() helper
PATCH 1/1 ioat/dca: Use struct_size() helper
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example:
struct ioat_dca_priv {
...
struct ioat_dca_slot req_slots[0];
};Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.
So, replace the following form:
sizeof(*ioatdca) + (sizeof(struct ioat_dca_slot) * slots)
with:
struct_size(ioatdca, req_slots, slots)
This code was detected with the help of Coccinelle.
--- drivers/dma/ioat/dca.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/ioat/dca.c +1 -2
@@ -286,8 +286,7 @@ struct dca_provider *ioat_dca_init(struct pci_dev *pdev, void __iomem *iobase)return NULL ; dca =alloc_dca_provider (&ioat_dca_ops, -sizeof (*ioatdca) - + (sizeof (struct ioat_dca_slot ) * slots)); +struct_size (ioatdca, req_slots, slots));if (!dca)return NULL ;
Signature · 1 line
2.23.0
Quoted 16 lines · Gustavo A. R. Silva
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example:
struct ioat_dca_priv { ... struct ioat_dca_slot req_slots[0]; };Make use of the
struct_size()helper instead of an open-coded version in order to avoid any potential type mistakes.So, replace the following form:
sizeof(*ioatdca)+ (sizeof(struct ioat_dca_slot)* slots)
Quoted 7 lines
with:
struct_size(ioatdca, req_slots, slots)This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>
Quoted 19 lines
--- drivers/dma/ioat/dca.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/dma/ioat/dca.c +1
-2@@ -286,8 +286,7 @@ struct dca_provider *ioat_dca_init(struct pci_dev *pdev, void __iomem *iobase)return NULL ; dca =alloc_dca_provider (&ioat_dca_ops, -sizeof (*ioatdca) - + (sizeof (struct ioat_dca_slot ) * slots)); +struct_size (ioatdca, req_slots, slots));if (!dca)return NULL ;
Vinod Koul
maintainerQuoted 14 lines · Gustavo A. R. Silva
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example:
struct ioat_dca_priv { ... struct ioat_dca_slot req_slots[0]; };Make use of the
struct_size()helper instead of an open-coded version in order to avoid any potential type mistakes.So, replace the following form:
Quoted 7 lines
sizeof(*ioatdca)+ (sizeof(struct ioat_dca_slot)* slots)with:
struct_size(ioatdca, req_slots, slots)This code was detected with the help of Coccinelle.
Please do not invent subsystem tags, git log should tell you the convention to be used!
Applied after fixing tags, thanks
Signature · 1 line
~Vinod