summaryrefslogtreecommitdiffstats
path: root/drivers/block/rsxx
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2021-05-13 22:37:30 +0200
committerJens Axboe <axboe@kernel.dk>2021-05-24 14:47:30 +0200
commit8184035805dc87dd826101b930d3dce97758f7b1 (patch)
tree21d91cdd62035c1fb6b81a1d2154c55681691cbc /drivers/block/rsxx
parentblk-mq: Use request queue-wide tags for tagset-wide sbitmap (diff)
downloadlinux-8184035805dc87dd826101b930d3dce97758f7b1.tar.xz
linux-8184035805dc87dd826101b930d3dce97758f7b1.zip
rsxx: Use struct_size() in vmalloc()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/r/20210513203730.GA212128@embeddedor Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/rsxx')
-rw-r--r--drivers/block/rsxx/dma.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/block/rsxx/dma.c b/drivers/block/rsxx/dma.c
index 0574f4495755..ed182f3dd054 100644
--- a/drivers/block/rsxx/dma.c
+++ b/drivers/block/rsxx/dma.c
@@ -74,9 +74,6 @@ struct dma_tracker {
struct rsxx_dma *dma;
};
-#define DMA_TRACKER_LIST_SIZE8 (sizeof(struct dma_tracker_list) + \
- (sizeof(struct dma_tracker) * RSXX_MAX_OUTSTANDING_CMDS))
-
struct dma_tracker_list {
spinlock_t lock;
int head;
@@ -808,7 +805,8 @@ static int rsxx_dma_ctrl_init(struct pci_dev *dev,
memset(&ctrl->stats, 0, sizeof(ctrl->stats));
- ctrl->trackers = vmalloc(DMA_TRACKER_LIST_SIZE8);
+ ctrl->trackers = vmalloc(struct_size(ctrl->trackers, list,
+ RSXX_MAX_OUTSTANDING_CMDS));
if (!ctrl->trackers)
return -ENOMEM;