From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Evgeniy Dushistov <dushistov@mail.ru>,
Al Viro <viro@zeniv.linux.org.uk>,
Ira Weiny <ira.weiny@intel.com>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Cc: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Subject: [PATCH v5 1/4] fs/ufs: Use the offset_in_page() helper
Date: Thu, 29 Dec 2022 23:50:57 +0100 [thread overview]
Message-ID: <20221229225100.22141-2-fmdefrancesco@gmail.com> (raw)
In-Reply-To: <20221229225100.22141-1-fmdefrancesco@gmail.com>
Use the offset_in_page() helper because it is more suitable than doing
explicit subtractions between pointers to directory entries and kernel
virtual addresses of mapped pages.
Cc: Ira Weiny <ira.weiny@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
fs/ufs/dir.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fs/ufs/dir.c b/fs/ufs/dir.c
index 391efaf1d528..69f78583c9c1 100644
--- a/fs/ufs/dir.c
+++ b/fs/ufs/dir.c
@@ -87,8 +87,7 @@ void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
struct page *page, struct inode *inode,
bool update_times)
{
- loff_t pos = page_offset(page) +
- (char *) de - (char *) page_address(page);
+ loff_t pos = page_offset(page) + offset_in_page(de);
unsigned len = fs16_to_cpu(dir->i_sb, de->d_reclen);
int err;
@@ -371,8 +370,7 @@ int ufs_add_link(struct dentry *dentry, struct inode *inode)
return -EINVAL;
got_it:
- pos = page_offset(page) +
- (char*)de - (char*)page_address(page);
+ pos = page_offset(page) + offset_in_page(de);
err = ufs_prepare_chunk(page, pos, rec_len);
if (err)
goto out_unlock;
@@ -497,8 +495,8 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
{
struct super_block *sb = inode->i_sb;
char *kaddr = page_address(page);
- unsigned from = ((char*)dir - kaddr) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1);
- unsigned to = ((char*)dir - kaddr) + fs16_to_cpu(sb, dir->d_reclen);
+ unsigned int from = offset_in_page(dir) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1);
+ unsigned int to = offset_in_page(dir) + fs16_to_cpu(sb, dir->d_reclen);
loff_t pos;
struct ufs_dir_entry *pde = NULL;
struct ufs_dir_entry *de = (struct ufs_dir_entry *) (kaddr + from);
@@ -522,7 +520,7 @@ int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
de = ufs_next_entry(sb, de);
}
if (pde)
- from = (char*)pde - (char*)page_address(page);
+ from = offset_in_page(pde);
pos = page_offset(page) + from;
lock_page(page);
--
2.39.0
next prev parent reply other threads:[~2022-12-29 22:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-29 22:50 [PATCH v5 0/4] fs/ufs: Replace kmap() with kmap_local_page Fabio M. De Francesco
2022-12-29 22:50 ` Fabio M. De Francesco [this message]
2022-12-30 0:41 ` [PATCH v5 1/4] fs/ufs: Use the offset_in_page() helper Ira Weiny
2022-12-29 22:50 ` [PATCH v5 2/4] fs/ufs: Change the signature of ufs_get_page() Fabio M. De Francesco
2022-12-29 22:50 ` [PATCH v5 3/4] fs/ufs: Use ufs_put_page() in ufs_rename() Fabio M. De Francesco
2022-12-30 0:50 ` Ira Weiny
2022-12-29 22:51 ` [PATCH v5 4/4] fs/ufs: Replace kmap() with kmap_local_page() Fabio M. De Francesco
2022-12-30 0:50 ` Ira Weiny
2023-03-27 10:13 ` [PATCH v5 0/4] fs/ufs: Replace kmap() with kmap_local_page Fabio M. De Francesco
2023-03-27 13:23 ` Matthew Wilcox
2023-04-03 5:27 ` Fabio M. De Francesco
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=20221229225100.22141-2-fmdefrancesco@gmail.com \
--to=fmdefrancesco@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=dushistov@mail.ru \
--cc=ira.weiny@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).