* [PATCH] dm-crypt: use struct_size() in kzalloc()
@ 2019-06-12 6:14 Zhengyuan Liu
2019-06-12 6:14 ` [PATCH] dm-log: use struct_size() to calculate the size of struct Zhengyuan Liu
0 siblings, 1 reply; 2+ messages in thread
From: Zhengyuan Liu @ 2019-06-12 6:14 UTC (permalink / raw
To: agk, snitzer; +Cc: dm-devel, Zhengyuan Liu
As Gustavo said in other patches doing the same replace, we can now
use the new struct_size() helper to avoid leaving these open-coded and
prone to type mistake.
Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn>
---
drivers/md/dm-crypt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 1b16d34..2587e94 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;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] dm-log: use struct_size() to calculate the size of struct
2019-06-12 6:14 [PATCH] dm-crypt: use struct_size() in kzalloc() Zhengyuan Liu
@ 2019-06-12 6:14 ` Zhengyuan Liu
0 siblings, 0 replies; 2+ messages in thread
From: Zhengyuan Liu @ 2019-06-12 6:14 UTC (permalink / raw
To: agk, snitzer; +Cc: dm-devel, Zhengyuan Liu
As Gustavo said in other patches doing the same replace, we can now
use the new struct_size() helper to avoid leaving these open-coded and
prone to type mistake.
Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn>
---
drivers/md/dm-log-writes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index 9ea2b02..cda6363 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -680,7 +680,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
if (discard_bio)
alloc_size = sizeof(struct pending_block);
else
- alloc_size = sizeof(struct pending_block) + sizeof(struct bio_vec) * bio_segments(bio);
+ alloc_size = struct_size(block, vecs, bio_segments(bio));
block = kzalloc(alloc_size, GFP_NOIO);
if (!block) {
--
2.7.4
.
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-12 6:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-12 6:14 [PATCH] dm-crypt: use struct_size() in kzalloc() Zhengyuan Liu
2019-06-12 6:14 ` [PATCH] dm-log: use struct_size() to calculate the size of struct Zhengyuan Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.