From: Huan Yang <link@vivo.com>
To: "Gerd Hoffmann" <kraxel@redhat.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Huan Yang <link@vivo.com>
Subject: [PATCH 2/2] udmabuf: make udmabuf folios and offsets set more readable
Date: Wed, 31 Jul 2024 17:02:33 +0800 [thread overview]
Message-ID: <20240731090233.1343559-2-link@vivo.com> (raw)
In-Reply-To: <20240731090233.1343559-1-link@vivo.com>
The current code for setting folios and offsets is not very readable.
In fact, udmabuf->folios represents the head page of each folio, while
the offset indicates the PAGE_SIZE offset within the folio for the
corresponding pgcnt. And folios only add head page(the folio) into unpin
list.
This patch changes the loop condition to use folios as the outer loop
and sets the subpages of the folio in the inner loop, making it easier
to understand the relationship between unpin and folios/offset.
The loop conditions for j and k are actually only used in the head loop,
so they can be turned into loop variables.
Signed-off-by: Huan Yang <link@vivo.com>
---
drivers/dma-buf/udmabuf.c | 40 ++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 6604d91e7072..0285194e6b51 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -301,7 +301,7 @@ static long udmabuf_create(struct miscdevice *device,
struct file *memfd = NULL;
struct folio **folios;
struct udmabuf *ubuf;
- u32 i, j, k, flags;
+ u32 i, flags;
loff_t end;
ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
@@ -338,6 +338,7 @@ static long udmabuf_create(struct miscdevice *device,
pgbuf = 0;
for (i = 0; i < head->count; i++) {
+ u32 j, k;
memfd = fget(list[i].memfd);
ret = check_memfd_seals(memfd);
if (ret < 0)
@@ -360,26 +361,27 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
}
- nr_folios = ret;
- pgoff >>= PAGE_SHIFT;
- for (j = 0, k = 0; j < pgcnt; j++) {
- ubuf->folios[pgbuf] = folios[k];
- ubuf->offsets[pgbuf] = pgoff << PAGE_SHIFT;
-
- if (j == 0 || ubuf->folios[pgbuf-1] != folios[k]) {
- ret = add_to_unpin_list(&ubuf->unpin_list,
- folios[k]);
- if (ret < 0) {
- kfree(folios);
- goto err;
- }
+ /**
+ * Iter each folios we got from pin, add each folio into unpin
+ * list and setup each folio and page offset into folio into
+ * corrent page count position.
+ * So that we can iter any offset in size and get correctly
+ * page.
+ */
+ for (j = 0, pgoff >>= PAGE_SHIFT, nr_folios = ret;
+ j < nr_folios; ++j, pgoff = 0) {
+ long nr_pages;
+
+ ret = add_to_unpin_list(&ubuf->unpin_list, folios[j]);
+ if (ret < 0) {
+ kfree(folios);
+ goto err;
}
- pgbuf++;
- if (++pgoff == folio_nr_pages(folios[k])) {
- pgoff = 0;
- if (++k == nr_folios)
- break;
+ for (k = 0, nr_pages = folio_nr_pages(folios[j]);
+ k < nr_pages; ++k, ++pgoff, ++pgbuf) {
+ ubuf->folios[pgbuf] = folios[j];
+ ubuf->offsets[pgbuf] = pgoff << PAGE_SHIFT;
}
}
--
2.45.2
prev parent reply other threads:[~2024-07-31 9:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 9:02 [PATCH 1/2] udmabuf: fix vmap_udmabuf error page set Huan Yang
2024-07-31 9:02 ` Huan Yang [this message]
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=20240731090233.1343559-2-link@vivo.com \
--to=link@vivo.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kraxel@redhat.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
--cc=sumit.semwal@linaro.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
all inboxes | Powered by JetHome®