public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Correct comment on bio_alloc_clone()
@ 2026-02-20 14:32 John Garry
  2026-02-20 15:10 ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2026-02-20 14:32 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, hch, John Garry

Correct the comment that the source bio must not be freed before the clone.

Signed-off-by: John Garry <john.g.garry@oracle.com>

diff --git a/block/bio.c b/block/bio.c
index 8203bb7455a9f..9d9191fe19b50 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -900,7 +900,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
  * Allocate a new bio that is a clone of @bio_src. The caller owns the returned
  * bio, but not the actual data it points to.
  *
- * The caller must ensure that the return bio is not freed before @bio_src.
+ * The caller must ensure that @bio_src is not freed before the returned bio.
  */
 struct bio *bio_alloc_clone(struct block_device *bdev, struct bio *bio_src,
 		gfp_t gfp, struct bio_set *bs)
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Correct comment on bio_alloc_clone()
  2026-02-20 14:32 [PATCH] block: Correct comment on bio_alloc_clone() John Garry
@ 2026-02-20 15:10 ` Christoph Hellwig
  2026-02-20 15:36   ` John Garry
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2026-02-20 15:10 UTC (permalink / raw)
  To: John Garry; +Cc: axboe, linux-block, hch

On Fri, Feb 20, 2026 at 02:32:33PM +0000, John Garry wrote:
> Correct the comment that the source bio must not be freed before the clone.

Note that while this version is better, it's not actually true either.
The bi_io_vec used by the clone must be freed after the clone, but it
might might not be owned by the passed in bio_src.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Correct comment on bio_alloc_clone()
  2026-02-20 15:10 ` Christoph Hellwig
@ 2026-02-20 15:36   ` John Garry
  2026-02-20 15:43     ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2026-02-20 15:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: axboe, linux-block

On 20/02/2026 15:10, Christoph Hellwig wrote:
> On Fri, Feb 20, 2026 at 02:32:33PM +0000, John Garry wrote:
>> Correct the comment that the source bio must not be freed before the clone.
> 
> Note that while this version is better, it's not actually true either.
> The bi_io_vec used by the clone must be freed after the clone, but it
> might might not be owned by the passed in bio_src.
> 

This is the complete function comment today:

  * Allocate a new bio that is a clone of @bio_src. The caller owns the 
returned
  * bio, but not the actual data it points to.
  *
  * The caller must ensure that the return bio is not freed before @bio_src.


So I can have this:

  * Allocate a new bio that is a clone of @bio_src. The caller owns the 
returned
  * bio, but not the actual data it points to, bi_io_vec.
  *
  * The caller must ensure that the returned bio is freed before bi_io_vec.

ok?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Correct comment on bio_alloc_clone()
  2026-02-20 15:36   ` John Garry
@ 2026-02-20 15:43     ` Christoph Hellwig
  2026-02-20 15:55       ` John Garry
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2026-02-20 15:43 UTC (permalink / raw)
  To: John Garry; +Cc: Christoph Hellwig, axboe, linux-block

On Fri, Feb 20, 2026 at 03:36:41PM +0000, John Garry wrote:
>
> So I can have this:
>
>  * Allocate a new bio that is a clone of @bio_src. The caller owns the 
> returned
>  * bio, but not the actual data it points to, bi_io_vec.

Well, bi_io_vec isn't really the data, but the indirection pointing
to the data.  I guess we need to come up with consistent terminology
first before we can make good sense of this.

Allocate a new bio that is a clone of @bio_src. This reuses the bio_vecs
pointed to by @bio_src->bi_io_vec, and clones the iterator pointing to
the current position in it.  The caller owns the  returned bio, but not
the bio_vecs, and must ensure the bio is freed before the memory
pointed to by @bio_Src->bi_io_vecs.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Correct comment on bio_alloc_clone()
  2026-02-20 15:43     ` Christoph Hellwig
@ 2026-02-20 15:55       ` John Garry
  2026-02-20 15:57         ` Christoph Hellwig
  0 siblings, 1 reply; 6+ messages in thread
From: John Garry @ 2026-02-20 15:55 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: axboe, linux-block

On 20/02/2026 15:43, Christoph Hellwig wrote:
> Well, bi_io_vec isn't really the data, but the indirection pointing
> to the data.  I guess we need to come up with consistent terminology
> first before we can make good sense of this.
> 
> Allocate a new bio that is a clone of @bio_src. This reuses the bio_vecs
> pointed to by @bio_src->bi_io_vec, and clones the iterator pointing to
> the current position in it.  The caller owns the  returned bio, but not
> the bio_vecs, and must ensure the bio is freed before the memory
> pointed to by @bio_Src->bi_io_vecs.

ok, fine.

BTW, the comment for bio_init_clone() was much the same as 
bio_alloc_clone(), modulo what I tried to originally remedy. I can just 
mention that that the same bio_src->bi_io_vec lifecycle rules apply 
there (as bio_alloc_clone())

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Correct comment on bio_alloc_clone()
  2026-02-20 15:55       ` John Garry
@ 2026-02-20 15:57         ` Christoph Hellwig
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-02-20 15:57 UTC (permalink / raw)
  To: John Garry; +Cc: Christoph Hellwig, axboe, linux-block

On Fri, Feb 20, 2026 at 03:55:41PM +0000, John Garry wrote:
> BTW, the comment for bio_init_clone() was much the same as 
> bio_alloc_clone(), modulo what I tried to originally remedy. I can just 
> mention that that the same bio_src->bi_io_vec lifecycle rules apply there 
> (as bio_alloc_clone())

Sounds good.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-20 15:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-20 14:32 [PATCH] block: Correct comment on bio_alloc_clone() John Garry
2026-02-20 15:10 ` Christoph Hellwig
2026-02-20 15:36   ` John Garry
2026-02-20 15:43     ` Christoph Hellwig
2026-02-20 15:55       ` John Garry
2026-02-20 15:57         ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox