Skip to contentSkip to conversation

fs/ext2: Use ext2_put_page

PATCH Superseded [email protected] 3 participants 5 messages Nov 11, 2020 – Nov 13, 2020 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ext2: Use ext2_put_page

From: Ira Weiny <[email protected]>

There are 3 places in namei.c where the equivalent of ext2_put_page() is open coded on a page which was returned from the ext2_get_page() call [through the use of ext2_find_entry() and ext2_dotdot()].

Move ext2_get_page() and ext2_put_page() to ext2.h in order to help clarify the use of the get/put and then use ext2_put_page() in namei.c

Also add a comment regarding the proper way to release the page returned from ext2_find_entry() and ext2_dotdot().

---

This was originally part of the kmap_thread() series here:

https://lore.kernel.org/lkml/[email protected]/

But this is really a valid clean up regardless of the kmap_thread[local]() changes.

---
 fs/ext2/dir.c   | 33 ++++++++-------------------------
 fs/ext2/ext2.h  | 27 +++++++++++++++++++++++++++
 fs/ext2/namei.c | 15 +++++----------
 3 files changed, 40 insertions(+), 35 deletions(-)
fs/ext2/dir.c +8 -25
index 70355ab6740e..8acd77a66ff4 100644
@@ -66,12 +66,6 @@ static inline unsigned ext2_chunk_size(struct inode *inode)
 	return inode->i_sb->s_blocksize;
 }
 
-static inline void ext2_put_page(struct page *page)
-{
-	kunmap(page);
-	put_page(page);
-}
-
 /*
  * Return the offset into page `page_nr' of the last valid
  * byte in that page, plus one.
@@ -196,25 +190,6 @@ static bool ext2_check_page(struct page *page, int quiet)
 	return false;
 }
 
-static struct page * ext2_get_page(struct inode *dir, unsigned long n,
-				   int quiet)
-{
-	struct address_space *mapping = dir->i_mapping;
-	struct page *page = read_mapping_page(mapping, n, NULL);
-	if (!IS_ERR(page)) {
-		kmap(page);
-		if (unlikely(!PageChecked(page))) {
-			if (PageError(page) || !ext2_check_page(page, quiet))
-				goto fail;
-		}
-	}
-	return page;
-
-fail:
-	ext2_put_page(page);
-	return ERR_PTR(-EIO);
-}
-
 /*
  * NOTE! unlike strncmp, ext2_match returns 1 for success, 0 for failure.
  *
@@ -336,6 +311,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
  * returns the page in which the entry was found (as a parameter - res_page),
  * and the entry itself. Page is returned mapped and unlocked.
  * Entry is guaranteed to be valid.
+ *
+ * On Success ext2_put_page() should be called on *res_page.
  */
 struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 			const struct qstr *child, struct page **res_page)
@@ -401,6 +378,12 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 	return de;
 }
 
+/**
+ * Return the '..' directory entry and the page in which the entry was found
+ * (as a parameter - p).
+ *
+ * On Success ext2_put_page() should be called on *p.
+ */
 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
 {
 	struct page *page = ext2_get_page(dir, 0, 0);
fs/ext2/ext2.h +27 -0
index 5136b7289e8d..b4403f96858b 100644
@@ -16,6 +16,8 @@
 #include <linux/blockgroup_lock.h>
 #include <linux/percpu_counter.h>
 #include <linux/rbtree.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
 
 /* XXX Here for now... not interested in restructing headers JUST now */
 
@@ -745,6 +747,31 @@ extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
 extern int ext2_empty_dir (struct inode *);
 extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
+static inline void ext2_put_page(struct page *page)
+{
+	kunmap(page);
+	put_page(page);
+}
+
+static inline struct page * ext2_get_page(struct inode *dir, unsigned long n,
+				   int quiet)
+{
+	struct address_space *mapping = dir->i_mapping;
+	struct page *page = read_mapping_page(mapping, n, NULL);
+	if (!IS_ERR(page)) {
+		kmap(page);
+		if (unlikely(!PageChecked(page))) {
+			if (PageError(page) || !ext2_check_page(page, quiet))
+				goto fail;
+		}
+	}
+	return page;
+
+fail:
+	ext2_put_page(page);
+	return ERR_PTR(-EIO);
+}
+
 
 /* ialloc.c */
 extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
fs/ext2/namei.c +5 -10
index 5bf2c145643b..ea980f1e2e99 100644
@@ -389,23 +389,18 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
 	if (dir_de) {
 		if (old_dir != new_dir)
 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
-		else {
-			kunmap(dir_page);
-			put_page(dir_page);
-		}
+		else
+			ext2_put_page(dir_page);
 		inode_dec_link_count(old_dir);
 	}
 	return 0;
 
 
 out_dir:
-	if (dir_de) {
-		kunmap(dir_page);
-		put_page(dir_page);
-	}
+	if (dir_de)
+		ext2_put_page(dir_page);
 out_old:
-	kunmap(old_page);
-	put_page(old_page);
+	ext2_put_page(old_page);
 out:
 	return err;
 }
Signature · 1 line
2.28.0.rc0.12.gb6a658bd00c9
#1 lore raw
I love your patch! Yet something to improve:

Hi,

I love your patch! Yet something to improve:

[auto build test ERROR on ext3/for_next]
[also build test ERROR on linus/master linux/master v5.10-rc3 next-20201111] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/ira-weiny-intel-com/fs-ext2-Use-ext2_put_page/20201112-050044
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git for_next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d24a7d5f9818dbc967629bb19cfa34856dbb7498
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review ira-weiny-intel-com/fs-ext2-Use-ext2_put_page/20201112-050044 git checkout d24a7d5f9818dbc967629bb19cfa34856dbb7498
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

In file included from fs/ext2/file.c:28:
fs/ext2/ext2.h: In function 'ext2_get_page':

>> fs/ext2/ext2.h:764:28: error: implicit declaration of function 'ext2_check_page'; did you mean 'ext2_get_page'? [-Werror=implicit-function-declaration]
     764 |    if (PageError(page) || !ext2_check_page(page, quiet))
         |                            ^~~~~~~~~~~~~~~
         |                            ext2_get_page

cc1: some warnings being treated as errors
--
In file included from fs/ext2/ioctl.c:11:
fs/ext2/ext2.h: In function 'ext2_get_page':

>> fs/ext2/ext2.h:760:22: error: implicit declaration of function 'read_mapping_page'; did you mean 'unmap_mapping_pages'? [-Werror=implicit-function-declaration]
     760 |  struct page *page = read_mapping_page(mapping, n, NULL);
         |                      ^~~~~~~~~~~~~~~~~
         |                      unmap_mapping_pages
>> fs/ext2/ext2.h:760:22: warning: initialization of 'struct page *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
>> fs/ext2/ext2.h:764:28: error: implicit declaration of function 'ext2_check_page'; did you mean 'ext2_get_page'? [-Werror=implicit-function-declaration]
     764 |    if (PageError(page) || !ext2_check_page(page, quiet))
         |                            ^~~~~~~~~~~~~~~
         |                            ext2_get_page

cc1: some warnings being treated as errors
--
In file included from fs/ext2/balloc.c:15:
fs/ext2/ext2.h: In function 'ext2_get_page':

>> fs/ext2/ext2.h:760:22: error: implicit declaration of function 'read_mapping_page'; did you mean 'unmap_mapping_pages'? [-Werror=implicit-function-declaration]
     760 |  struct page *page = read_mapping_page(mapping, n, NULL);
         |                      ^~~~~~~~~~~~~~~~~
         |                      unmap_mapping_pages
>> fs/ext2/ext2.h:760:22: warning: initialization of 'struct page *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
>> fs/ext2/ext2.h:764:28: error: implicit declaration of function 'ext2_check_page'; did you mean 'ext2_get_page'? [-Werror=implicit-function-declaration]
     764 |    if (PageError(page) || !ext2_check_page(page, quiet))
         |                            ^~~~~~~~~~~~~~~
         |                            ext2_get_page
   In file included from include/linux/buffer_head.h:14,
                    from fs/ext2/balloc.c:20:
   include/linux/pagemap.h: At top level:
>> include/linux/pagemap.h:497:28: error: conflicting types for 'read_mapping_page'
     497 | static inline struct page *read_mapping_page(struct address_space *mapping,
         |                            ^~~~~~~~~~~~~~~~~
   In file included from fs/ext2/balloc.c:15:
   fs/ext2/ext2.h:760:22: note: previous implicit declaration of 'read_mapping_page' was here
     760 |  struct page *page = read_mapping_page(mapping, n, NULL);
         |                      ^~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors
--
In file included from fs/ext2/dir.c:25:
fs/ext2/ext2.h: In function 'ext2_get_page':

>> fs/ext2/ext2.h:760:22: error: implicit declaration of function 'read_mapping_page'; did you mean 'unmap_mapping_pages'? [-Werror=implicit-function-declaration]
     760 |  struct page *page = read_mapping_page(mapping, n, NULL);
         |                      ^~~~~~~~~~~~~~~~~
         |                      unmap_mapping_pages
>> fs/ext2/ext2.h:760:22: warning: initialization of 'struct page *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
>> fs/ext2/ext2.h:764:28: error: implicit declaration of function 'ext2_check_page'; did you mean 'ext2_get_page'? [-Werror=implicit-function-declaration]
     764 |    if (PageError(page) || !ext2_check_page(page, quiet))
         |                            ^~~~~~~~~~~~~~~
         |                            ext2_get_page
   In file included from include/linux/buffer_head.h:14,
                    from fs/ext2/dir.c:26:
   include/linux/pagemap.h: At top level:
>> include/linux/pagemap.h:497:28: error: conflicting types for 'read_mapping_page'
     497 | static inline struct page *read_mapping_page(struct address_space *mapping,
         |                            ^~~~~~~~~~~~~~~~~
   In file included from fs/ext2/dir.c:25:
   fs/ext2/ext2.h:760:22: note: previous implicit declaration of 'read_mapping_page' was here
     760 |  struct page *page = read_mapping_page(mapping, n, NULL);
         |                      ^~~~~~~~~~~~~~~~~
>> fs/ext2/dir.c:109:13: error: conflicting types for 'ext2_check_page'
     109 | static bool ext2_check_page(struct page *page, int quiet)
         |             ^~~~~~~~~~~~~~~
   In file included from fs/ext2/dir.c:25:
   fs/ext2/ext2.h:764:28: note: previous implicit declaration of 'ext2_check_page' was here
     764 |    if (PageError(page) || !ext2_check_page(page, quiet))
         |                            ^~~~~~~~~~~~~~~

fs/ext2/dir.c:109:13: warning: 'ext2_check_page' defined but not used [-Wunused-function]
109 | static bool ext2_check_page(struct page *page, int quiet)
| ^~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

vim +764 fs/ext2/ext2.h

755
756 static inline struct page * ext2_get_page(struct inode *dir, unsigned long n,
757 int quiet)
758 {
759 struct address_space *mapping = dir->i_mapping;

 > 760		struct page *page = read_mapping_page(mapping, n, NULL);
   761		if (!IS_ERR(page)) {
   762			kmap(page);
   763			if (unlikely(!PageChecked(page))) {
 > 764				if (PageError(page) || !ext2_check_page(page, quiet))

765 goto fail;
766 }
767 }
768 return page;
769
770 fail:
771 ext2_put_page(page);
772 return ERR_PTR(-EIO);
773 }
774

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Wed 11-11-20 12:55:30, [email protected] wrote:

From: Ira Weiny <[email protected]>

There are 3 places in namei.c where the equivalent of ext2_put_page() is open coded on a page which was returned from the ext2_get_page() call [through the use of ext2_find_entry() and ext2_dotdot()].

Quoted 7 lines

Move ext2_get_page() and ext2_put_page() to ext2.h in order to help clarify the use of the get/put and then use ext2_put_page() in namei.c

Also add a comment regarding the proper way to release the page returned from ext2_find_entry() and ext2_dotdot().

Thanks. Good cleanup. I've added it to my tree.

Honza

Quoted 161 lines

---

This was originally part of the kmap_thread() series here:

https://lore.kernel.org/lkml/[email protected]/

But this is really a valid clean up regardless of the kmap_thread[local]() changes.

---
 fs/ext2/dir.c   | 33 ++++++++-------------------------
 fs/ext2/ext2.h  | 27 +++++++++++++++++++++++++++
 fs/ext2/namei.c | 15 +++++----------
 3 files changed, 40 insertions(+), 35 deletions(-)
fs/ext2/dir.c +8 -25
index 70355ab6740e..8acd77a66ff4 100644
@@ -66,12 +66,6 @@ static inline unsigned ext2_chunk_size(struct inode *inode)
 	return inode->i_sb->s_blocksize;
 }
 
-static inline void ext2_put_page(struct page *page)
-{
-	kunmap(page);
-	put_page(page);
-}
-
 /*
  * Return the offset into page `page_nr' of the last valid
  * byte in that page, plus one.
@@ -196,25 +190,6 @@ static bool ext2_check_page(struct page *page, int quiet)
 	return false;
 }
 
-static struct page * ext2_get_page(struct inode *dir, unsigned long n,
-				   int quiet)
-{
-	struct address_space *mapping = dir->i_mapping;
-	struct page *page = read_mapping_page(mapping, n, NULL);
-	if (!IS_ERR(page)) {
-		kmap(page);
-		if (unlikely(!PageChecked(page))) {
-			if (PageError(page) || !ext2_check_page(page, quiet))
-				goto fail;
-		}
-	}
-	return page;
-
-fail:
-	ext2_put_page(page);
-	return ERR_PTR(-EIO);
-}
-
 /*
  * NOTE! unlike strncmp, ext2_match returns 1 for success, 0 for failure.
  *
@@ -336,6 +311,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
  * returns the page in which the entry was found (as a parameter - res_page),
  * and the entry itself. Page is returned mapped and unlocked.
  * Entry is guaranteed to be valid.
+ *
+ * On Success ext2_put_page() should be called on *res_page.
  */
 struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 			const struct qstr *child, struct page **res_page)
@@ -401,6 +378,12 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 	return de;
 }
 
+/**
+ * Return the '..' directory entry and the page in which the entry was found
+ * (as a parameter - p).
+ *
+ * On Success ext2_put_page() should be called on *p.
+ */
 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
 {
 	struct page *page = ext2_get_page(dir, 0, 0);
fs/ext2/ext2.h +27 -0
index 5136b7289e8d..b4403f96858b 100644
@@ -16,6 +16,8 @@
 #include <linux/blockgroup_lock.h>
 #include <linux/percpu_counter.h>
 #include <linux/rbtree.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
 
 /* XXX Here for now... not interested in restructing headers JUST now */
 
@@ -745,6 +747,31 @@ extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
 extern int ext2_empty_dir (struct inode *);
 extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
+static inline void ext2_put_page(struct page *page)
+{
+	kunmap(page);
+	put_page(page);
+}
+
+static inline struct page * ext2_get_page(struct inode *dir, unsigned long n,
+				   int quiet)
+{
+	struct address_space *mapping = dir->i_mapping;
+	struct page *page = read_mapping_page(mapping, n, NULL);
+	if (!IS_ERR(page)) {
+		kmap(page);
+		if (unlikely(!PageChecked(page))) {
+			if (PageError(page) || !ext2_check_page(page, quiet))
+				goto fail;
+		}
+	}
+	return page;
+
+fail:
+	ext2_put_page(page);
+	return ERR_PTR(-EIO);
+}
+
 
 /* ialloc.c */
 extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
fs/ext2/namei.c +5 -10
index 5bf2c145643b..ea980f1e2e99 100644
@@ -389,23 +389,18 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
 	if (dir_de) {
 		if (old_dir != new_dir)
 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
-		else {
-			kunmap(dir_page);
-			put_page(dir_page);
-		}
+		else
+			ext2_put_page(dir_page);
 		inode_dec_link_count(old_dir);
 	}
 	return 0;
 
 
 out_dir:
-	if (dir_de) {
-		kunmap(dir_page);
-		put_page(dir_page);
-	}
+	if (dir_de)
+		ext2_put_page(dir_page);
 out_old:
-	kunmap(old_page);
-	put_page(old_page);
+	ext2_put_page(old_page);
 out:
 	return err;
 }
Signature · 1 line
2.28.0.rc0.12.gb6a658bd00c9
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw

PATCH v2 1/1 fs/ext2: Use ext2_put_page

In reply to [email protected]

From: Ira Weiny <[email protected]>

There are 3 places in namei.c where the equivalent of ext2_put_page() is open coded on a page which was returned from the ext2_get_page() call [through the use of ext2_find_entry() and ext2_dotdot()].

Move ext2_put_page() to ext2.h and use it in namei.c

Also add a comment regarding the proper way to release the page returned from ext2_find_entry() and ext2_dotdot().

---
Changes from V1:

move ext2_get_page() back to dir.c; my testing must have had the wrong .config because I did not see the compile error yesterday...

This was originally part of the kmap_thread() series here:

https://lore.kernel.org/lkml/[email protected]/

But this is really a valid clean up regardless of the kmap_thread[local]() changes.

---
 fs/ext2/dir.c   | 14 ++++++++------
 fs/ext2/ext2.h  |  7 +++++++
 fs/ext2/namei.c | 15 +++++----------
 3 files changed, 20 insertions(+), 16 deletions(-)
fs/ext2/dir.c +8 -6
index 70355ab6740e..14aa45316ad2 100644
@@ -66,12 +66,6 @@ static inline unsigned ext2_chunk_size(struct inode *inode)
 	return inode->i_sb->s_blocksize;
 }
 
-static inline void ext2_put_page(struct page *page)
-{
-	kunmap(page);
-	put_page(page);
-}
-
 /*
  * Return the offset into page `page_nr' of the last valid
  * byte in that page, plus one.
@@ -336,6 +330,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
  * returns the page in which the entry was found (as a parameter - res_page),
  * and the entry itself. Page is returned mapped and unlocked.
  * Entry is guaranteed to be valid.
+ *
+ * On Success ext2_put_page() should be called on *res_page.
  */
 struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 			const struct qstr *child, struct page **res_page)
@@ -401,6 +397,12 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 	return de;
 }
 
+/**
+ * Return the '..' directory entry and the page in which the entry was found
+ * (as a parameter - p).
+ *
+ * On Success ext2_put_page() should be called on *p.
+ */
 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
 {
 	struct page *page = ext2_get_page(dir, 0, 0);
fs/ext2/ext2.h +7 -0
index 5136b7289e8d..2a4175fbaf5e 100644
@@ -16,6 +16,8 @@
 #include <linux/blockgroup_lock.h>
 #include <linux/percpu_counter.h>
 #include <linux/rbtree.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
 
 /* XXX Here for now... not interested in restructing headers JUST now */
 
@@ -745,6 +747,11 @@ extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
 extern int ext2_empty_dir (struct inode *);
 extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
+static inline void ext2_put_page(struct page *page)
+{
+	kunmap(page);
+	put_page(page);
+}
 
 /* ialloc.c */
 extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
fs/ext2/namei.c +5 -10
index 5bf2c145643b..ea980f1e2e99 100644
@@ -389,23 +389,18 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
 	if (dir_de) {
 		if (old_dir != new_dir)
 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
-		else {
-			kunmap(dir_page);
-			put_page(dir_page);
-		}
+		else
+			ext2_put_page(dir_page);
 		inode_dec_link_count(old_dir);
 	}
 	return 0;
 
 
 out_dir:
-	if (dir_de) {
-		kunmap(dir_page);
-		put_page(dir_page);
-	}
+	if (dir_de)
+		ext2_put_page(dir_page);
 out_old:
-	kunmap(old_page);
-	put_page(old_page);
+	ext2_put_page(old_page);
 out:
 	return err;
 }
Signature · 1 line
2.28.0.rc0.12.gb6a658bd00c9
#4 lore raw
Quoted 11 lines · On Thu 12-11-20 09:42:44, [email protected] wrote:

From: Ira Weiny <[email protected]>

There are 3 places in namei.c where the equivalent of ext2_put_page() is open coded on a page which was returned from the ext2_get_page() call [through the use of ext2_find_entry() and ext2_dotdot()].

Move ext2_put_page() to ext2.h and use it in namei.c

Also add a comment regarding the proper way to release the page returned from ext2_find_entry() and ext2_dotdot().

Quoted 8 lines

---
Changes from V1:

move ext2_get_page() back to dir.c; my testing must have had the wrong .config because I did not see the compile error yesterday...

Drat, and I forgot a compilation test as well :-| My bad. Thanks for the fix anyway!

Honza

Quoted 113 lines

This was originally part of the kmap_thread() series here:

https://lore.kernel.org/lkml/[email protected]/

But this is really a valid clean up regardless of the kmap_thread[local]() changes.

---
 fs/ext2/dir.c   | 14 ++++++++------
 fs/ext2/ext2.h  |  7 +++++++
 fs/ext2/namei.c | 15 +++++----------
 3 files changed, 20 insertions(+), 16 deletions(-)
fs/ext2/dir.c +8 -6
index 70355ab6740e..14aa45316ad2 100644
@@ -66,12 +66,6 @@ static inline unsigned ext2_chunk_size(struct inode *inode)
 	return inode->i_sb->s_blocksize;
 }
 
-static inline void ext2_put_page(struct page *page)
-{
-	kunmap(page);
-	put_page(page);
-}
-
 /*
  * Return the offset into page `page_nr' of the last valid
  * byte in that page, plus one.
@@ -336,6 +330,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx)
  * returns the page in which the entry was found (as a parameter - res_page),
  * and the entry itself. Page is returned mapped and unlocked.
  * Entry is guaranteed to be valid.
+ *
+ * On Success ext2_put_page() should be called on *res_page.
  */
 struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 			const struct qstr *child, struct page **res_page)
@@ -401,6 +397,12 @@ struct ext2_dir_entry_2 *ext2_find_entry (struct inode *dir,
 	return de;
 }
 
+/**
+ * Return the '..' directory entry and the page in which the entry was found
+ * (as a parameter - p).
+ *
+ * On Success ext2_put_page() should be called on *p.
+ */
 struct ext2_dir_entry_2 * ext2_dotdot (struct inode *dir, struct page **p)
 {
 	struct page *page = ext2_get_page(dir, 0, 0);
fs/ext2/ext2.h +7 -0
index 5136b7289e8d..2a4175fbaf5e 100644
@@ -16,6 +16,8 @@
 #include <linux/blockgroup_lock.h>
 #include <linux/percpu_counter.h>
 #include <linux/rbtree.h>
+#include <linux/mm.h>
+#include <linux/highmem.h>
 
 /* XXX Here for now... not interested in restructing headers JUST now */
 
@@ -745,6 +747,11 @@ extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
 extern int ext2_empty_dir (struct inode *);
 extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
 extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
+static inline void ext2_put_page(struct page *page)
+{
+	kunmap(page);
+	put_page(page);
+}
 
 /* ialloc.c */
 extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
fs/ext2/namei.c +5 -10
index 5bf2c145643b..ea980f1e2e99 100644
@@ -389,23 +389,18 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
 	if (dir_de) {
 		if (old_dir != new_dir)
 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
-		else {
-			kunmap(dir_page);
-			put_page(dir_page);
-		}
+		else
+			ext2_put_page(dir_page);
 		inode_dec_link_count(old_dir);
 	}
 	return 0;
 
 
 out_dir:
-	if (dir_de) {
-		kunmap(dir_page);
-		put_page(dir_page);
-	}
+	if (dir_de)
+		ext2_put_page(dir_page);
 out_old:
-	kunmap(old_page);
-	put_page(old_page);
+	ext2_put_page(old_page);
 out:
 	return err;
 }
Signature · 1 line
2.28.0.rc0.12.gb6a658bd00c9
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR