From: Zhengyuan Liu Date: Wed, 12 Jun 2019 06:14:45 +0000 (+0800) Subject: dm crypt: use struct_size() when allocating encryption context X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=9c81c99b242f1241e18573d1ce29f7479c168e38;p=linux.git dm crypt: use struct_size() when allocating encryption context Use struct_size() to avoid open-coded equivalent that is prone to a type mistake. Signed-off-by: Zhengyuan Liu Signed-off-by: Mike Snitzer --- diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 1b16d34bb7851..2587e94b05114 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -2699,7 +2699,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) return -EINVAL; } - cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL); + cc = kzalloc(struct_size(cc, key, key_size), GFP_KERNEL); if (!cc) { ti->error = "Cannot allocate encryption context"; return -ENOMEM;