Re: [PATCH] block; release bip in a right way in error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 23, 2020 at 10:06:53PM +0800, Chengguang Xu wrote:
> Release bip using kfree() in error path when that was allocated
> by kmalloc().
> 
> Signed-off-by: Chengguang Xu <cgxu519@xxxxxxxxxxxx>
> ---
>  block/bio-integrity.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/block/bio-integrity.c b/block/bio-integrity.c
> index 23632a33ed39..538c8dc8840a 100644
> --- a/block/bio-integrity.c
> +++ b/block/bio-integrity.c
> @@ -78,7 +78,11 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
>  
>  	return bip;
>  err:
> -	mempool_free(bip, &bs->bio_integrity_pool);
> +	if (bs && mempool_initialized(&bs->bio_integrity_pool))
> +		mempool_free(bip, &bs->bio_integrity_pool);
> +	else
> +		kfree(bip);
> +
>  	return ERR_PTR(-ENOMEM);

How about factoring out a __bio_integrity_free helper to not duplicate
this logic?



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux