linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kundan Kumar <kundan.kumar@samsung.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Subject: Re: [PATCH 2/2] block: share more code for bio addition helpers
Date: Wed, 6 Nov 2024 15:33:38 +0530	[thread overview]
Message-ID: <20241106100338.35xxy2mcpp4u36xl@green245> (raw)
In-Reply-To: <20241105155235.460088-3-hch@lst.de>

[-- Attachment #1: Type: text/plain, Size: 1826 bytes --]

On 05/11/24 04:52PM, Christoph Hellwig wrote:
>__bio_iov_iter_get_pages currently open codes adding pages to the bio,
>which duplicates a lot of code from bio_add_page.  Add a lower level
>bio_do_add_page helpers that passes down the same_page output argument
>so that __bio_iov_iter_get_pages can reuse the code and also check
>for the error return from it - while no error should happen due to
>how the bvec space is used for the pin_user_space result I'd rather
>be safe than sorry and actually check for these impossible errors.
>
>Signed-off-by: Christoph Hellwig <hch@lst.de>
>---
> block/bio.c | 66 ++++++++++++++++++++++++-----------------------------
> 1 file changed, 30 insertions(+), 36 deletions(-)
>
>diff --git a/block/bio.c b/block/bio.c
>index 1f6ac44b4881..bc3bca5f0686 100644
>--- a/block/bio.c
>+++ b/block/bio.c
>@@ -1063,20 +1063,9 @@ void __bio_add_page(struct bio *bio, struct page *page,
> }
> EXPORT_SYMBOL_GPL(__bio_add_page);
>
>-/**
>- *	bio_add_page	-	attempt to add page(s) to bio
>- *	@bio: destination bio
>- *	@page: start page to add
>- *	@len: vec entry length, may cross pages
>- *	@offset: vec entry offset relative to @page, may cross pages
>- *
>- *	Attempt to add page(s) to the bio_vec maplist. This will only fail
>- *	if either bio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio.
>- */
>-int bio_add_page(struct bio *bio, struct page *page,
>-		 unsigned int len, unsigned int offset)
>+static int bio_do_add_page(struct bio *bio, struct page *page,
>+		 unsigned int len, unsigned int offset, bool *same_page)

As we are passing length within a folio, values will reach near UINT_MAX.
It will be better to make len and offset as size_t, also to add a check like :
if (len > UINT_MAX || offset > UINT_MAX)
		return 0; 

> {
>-	bool same_page = false;

nit: extra line got added


[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2024-11-06 10:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 15:52 bio_add_* cleanups Christoph Hellwig
2024-11-05 15:52 ` [PATCH 1/2] block: remove bio_add_hw_folio Christoph Hellwig
2024-11-06  9:54   ` Kundan Kumar
2024-11-05 15:52 ` [PATCH 2/2] block: share more code for bio addition helpers Christoph Hellwig
2024-11-06 10:03   ` Kundan Kumar [this message]
2024-11-07  7:20     ` Christoph Hellwig
2024-11-07  9:10       ` Kundan Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241106100338.35xxy2mcpp4u36xl@green245 \
    --to=kundan.kumar@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).