diff options
author | Stephen Kitt <steve@sk2.org> | 2020-01-24 21:03:07 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-01-30 05:03:33 +0100 |
commit | 6a365874a43c43b227492266f59cd68ecc5a6f83 (patch) | |
tree | 6c1e771042b2d7bbcbb08c61a0baef104ddf8b35 /drivers/block/drbd/drbd_worker.c | |
parent | MAINTAINERS: Add Revanth Rajashekar as a SED-Opal maintainer (diff) | |
download | linux-6a365874a43c43b227492266f59cd68ecc5a6f83.tar.xz linux-6a365874a43c43b227492266f59cd68ecc5a6f83.zip |
drbd: fifo_alloc() should use struct_size
Switching to struct_size for the allocation in fifo_alloc avoids
hard-coding the type of fifo_buffer.values in fifo_alloc. It also
provides overflow protection; to avoid pessimistic code being
generated by the compiler as a result, this patch also switches
fifo_size to unsigned, propagating the change as appropriate.
Reviewed-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/drbd/drbd_worker.c')
-rw-r--r-- | drivers/block/drbd/drbd_worker.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c index 5bdcc70ad589..b7f605c6e231 100644 --- a/drivers/block/drbd/drbd_worker.c +++ b/drivers/block/drbd/drbd_worker.c @@ -482,11 +482,11 @@ static void fifo_add_val(struct fifo_buffer *fb, int value) fb->values[i] += value; } -struct fifo_buffer *fifo_alloc(int fifo_size) +struct fifo_buffer *fifo_alloc(unsigned int fifo_size) { struct fifo_buffer *fb; - fb = kzalloc(sizeof(struct fifo_buffer) + sizeof(int) * fifo_size, GFP_NOIO); + fb = kzalloc(struct_size(fb, values, fifo_size), GFP_NOIO); if (!fb) return NULL; |