Skip to contentSkip to conversation

FS/AFFS: replace min() with casting/constant suffix by min_t

PATCH In review Fabian Frederick 2 participants 8 messages Feb 3, 2015 Affs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 FS/AFFS: replace min() with casting/constant suffix by min_t

This patch prepares for AFFSNAMEMAX definition

---
 fs/affs/amigaffs.c | 2 +-
 fs/affs/dir.c      | 2 +-
 fs/affs/namei.c    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/affs/amigaffs.c +1 -1
index 511ab6b..7a6de60 100644
@@ -508,7 +508,7 @@ affs_check_name(const unsigned char *name, int len, bool notruncate)
 int
 affs_copy_name(unsigned char *bstr, struct dentry *dentry)
 {
-	int len = min(dentry->d_name.len, 30u);
+	int len = min_t(u64, dentry->d_name.len, 30);
 
 	*bstr++ = len;
 	memcpy(bstr, dentry->d_name.name, len);
fs/affs/dir.c +1 -1
index a682892..580b958 100644
@@ -114,7 +114,7 @@ inside:
 				break;
 			}
 
-			namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30);
+			namelen = min_t(u8, AFFS_TAIL(sb, fh_bh)->name[0], 30);
 			name = AFFS_TAIL(sb, fh_bh)->name + 1;
 			pr_debug("readdir(): dir_emit(\"%.*s\", ino=%u), hash=%d, f_pos=%llx\n",
 				 namelen, name, ino, hash_pos, ctx->pos);
fs/affs/namei.c +2 -2
index de84f4d..4a04c2d 100644
@@ -71,7 +71,7 @@ __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
 		return i;
 
 	hash = init_name_hash();
-	i = min(qstr->len, 30u);
+	i = min_t(u64, qstr->len, 30);
 	for (; i > 0; name++, i--)
 		hash = partial_name_hash(toupper(*name), hash);
 	qstr->hash = end_name_hash(hash);
@@ -175,7 +175,7 @@ affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len)
 	toupper_t toupper = affs_get_toupper(sb);
 	int hash;
 
-	hash = len = min(len, 30u);
+	hash = len = min_t(unsigned, len, 30);
 	for (; len > 0; len--)
 		hash = (hash * 13 + toupper(*name++)) & 0x7ff;
 
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/6 FS/AFFS: define AFFSNAMEMAX to replace constant use

30 was used all over the place to compare name length against AFFS maximum name length.

---
 fs/affs/affs.h     |  2 ++
 fs/affs/amigaffs.c |  6 +++---
 fs/affs/dir.c      |  3 ++-
 fs/affs/namei.c    | 16 ++++++++--------
 fs/affs/super.c    |  2 +-
 5 files changed, 16 insertions(+), 13 deletions(-)
fs/affs/affs.h +2 -0
index ff44ff3..26c89fb 100644
@@ -30,6 +30,8 @@
 #define AFFS_AC_SIZE		(AFFS_CACHE_SIZE/sizeof(struct affs_ext_key)/2)
 #define AFFS_AC_MASK		(AFFS_AC_SIZE-1)
 
+#define AFFSNAMEMAX 30
+
 struct affs_ext_key {
 	u32	ext;				/* idx of the extended block */
 	u32	key;				/* block number */
fs/affs/amigaffs.c +3 -3
index 7a6de60..581a2fb 100644
@@ -483,11 +483,11 @@ affs_check_name(const unsigned char *name, int len, bool notruncate)
 {
 	int	 i;
 
-	if (len > 30) {
+	if (len > AFFSNAMEMAX) {
 		if (notruncate)
 			return -ENAMETOOLONG;
 		else
-			len = 30;
+			len = AFFSNAMEMAX;
 	}
 	for (i = 0; i < len; i++) {
 		if (name[i] < ' ' || name[i] == ':'
@@ -508,7 +508,7 @@ affs_check_name(const unsigned char *name, int len, bool notruncate)
 int
 affs_copy_name(unsigned char *bstr, struct dentry *dentry)
 {
-	int len = min_t(u64, dentry->d_name.len, 30);
+	int len = min_t(u64, dentry->d_name.len, AFFSNAMEMAX);
 
 	*bstr++ = len;
 	memcpy(bstr, dentry->d_name.name, len);
fs/affs/dir.c +2 -1
index 580b958..06a3ba7 100644
@@ -114,7 +114,8 @@ inside:
 				break;
 			}
 
-			namelen = min_t(u8, AFFS_TAIL(sb, fh_bh)->name[0], 30);
+			namelen = min_t(u8, AFFS_TAIL(sb, fh_bh)->name[0],
+					AFFSNAMEMAX);
 			name = AFFS_TAIL(sb, fh_bh)->name + 1;
 			pr_debug("readdir(): dir_emit(\"%.*s\", ino=%u), hash=%d, f_pos=%llx\n",
 				 namelen, name, ino, hash_pos, ctx->pos);
fs/affs/namei.c +8 -8
index 4a04c2d..f3cd869 100644
@@ -71,7 +71,7 @@ __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
 		return i;
 
 	hash = init_name_hash();
-	i = min_t(u64, qstr->len, 30);
+	i = min_t(u64, qstr->len, AFFSNAMEMAX);
 	for (; i > 0; name++, i--)
 		hash = partial_name_hash(toupper(*name), hash);
 	qstr->hash = end_name_hash(hash);
@@ -114,10 +114,10 @@ static inline int __affs_compare_dentry(unsigned int len,
 	 * If the names are longer than the allowed 30 chars,
 	 * the excess is ignored, so their length may differ.
 	 */
-	if (len >= 30) {
-		if (name->len < 30)
+	if (len >= AFFSNAMEMAX) {
+		if (name->len < AFFSNAMEMAX)
 			return 1;
-		len = 30;
+		len = AFFSNAMEMAX;
 	} else if (len != name->len)
 		return 1;
 
@@ -156,10 +156,10 @@ affs_match(struct dentry *dentry, const u8 *name2, toupper_t toupper)
 	const u8 *name = dentry->d_name.name;
 	int len = dentry->d_name.len;
 
-	if (len >= 30) {
-		if (*name2 < 30)
+	if (len >= AFFSNAMEMAX) {
+		if (*name2 < AFFSNAMEMAX)
 			return 0;
-		len = 30;
+		len = AFFSNAMEMAX;
 	} else if (len != *name2)
 		return 0;
 
@@ -175,7 +175,7 @@ affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len)
 	toupper_t toupper = affs_get_toupper(sb);
 	int hash;
 
-	hash = len = min_t(unsigned, len, 30);
+	hash = len = min_t(unsigned, len, AFFSNAMEMAX);
 	for (; len > 0; len--)
 		hash = (hash * 13 + toupper(*name++)) & 0x7ff;
 
fs/affs/super.c +1 -1
index ee8eca7..c3524bf 100644
@@ -584,7 +584,7 @@ affs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bavail  = free;
 	buf->f_fsid.val[0] = (u32)id;
 	buf->f_fsid.val[1] = (u32)(id >> 32);
-	buf->f_namelen = 30;
+	buf->f_namelen = AFFSNAMEMAX;
 	return 0;
 }
 
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH 2/6 linux-next] FS/AFFS: define AFFSNAMEMAX to replace constant use

Quoted 6 lines · On Tue, 3 Feb 2015 19:07:53 +0100 Fabian Frederick <[email protected]> wrote:

30 was used all over the place to compare name length against AFFS maximum name length.

...

+#define AFFSNAMEMAX 30

Making this 30U would probably help when cleaning up the sites which use it.

#3 lore raw

PATCH 3/6 fs/affs/amigaffs.c: remove else after return

In reply to Fabian Frederick

else is unnecessary after return -ENAMETOOLONG

---
 fs/affs/amigaffs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/affs/amigaffs.c +1 -2
index 581a2fb..029e23a 100644
@@ -486,8 +486,7 @@ affs_check_name(const unsigned char *name, int len, bool notruncate)
 	if (len > AFFSNAMEMAX) {
 		if (notruncate)
 			return -ENAMETOOLONG;
-		else
-			len = AFFSNAMEMAX;
+		len = AFFSNAMEMAX;
 	}
 	for (i = 0; i < len; i++) {
 		if (name[i] < ' ' || name[i] == ':'
Signature · 1 line
2.1.0
#4 lore raw

PATCH 4/6 fs/affs/bitmap.c: remove unnecessary return

In reply to Fabian Frederick

return is not needed at the end of function.

---
 fs/affs/bitmap.c | 1 -
 1 file changed, 1 deletion(-)
fs/affs/bitmap.c +0 -1
index c8de511..6751489 100644
@@ -99,7 +99,6 @@ err_bh_read:
 
 err_range:
 	affs_error(sb, "affs_free_block","Block %u outside partition", block);
-	return;
 }
 
 /*
Signature · 1 line
2.1.0
#5 lore raw

PATCH 5/6 fs/affs/inode.c: remove double extern affs_symlink_inode_operations

In reply to Fabian Frederick

affs_symlink_inode_operations was already declared extern in affs.h

---
 fs/affs/inode.c | 2 --
 1 file changed, 2 deletions(-)
fs/affs/inode.c +0 -2
index 25cb4b4..6f34510 100644
@@ -13,8 +13,6 @@
 #include <linux/gfp.h>
 #include "affs.h"
 
-extern const struct inode_operations affs_symlink_inode_operations;
-
 struct inode *affs_iget(struct super_block *sb, unsigned long ino)
 {
 	struct affs_sb_info	*sbi = AFFS_SB(sb);
Signature · 1 line
2.1.0
#6 lore raw

PATCH 6/6 fs/affs/super.c: fix switch indentation

In reply to Fabian Frederick

Fix checkpatch error:
"ERROR: switch and case should be at the same indent"

---
 fs/affs/super.c | 66 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 33 insertions(+), 33 deletions(-)
fs/affs/super.c +33 -33
index c3524bf..4cf0e91 100644
@@ -432,39 +432,39 @@ got_root:
 		sb->s_flags |= MS_RDONLY;
 	}
 	switch (chksum) {
-		case MUFS_FS:
-		case MUFS_INTLFFS:
-		case MUFS_DCFFS:
-			sbi->s_flags |= SF_MUFS;
-			/* fall thru */
-		case FS_INTLFFS:
-		case FS_DCFFS:
-			sbi->s_flags |= SF_INTL;
-			break;
-		case MUFS_FFS:
-			sbi->s_flags |= SF_MUFS;
-			break;
-		case FS_FFS:
-			break;
-		case MUFS_OFS:
-			sbi->s_flags |= SF_MUFS;
-			/* fall thru */
-		case FS_OFS:
-			sbi->s_flags |= SF_OFS;
-			sb->s_flags |= MS_NOEXEC;
-			break;
-		case MUFS_DCOFS:
-		case MUFS_INTLOFS:
-			sbi->s_flags |= SF_MUFS;
-		case FS_DCOFS:
-		case FS_INTLOFS:
-			sbi->s_flags |= SF_INTL | SF_OFS;
-			sb->s_flags |= MS_NOEXEC;
-			break;
-		default:
-			pr_err("Unknown filesystem on device %s: %08X\n",
-			       sb->s_id, chksum);
-			return -EINVAL;
+	case MUFS_FS:
+	case MUFS_INTLFFS:
+	case MUFS_DCFFS:
+		sbi->s_flags |= SF_MUFS;
+		/* fall thru */
+	case FS_INTLFFS:
+	case FS_DCFFS:
+		sbi->s_flags |= SF_INTL;
+		break;
+	case MUFS_FFS:
+		sbi->s_flags |= SF_MUFS;
+		break;
+	case FS_FFS:
+		break;
+	case MUFS_OFS:
+		sbi->s_flags |= SF_MUFS;
+		/* fall thru */
+	case FS_OFS:
+		sbi->s_flags |= SF_OFS;
+		sb->s_flags |= MS_NOEXEC;
+		break;
+	case MUFS_DCOFS:
+	case MUFS_INTLOFS:
+		sbi->s_flags |= SF_MUFS;
+	case FS_DCOFS:
+	case FS_INTLOFS:
+		sbi->s_flags |= SF_INTL | SF_OFS;
+		sb->s_flags |= MS_NOEXEC;
+		break;
+	default:
+		pr_err("Unknown filesystem on device %s: %08X\n",
+		       sb->s_id, chksum);
+		return -EINVAL;
 	}
 
 	if (mount_flags & SF_VERBOSE) {
Signature · 1 line
2.1.0
#7 lore raw
In reply to Fabian Frederick
Quoted 15 lines · On Tue, 3 Feb 2015 19:07:52 +0100 Fabian Frederick <[email protected]> wrote:

This patch prepares for AFFSNAMEMAX definition

---
 fs/affs/amigaffs.c | 2 +-
 fs/affs/dir.c      | 2 +-
 fs/affs/namei.c    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
fs/affs/amigaffs.c +0 -0
index 511ab6b..7a6de60 100644

fs/affs/amigaffs.c affs_check_name(const unsigned char *name, int len, bool notruncate) · line 511

Quoted 5 lines
fs/affs/amigaffs.c +1 -1
@@ -508,7 +508,7 @@ affs_check_name(const unsigned char *name, int len, bool notruncate)
 int
 affs_copy_name(unsigned char *bstr, struct dentry *dentry)
 {
-	int len = min(dentry->d_name.len, 30u);
+	int len = min_t(u64, dentry->d_name.len, 30);
	int = min_t(u64, u32, int)

Doesn't seem to make sense?

Quoted 20 lines
fs/affs/amigaffs.c +0 -0
 	*bstr++ = len;
 	memcpy(bstr, dentry->d_name.name, len);
fs/affs/dir.c +1 -1
index a682892..580b958 100644
@@ -114,7 +114,7 @@ inside:
 				break;
 			}
 
-			namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30);
+			namelen = min_t(u8, AFFS_TAIL(sb, fh_bh)->name[0], 30);
 			name = AFFS_TAIL(sb, fh_bh)->name + 1;
 			pr_debug("readdir(): dir_emit(\"%.*s\", ino=%u), hash=%d, f_pos=%llx\n",
 				 namelen, name, ino, hash_pos, ctx->pos);
fs/affs/namei.c +0 -0
index de84f4d..4a04c2d 100644

fs/affs/namei.c __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate) · line 74

Quoted 5 lines
fs/affs/namei.c +1 -1
@@ -71,7 +71,7 @@ __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
 		return i;
 
 	hash = init_name_hash();
-	i = min(qstr->len, 30u);
+	i = min_t(u64, qstr->len, 30);

same here

fs/affs/namei.c affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len) · line 178

Quoted 9 lines
fs/affs/namei.c +1 -1
 	for (; i > 0; name++, i--)
 		hash = partial_name_hash(toupper(*name), hash);
 	qstr->hash = end_name_hash(hash);
@@ -175,7 +175,7 @@ affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len)
 	toupper_t toupper = affs_get_toupper(sb);
 	int hash;
 
-	hash = len = min(len, 30u);
+	hash = len = min_t(unsigned, len, 30);
	int = min_t(unsigned, u32, int)

It's a mess! It would be better to do something like

	u32 hash;

	hash = min(len, 30U);

Use of min_t is a pretty reliable sign that the types have been screwed up. Let's try to unscrew the type choices rather than working around earlier mistakes.