* [PATCH] block; release bip in a right way in error path
@ 2020-06-23 14:06 Chengguang Xu
2020-06-24 6:50 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Chengguang Xu @ 2020-06-23 14:06 UTC (permalink / raw)
To: axboe; +Cc: linux-block, Chengguang Xu
Release bip using kfree() in error path when that was allocated
by kmalloc().
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
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);
}
EXPORT_SYMBOL(bio_integrity_alloc);
--
2.17.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block; release bip in a right way in error path
2020-06-23 14:06 [PATCH] block; release bip in a right way in error path Chengguang Xu
@ 2020-06-24 6:50 ` Christoph Hellwig
2020-06-24 8:01 ` cgxu
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2020-06-24 6:50 UTC (permalink / raw)
To: Chengguang Xu; +Cc: axboe, linux-block
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@mykernel.net>
> ---
> 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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block; release bip in a right way in error path
2020-06-24 6:50 ` Christoph Hellwig
@ 2020-06-24 8:01 ` cgxu
0 siblings, 0 replies; 3+ messages in thread
From: cgxu @ 2020-06-24 8:01 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: axboe, linux-block
On 6/24/20 2:50 PM, Christoph Hellwig wrote:
> 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@mykernel.net>
>> ---
>> 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?
>
Yeah, that's better, thanks for the suggestion.
cgxu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-24 8:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 14:06 [PATCH] block; release bip in a right way in error path Chengguang Xu
2020-06-24 6:50 ` Christoph Hellwig
2020-06-24 8:01 ` cgxu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).