Skip to content

Commit

Permalink
ext2_put_page(): accept any pointer within the page
Browse files Browse the repository at this point in the history
eliminates the need to keep the pointer to the first byte within
the page if we are guaranteed to have pointers to some byte
in the same page at hand.

Don't backport without commit 88d7b12 ("highmem: round down the
address passed to kunmap_flush_on_unmap()").

Signed-off-by: Al Viro <[email protected]>
Reviewed-by: Fabio M. De Francesco <[email protected]>
Tested-by: Fabio M. De Francesco <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
Al Viro authored and jankara committed May 29, 2023
1 parent 4602237 commit 91f646f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
38 changes: 17 additions & 21 deletions fs/ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
if (de->rec_len == 0) {
ext2_error(sb, __func__,
"zero-length directory entry");
ext2_put_page(page, kaddr);
ext2_put_page(page, de);
return -EIO;
}
if (de->inode) {
Expand All @@ -311,7 +311,7 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
if (!dir_emit(ctx, de->name, de->name_len,
le32_to_cpu(de->inode),
d_type)) {
ext2_put_page(page, kaddr);
ext2_put_page(page, de);
return 0;
}
}
Expand Down Expand Up @@ -377,14 +377,14 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
if (de->rec_len == 0) {
ext2_error(dir->i_sb, __func__,
"zero-length directory entry");
ext2_put_page(page, page_addr);
ext2_put_page(page, de);
goto out;
}
if (ext2_match(namelen, name, de))
goto found;
de = ext2_next_entry(de);
}
ext2_put_page(page, page_addr);
ext2_put_page(page, kaddr);

if (++n >= npages)
n = 0;
Expand Down Expand Up @@ -443,7 +443,7 @@ int ext2_inode_by_name(struct inode *dir, const struct qstr *child, ino_t *ino)
return PTR_ERR(de);

*ino = le32_to_cpu(de->inode);
ext2_put_page(page, page_addr);
ext2_put_page(page, de);
return 0;
}

Expand Down Expand Up @@ -499,7 +499,6 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
unsigned reclen = EXT2_DIR_REC_LEN(namelen);
unsigned short rec_len, name_len;
struct page *page = NULL;
void *page_addr = NULL;
ext2_dirent * de;
unsigned long npages = dir_pages(dir);
unsigned long n;
Expand All @@ -515,11 +514,10 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
char *kaddr;
char *dir_end;

page_addr = ext2_get_page(dir, n, 0, &page);
if (IS_ERR(page_addr))
return PTR_ERR(page_addr);
kaddr = ext2_get_page(dir, n, 0, &page);
if (IS_ERR(kaddr))
return PTR_ERR(kaddr);
lock_page(page);
kaddr = page_addr;
dir_end = kaddr + ext2_last_byte(dir, n);
de = (ext2_dirent *)kaddr;
kaddr += PAGE_SIZE - reclen;
Expand Down Expand Up @@ -550,7 +548,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
de = (ext2_dirent *) ((char *) de + rec_len);
}
unlock_page(page);
ext2_put_page(page, page_addr);
ext2_put_page(page, kaddr);
}
BUG();
return -EINVAL;
Expand All @@ -577,7 +575,7 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
err = ext2_handle_dirsync(dir);
/* OFFSET_CACHE */
out_put:
ext2_put_page(page, page_addr);
ext2_put_page(page, de);
return err;
out_unlock:
unlock_page(page);
Expand Down Expand Up @@ -675,19 +673,17 @@ int ext2_make_empty(struct inode *inode, struct inode *parent)
*/
int ext2_empty_dir (struct inode * inode)
{
void *page_addr = NULL;
struct page *page = NULL;
struct page *page;
char *kaddr;
unsigned long i, npages = dir_pages(inode);

for (i = 0; i < npages; i++) {
char *kaddr;
ext2_dirent * de;
page_addr = ext2_get_page(inode, i, 0, &page);
ext2_dirent *de;

if (IS_ERR(page_addr))
kaddr = ext2_get_page(inode, i, 0, &page);
if (IS_ERR(kaddr))
return 0;

kaddr = page_addr;
de = (ext2_dirent *)kaddr;
kaddr += ext2_last_byte(inode, i) - EXT2_DIR_REC_LEN(1);

Expand All @@ -713,12 +709,12 @@ int ext2_empty_dir (struct inode * inode)
}
de = ext2_next_entry(de);
}
ext2_put_page(page, page_addr);
ext2_put_page(page, kaddr);
}
return 1;

not_empty:
ext2_put_page(page, page_addr);
ext2_put_page(page, kaddr);
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
}

err = ext2_delete_entry (de, page, page_addr);
ext2_put_page(page, page_addr);
ext2_put_page(page, de);
if (err)
goto out;

Expand Down Expand Up @@ -370,7 +370,7 @@ static int ext2_rename (struct mnt_idmap * idmap,
}
err = ext2_set_link(new_dir, new_de, new_page, page_addr,
old_inode, true);
ext2_put_page(new_page, page_addr);
ext2_put_page(new_page, new_de);
if (err)
goto out_dir;
new_inode->i_ctime = current_time(new_inode);
Expand Down Expand Up @@ -402,9 +402,9 @@ static int ext2_rename (struct mnt_idmap * idmap,
}
out_dir:
if (dir_de)
ext2_put_page(dir_page, dir_page_addr);
ext2_put_page(dir_page, dir_de);
out_old:
ext2_put_page(old_page, old_page_addr);
ext2_put_page(old_page, old_de);
return err;
}

Expand Down

0 comments on commit 91f646f

Please sign in to comment.