From: Russell King <rmk+kernel@armlinux.org.uk>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH 13/41] fs/adfs: dir: add common directory buffer release method
Date: Mon, 09 Dec 2019 11:09:20 +0000 [thread overview]
Message-ID: <E1ieGum-0004b3-8C@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20191209110731.GD25745@shell.armlinux.org.uk>
With the bhs pointer in place, we have no need for separate per-format
free() methods, since a generic version will do. Provide a generic
implementation, remove the format specific implementations and the
method function pointer.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
fs/adfs/adfs.h | 2 +-
fs/adfs/dir.c | 21 ++++++++++++++++++---
fs/adfs/dir_f.c | 28 ++++------------------------
fs/adfs/dir_fplus.c | 34 ++--------------------------------
4 files changed, 25 insertions(+), 60 deletions(-)
diff --git a/fs/adfs/adfs.h b/fs/adfs/adfs.h
index 956ac0bd53e1..3bb6fd5b5eb0 100644
--- a/fs/adfs/adfs.h
+++ b/fs/adfs/adfs.h
@@ -126,7 +126,6 @@ struct adfs_dir_ops {
int (*create)(struct adfs_dir *dir, struct object_info *obj);
int (*remove)(struct adfs_dir *dir, struct object_info *obj);
int (*sync)(struct adfs_dir *dir);
- void (*free)(struct adfs_dir *dir);
};
struct adfs_discmap {
@@ -167,6 +166,7 @@ extern const struct dentry_operations adfs_dentry_operations;
extern const struct adfs_dir_ops adfs_f_dir_ops;
extern const struct adfs_dir_ops adfs_fplus_dir_ops;
+void adfs_dir_relse(struct adfs_dir *dir);
void adfs_object_fixup(struct adfs_dir *dir, struct object_info *obj);
extern int adfs_dir_update(struct super_block *sb, struct object_info *obj,
int wait);
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index c1b8b5bccbec..f50302775504 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -6,6 +6,7 @@
*
* Common directory handling for ADFS
*/
+#include <linux/slab.h>
#include "adfs.h"
/*
@@ -13,6 +14,20 @@
*/
static DEFINE_RWLOCK(adfs_dir_lock);
+void adfs_dir_relse(struct adfs_dir *dir)
+{
+ unsigned int i;
+
+ for (i = 0; i < dir->nr_buffers; i++)
+ brelse(dir->bhs[i]);
+ dir->nr_buffers = 0;
+
+ if (dir->bhs != dir->bh)
+ kfree(dir->bhs);
+ dir->bhs = NULL;
+ dir->sb = NULL;
+}
+
static int adfs_dir_read(struct super_block *sb, u32 indaddr,
unsigned int size, struct adfs_dir *dir)
{
@@ -105,7 +120,7 @@ adfs_readdir(struct file *file, struct dir_context *ctx)
read_unlock(&adfs_dir_lock);
free_out:
- ops->free(&dir);
+ adfs_dir_relse(&dir);
return ret;
}
@@ -139,7 +154,7 @@ adfs_dir_update(struct super_block *sb, struct object_info *obj, int wait)
ret = err;
}
- ops->free(&dir);
+ adfs_dir_relse(&dir);
out:
#endif
return ret;
@@ -211,7 +226,7 @@ static int adfs_dir_lookup_byname(struct inode *inode, const struct qstr *qstr,
read_unlock(&adfs_dir_lock);
free_out:
- ops->free(&dir);
+ adfs_dir_relse(&dir);
out:
return ret;
}
diff --git a/fs/adfs/dir_f.c b/fs/adfs/dir_f.c
index e62f35eb7789..e249fdb915fa 100644
--- a/fs/adfs/dir_f.c
+++ b/fs/adfs/dir_f.c
@@ -9,8 +9,6 @@
#include "adfs.h"
#include "dir_f.h"
-static void adfs_f_free(struct adfs_dir *dir);
-
/*
* Read an (unaligned) value of length 1..4 bytes
*/
@@ -128,7 +126,7 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
unsigned int size, struct adfs_dir *dir)
{
const unsigned int blocksize_bits = sb->s_blocksize_bits;
- int blk = 0;
+ int blk;
/*
* Directories which are not a multiple of 2048 bytes
@@ -152,6 +150,8 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
dir->bh[blk] = sb_bread(sb, phys);
if (!dir->bh[blk])
goto release_buffers;
+
+ dir->nr_buffers += 1;
}
memcpy(&dir->dirhead, bufoff(dir->bh, 0), sizeof(dir->dirhead));
@@ -168,17 +168,12 @@ static int adfs_dir_read(struct super_block *sb, u32 indaddr,
if (adfs_dir_checkbyte(dir) != dir->dirtail.new.dircheckbyte)
goto bad_dir;
- dir->nr_buffers = blk;
-
return 0;
bad_dir:
adfs_error(sb, "dir %06x is corrupted", indaddr);
release_buffers:
- for (blk -= 1; blk >= 0; blk -= 1)
- brelse(dir->bh[blk]);
-
- dir->sb = NULL;
+ adfs_dir_relse(dir);
return -EIO;
}
@@ -435,25 +430,10 @@ adfs_f_sync(struct adfs_dir *dir)
return err;
}
-static void
-adfs_f_free(struct adfs_dir *dir)
-{
- int i;
-
- for (i = dir->nr_buffers - 1; i >= 0; i--) {
- brelse(dir->bh[i]);
- dir->bh[i] = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
-}
-
const struct adfs_dir_ops adfs_f_dir_ops = {
.read = adfs_f_read,
.setpos = adfs_f_setpos,
.getnext = adfs_f_getnext,
.update = adfs_f_update,
.sync = adfs_f_sync,
- .free = adfs_f_free
};
diff --git a/fs/adfs/dir_fplus.c b/fs/adfs/dir_fplus.c
index 52c42a9986d9..25308b334dd3 100644
--- a/fs/adfs/dir_fplus.c
+++ b/fs/adfs/dir_fplus.c
@@ -15,7 +15,7 @@ adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct
struct adfs_bigdirtail *t;
unsigned long block;
unsigned int blk, size;
- int i, ret = -EIO;
+ int ret = -EIO;
block = __adfs_block_map(sb, id, 0);
if (!block) {
@@ -92,18 +92,8 @@ adfs_fplus_read(struct super_block *sb, unsigned int id, unsigned int sz, struct
return 0;
out:
- if (dir->bhs) {
- for (i = 0; i < dir->nr_buffers; i++)
- brelse(dir->bhs[i]);
+ adfs_dir_relse(dir);
- if (&dir->bh[0] != dir->bhs)
- kfree(dir->bhs);
-
- dir->bhs = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
return ret;
}
@@ -205,29 +195,9 @@ adfs_fplus_sync(struct adfs_dir *dir)
return err;
}
-static void
-adfs_fplus_free(struct adfs_dir *dir)
-{
- int i;
-
- if (dir->bhs) {
- for (i = 0; i < dir->nr_buffers; i++)
- brelse(dir->bhs[i]);
-
- if (&dir->bh[0] != dir->bhs)
- kfree(dir->bhs);
-
- dir->bhs = NULL;
- }
-
- dir->nr_buffers = 0;
- dir->sb = NULL;
-}
-
const struct adfs_dir_ops adfs_fplus_dir_ops = {
.read = adfs_fplus_read,
.setpos = adfs_fplus_setpos,
.getnext = adfs_fplus_getnext,
.sync = adfs_fplus_sync,
- .free = adfs_fplus_free
};
--
2.20.1
next prev parent reply other threads:[~2019-12-09 11:09 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-09 11:07 [PATCH 00/41] fs/adfs updates for 5.6 Russell King - ARM Linux admin
2019-12-09 11:08 ` [PATCH 01/41] fs/adfs: inode: update timestamps to centisecond precision Russell King
2019-12-09 13:54 ` Vyacheslav Dubeyko
2019-12-09 14:03 ` Russell King - ARM Linux admin
2019-12-09 14:34 ` Vyacheslav Dubeyko
2019-12-09 14:40 ` Russell King - ARM Linux admin
2019-12-09 17:15 ` Matthew Wilcox
2019-12-09 11:08 ` [PATCH 02/41] fs/adfs: inode: fix adfs_mode2atts() Russell King
2019-12-09 11:08 ` [PATCH 03/41] fs/adfs: map: move map reading and validation to map.c Russell King
2019-12-09 11:08 ` [PATCH 04/41] fs/adfs: map: rename adfs_map_free() to adfs_map_statfs() Russell King
2019-12-09 11:08 ` [PATCH 05/41] fs/adfs: map: break up adfs_read_map() Russell King
2019-12-09 11:08 ` [PATCH 06/41] fs/adfs: map: factor out map cleanup Russell King
2019-12-09 11:08 ` [PATCH 07/41] fs/adfs: map: incorporate map offsets into layout Russell King
2019-12-09 11:08 ` [PATCH 08/41] fs/adfs: map: use find_next_bit_le() rather than open coding it Russell King
2019-12-09 11:08 ` [PATCH 09/41] fs/adfs: map: move map-specific sb initialisation to map.c Russell King
2019-12-09 11:09 ` [PATCH 10/41] fs/adfs: map: fix map scanning Russell King
2019-12-09 11:09 ` [PATCH 11/41] fs/adfs: dir: rename bh_fplus to bhs Russell King
2019-12-09 11:09 ` [PATCH 12/41] fs/adfs: dir: add common dir object initialisation Russell King
2019-12-09 11:09 ` Russell King [this message]
2019-12-09 11:09 ` [PATCH 14/41] fs/adfs: dir: add common directory sync method Russell King
2019-12-09 11:09 ` [PATCH 15/41] fs/adfs: dir: add generic copy functions Russell King
2019-12-09 11:09 ` [PATCH 16/41] fs/adfs: dir: add generic directory reading Russell King
2019-12-09 11:09 ` [PATCH 17/41] fs/adfs: dir: add helper to read directory using inode Russell King
2019-12-09 11:09 ` [PATCH 18/41] fs/adfs: dir: add helper to mark directory buffers dirty Russell King
2019-12-09 11:09 ` [PATCH 19/41] fs/adfs: dir: update directory locking Russell King
2019-12-09 11:09 ` [PATCH 20/41] fs/adfs: dir: modernise on-disk directory structures Russell King
2019-12-09 11:10 ` [PATCH 21/41] fs/adfs: dir: improve update failure handling Russell King
2019-12-09 11:10 ` [PATCH 22/41] fs/adfs: dir: improve compiler coverage in adfs_dir_update Russell King
2019-12-09 11:10 ` [PATCH 23/41] fs/adfs: dir: switch to iterate_shared method Russell King
2019-12-09 11:10 ` [PATCH 24/41] fs/adfs: dir: add more efficient iterate() per-format method Russell King
2019-12-09 11:10 ` [PATCH 25/41] fs/adfs: dir: use pointers to access directory head/tails Russell King
2019-12-09 11:10 ` [PATCH 26/41] fs/adfs: newdir: factor out directory format validation Russell King
2019-12-09 11:10 ` [PATCH 27/41] fs/adfs: newdir: improve directory validation Russell King
2019-12-09 11:10 ` [PATCH 28/41] fs/adfs: newdir: merge adfs_dir_read() into adfs_f_read() Russell King
2019-12-09 11:10 ` [PATCH 29/41] fs/adfs: newdir: clean up adfs_f_update() Russell King
2019-12-09 11:10 ` [PATCH 30/41] fs/adfs: newdir: split out directory commit from update Russell King
2019-12-09 11:10 ` [PATCH 31/41] fs/adfs: bigdir: factor out directory entry offset calculation Russell King
2019-12-09 11:10 ` [PATCH 32/41] fs/adfs: bigdir: extract directory validation Russell King
2019-12-09 11:11 ` [PATCH 33/41] fs/adfs: bigdir: directory validation strengthening Russell King
2019-12-09 11:11 ` [PATCH 34/41] fs/adfs: bigdir: calculate and validate directory checkbyte Russell King
2019-12-09 11:11 ` [PATCH 35/41] fs/adfs: bigdir: implement directory update support Russell King
2019-12-09 11:11 ` [PATCH 36/41] fs/adfs: super: fix inode dropping Russell King
2019-12-09 11:11 ` [PATCH 37/41] fs/adfs: dir: remove debug in adfs_dir_update() Russell King
2019-12-09 11:11 ` [PATCH 38/41] fs/adfs: super: extract filesystem block probe Russell King
2019-12-09 11:11 ` [PATCH 39/41] fs/adfs: super: add support for E and E+ floppy image formats Russell King
2019-12-09 11:11 ` [PATCH 40/41] fs/adfs: mostly divorse inode number from indirect disc address Russell King
2019-12-09 11:11 ` [PATCH 41/41] Documentation: update adfs filesystem documentation Russell King
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=E1ieGum-0004b3-8C@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=linux-fsdevel@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).