diff mbox series

block/bio-integrity: use struct_size() in kmalloc()

Message ID 1557910339-2140-1-git-send-email-liuyun01@kylinos.cn (mailing list archive)
State New, archived
Headers show
Series block/bio-integrity: use struct_size() in kmalloc() | expand

Commit Message

Jackie Liu May 15, 2019, 8:52 a.m. UTC
Use the new struct_size() helper to keep code simple.

Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 block/bio-integrity.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Chaitanya Kulkarni May 15, 2019, 3:50 p.m. UTC | #1
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

On 05/15/2019 02:04 AM, Jackie Liu wrote:
> Use the new struct_size() helper to keep code simple.
>
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
>   block/bio-integrity.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/block/bio-integrity.c b/block/bio-integrity.c
> index 1b633a3526d4..5152009b5b59 100644
> --- a/block/bio-integrity.c
> +++ b/block/bio-integrity.c
> @@ -57,8 +57,7 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
>   	unsigned inline_vecs;
>
>   	if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) {
> -		bip = kmalloc(sizeof(struct bio_integrity_payload) +
> -			      sizeof(struct bio_vec) * nr_vecs, gfp_mask);
> +		bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask);
>   		inline_vecs = nr_vecs;
>   	} else {
>   		bip = mempool_alloc(&bs->bio_integrity_pool, gfp_mask);
>
Jens Axboe May 16, 2019, 2:49 p.m. UTC | #2
On 5/15/19 2:52 AM, Jackie Liu wrote:
> Use the new struct_size() helper to keep code simple.

Applied, thanks.
diff mbox series

Patch

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 1b633a3526d4..5152009b5b59 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -57,8 +57,7 @@  struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
 	unsigned inline_vecs;
 
 	if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) {
-		bip = kmalloc(sizeof(struct bio_integrity_payload) +
-			      sizeof(struct bio_vec) * nr_vecs, gfp_mask);
+		bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask);
 		inline_vecs = nr_vecs;
 	} else {
 		bip = mempool_alloc(&bs->bio_integrity_pool, gfp_mask);