Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/affs: define AFFSNAMEMAX to replace constant use

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

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Fabian Frederick and committed by
Linus Torvalds
f157853e eeb36f8e

+16 -13
+2
fs/affs/affs.h
··· 30 30 #define AFFS_AC_SIZE (AFFS_CACHE_SIZE/sizeof(struct affs_ext_key)/2) 31 31 #define AFFS_AC_MASK (AFFS_AC_SIZE-1) 32 32 33 + #define AFFSNAMEMAX 30U 34 + 33 35 struct affs_ext_key { 34 36 u32 ext; /* idx of the extended block */ 35 37 u32 key; /* block number */
+3 -3
fs/affs/amigaffs.c
··· 483 483 { 484 484 int i; 485 485 486 - if (len > 30) { 486 + if (len > AFFSNAMEMAX) { 487 487 if (notruncate) 488 488 return -ENAMETOOLONG; 489 489 else 490 - len = 30; 490 + len = AFFSNAMEMAX; 491 491 } 492 492 for (i = 0; i < len; i++) { 493 493 if (name[i] < ' ' || name[i] == ':' ··· 508 508 int 509 509 affs_copy_name(unsigned char *bstr, struct dentry *dentry) 510 510 { 511 - u32 len = min(dentry->d_name.len, 30u); 511 + u32 len = min(dentry->d_name.len, AFFSNAMEMAX); 512 512 513 513 *bstr++ = len; 514 514 memcpy(bstr, dentry->d_name.name, len);
+2 -1
fs/affs/dir.c
··· 114 114 break; 115 115 } 116 116 117 - namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30); 117 + namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], 118 + (u8)AFFSNAMEMAX); 118 119 name = AFFS_TAIL(sb, fh_bh)->name + 1; 119 120 pr_debug("readdir(): dir_emit(\"%.*s\", ino=%u), hash=%d, f_pos=%llx\n", 120 121 namelen, name, ino, hash_pos, ctx->pos);
+8 -8
fs/affs/namei.c
··· 72 72 return retval; 73 73 74 74 hash = init_name_hash(); 75 - len = min(qstr->len, 30u); 75 + len = min(qstr->len, AFFSNAMEMAX); 76 76 for (; len > 0; name++, len--) 77 77 hash = partial_name_hash(toupper(*name), hash); 78 78 qstr->hash = end_name_hash(hash); ··· 115 115 * If the names are longer than the allowed 30 chars, 116 116 * the excess is ignored, so their length may differ. 117 117 */ 118 - if (len >= 30) { 119 - if (name->len < 30) 118 + if (len >= AFFSNAMEMAX) { 119 + if (name->len < AFFSNAMEMAX) 120 120 return 1; 121 - len = 30; 121 + len = AFFSNAMEMAX; 122 122 } else if (len != name->len) 123 123 return 1; 124 124 ··· 157 157 const u8 *name = dentry->d_name.name; 158 158 int len = dentry->d_name.len; 159 159 160 - if (len >= 30) { 161 - if (*name2 < 30) 160 + if (len >= AFFSNAMEMAX) { 161 + if (*name2 < AFFSNAMEMAX) 162 162 return 0; 163 - len = 30; 163 + len = AFFSNAMEMAX; 164 164 } else if (len != *name2) 165 165 return 0; 166 166 ··· 176 176 toupper_t toupper = affs_get_toupper(sb); 177 177 u32 hash; 178 178 179 - hash = len = min(len, 30u); 179 + hash = len = min(len, AFFSNAMEMAX); 180 180 for (; len > 0; len--) 181 181 hash = (hash * 13 + toupper(*name++)) & 0x7ff; 182 182
+1 -1
fs/affs/super.c
··· 584 584 buf->f_bavail = free; 585 585 buf->f_fsid.val[0] = (u32)id; 586 586 buf->f_fsid.val[1] = (u32)(id >> 32); 587 - buf->f_namelen = 30; 587 + buf->f_namelen = AFFSNAMEMAX; 588 588 return 0; 589 589 } 590 590