Commit 6a365874 authored by Stephen Kitt's avatar Stephen Kitt Committed by Jens Axboe

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: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: default avatarStephen Kitt <steve@sk2.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent a258edbc
...@@ -622,7 +622,7 @@ struct fifo_buffer { ...@@ -622,7 +622,7 @@ struct fifo_buffer {
int total; /* sum of all values */ int total; /* sum of all values */
int values[0]; int values[0];
}; };
extern struct fifo_buffer *fifo_alloc(int fifo_size); extern struct fifo_buffer *fifo_alloc(unsigned int fifo_size);
/* flag bits per connection */ /* flag bits per connection */
enum { enum {
......
...@@ -1575,7 +1575,8 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) ...@@ -1575,7 +1575,8 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
struct drbd_device *device; struct drbd_device *device;
struct disk_conf *new_disk_conf, *old_disk_conf; struct disk_conf *new_disk_conf, *old_disk_conf;
struct fifo_buffer *old_plan = NULL, *new_plan = NULL; struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
int err, fifo_size; int err;
unsigned int fifo_size;
retcode = drbd_adm_prepare(&adm_ctx, skb, info, DRBD_ADM_NEED_MINOR); retcode = drbd_adm_prepare(&adm_ctx, skb, info, DRBD_ADM_NEED_MINOR);
if (!adm_ctx.reply_skb) if (!adm_ctx.reply_skb)
......
...@@ -3887,7 +3887,7 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i ...@@ -3887,7 +3887,7 @@ static int receive_SyncParam(struct drbd_connection *connection, struct packet_i
struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL; struct disk_conf *old_disk_conf = NULL, *new_disk_conf = NULL;
const int apv = connection->agreed_pro_version; const int apv = connection->agreed_pro_version;
struct fifo_buffer *old_plan = NULL, *new_plan = NULL; struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
int fifo_size = 0; unsigned int fifo_size = 0;
int err; int err;
peer_device = conn_peer_device(connection, pi->vnr); peer_device = conn_peer_device(connection, pi->vnr);
......
...@@ -482,11 +482,11 @@ static void fifo_add_val(struct fifo_buffer *fb, int value) ...@@ -482,11 +482,11 @@ static void fifo_add_val(struct fifo_buffer *fb, int value)
fb->values[i] += 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; 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) if (!fb)
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment