:::::: :::::: Manual check reason: "low confidence static check warning: fs/ext4/inline.c:1386:13: warning: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign]" :::::: BCC: lkp@intel.com CC: llvm@lists.linux.dev CC: oe-kbuild-all@lists.linux.dev CC: linux-kernel@vger.kernel.org TO: NeilBrown CC: Andrew Morton CC: Linux Memory Management List tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 9b43a525db125799df81e6fbef712a2ae50bfc5d commit: 4034247a0d6ab281ba3293798ce67af494d86129 mm: introduce memalloc_retry_wait() date: 12 months ago :::::: branch date: 17 hours ago :::::: commit date: 12 months ago config: i386-randconfig-c001 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) 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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4034247a0d6ab281ba3293798ce67af494d86129 git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git git fetch --no-tags linus master git checkout 4034247a0d6ab281ba3293798ce67af494d86129 # save the config file COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot clang_analyzer warnings: (new ones prefixed by >>) ^ fs/ext4/inline.c:1234:2: note: Taking false branch if (!data_bh) { ^ include/linux/compiler.h:56:23: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ fs/ext4/inline.c:1242:2: note: Assuming 'error' is 0 if (error) { ^ include/linux/compiler.h:56:45: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ fs/ext4/inline.c:1242:2: note: '?' condition is false if (error) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ fs/ext4/inline.c:1242:6: note: 'error' is 0 if (error) { ^ include/linux/compiler.h:56:47: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^~~~ include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value' (cond) ? \ ^~~~ fs/ext4/inline.c:1242:2: note: '?' condition is false if (error) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value' (cond) ? \ ^ fs/ext4/inline.c:1242:2: note: Taking false branch if (error) { ^ include/linux/compiler.h:56:23: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ fs/ext4/inline.c:1249:7: note: Assuming the condition is true if (!S_ISDIR(inode->i_mode)) { ^ include/uapi/linux/stat.h:23:21: note: expanded from macro 'S_ISDIR' #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) ^ include/linux/compiler.h:56:47: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ fs/ext4/inline.c:1249:2: note: '?' condition is false if (!S_ISDIR(inode->i_mode)) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ fs/ext4/inline.c:1249:2: note: '?' condition is false if (!S_ISDIR(inode->i_mode)) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value' (cond) ? \ ^ fs/ext4/inline.c:1249:2: note: Taking false branch if (!S_ISDIR(inode->i_mode)) { ^ include/linux/compiler.h:56:23: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ fs/ext4/inline.c:1255:11: note: Calling 'ext4_finish_convert_inline_dir' error = ext4_finish_convert_inline_dir(handle, inode, data_bh, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fs/ext4/inline.c:1156:7: note: 5th function call argument is an uninitialized value de = ext4_init_dot_dotdot(inode, de, ^ >> fs/ext4/inline.c:1386:13: warning: Assigned value is garbage or undefined [clang-analyzer-core.uninitialized.Assign] parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode); ^ fs/ext4/inline.c:1362:2: note: Assuming 'ret' is 0 if (ret) ^ include/linux/compiler.h:56:45: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ fs/ext4/inline.c:1362:2: note: '?' condition is false if (ret) ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ fs/ext4/inline.c:1362:6: note: 'ret' is 0 if (ret) ^ include/linux/compiler.h:56:47: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^~~~ include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value' (cond) ? \ ^~~~ fs/ext4/inline.c:1362:2: note: '?' condition is false if (ret) ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value' (cond) ? \ ^ fs/ext4/inline.c:1362:2: note: Taking false branch if (ret) ^ include/linux/compiler.h:56:23: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ fs/ext4/inline.c:1366:2: note: '?' condition is false if (!ext4_has_inline_data(inode)) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:31: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ fs/ext4/inline.c:1366:6: note: Assuming the condition is false if (!ext4_has_inline_data(inode)) { ^ include/linux/compiler.h:56:47: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^~~~ include/linux/compiler.h:58:86: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^~~~ include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value' (cond) ? \ ^~~~ fs/ext4/inline.c:1366:2: note: '?' condition is false if (!ext4_has_inline_data(inode)) { ^ include/linux/compiler.h:56:28: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ include/linux/compiler.h:58:69: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) ^ include/linux/compiler.h:69:2: note: expanded from macro '__trace_if_value' (cond) ? \ ^ fs/ext4/inline.c:1366:2: note: Taking false branch if (!ext4_has_inline_data(inode)) { ^ include/linux/compiler.h:56:23: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^ fs/ext4/inline.c:1373:12: note: Uninitialized value stored to field 'inode' dir_buf = kmalloc(inline_size, GFP_NOFS); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fs/ext4/inline.c:1374:6: note: Assuming 'dir_buf' is non-null if (!dir_buf) { ^ include/linux/compiler.h:56:47: note: expanded from macro 'if' #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) ) ^~~~ include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var' #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond)) vim +1386 fs/ext4/inline.c 3c47d54170b6a6 Tao Ma 2012-12-10 1184 3c47d54170b6a6 Tao Ma 2012-12-10 1185 static int ext4_convert_inline_data_nolock(handle_t *handle, 3c47d54170b6a6 Tao Ma 2012-12-10 1186 struct inode *inode, 3c47d54170b6a6 Tao Ma 2012-12-10 1187 struct ext4_iloc *iloc) 3c47d54170b6a6 Tao Ma 2012-12-10 1188 { 3c47d54170b6a6 Tao Ma 2012-12-10 1189 int error; 3c47d54170b6a6 Tao Ma 2012-12-10 1190 void *buf = NULL; 3c47d54170b6a6 Tao Ma 2012-12-10 1191 struct buffer_head *data_bh = NULL; 3c47d54170b6a6 Tao Ma 2012-12-10 1192 struct ext4_map_blocks map; 3c47d54170b6a6 Tao Ma 2012-12-10 1193 int inline_size; 3c47d54170b6a6 Tao Ma 2012-12-10 1194 3c47d54170b6a6 Tao Ma 2012-12-10 1195 inline_size = ext4_get_inline_size(inode); 3c47d54170b6a6 Tao Ma 2012-12-10 1196 buf = kmalloc(inline_size, GFP_NOFS); 3c47d54170b6a6 Tao Ma 2012-12-10 1197 if (!buf) { 3c47d54170b6a6 Tao Ma 2012-12-10 1198 error = -ENOMEM; 3c47d54170b6a6 Tao Ma 2012-12-10 1199 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1200 } 3c47d54170b6a6 Tao Ma 2012-12-10 1201 3c47d54170b6a6 Tao Ma 2012-12-10 1202 error = ext4_read_inline_data(inode, buf, inline_size, iloc); 3c47d54170b6a6 Tao Ma 2012-12-10 1203 if (error < 0) 3c47d54170b6a6 Tao Ma 2012-12-10 1204 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1205 40b163f1c45f52 Darrick J. Wong 2014-07-28 1206 /* 40b163f1c45f52 Darrick J. Wong 2014-07-28 1207 * Make sure the inline directory entries pass checks before we try to 40b163f1c45f52 Darrick J. Wong 2014-07-28 1208 * convert them, so that we avoid touching stuff that needs fsck. 40b163f1c45f52 Darrick J. Wong 2014-07-28 1209 */ 40b163f1c45f52 Darrick J. Wong 2014-07-28 1210 if (S_ISDIR(inode->i_mode)) { 40b163f1c45f52 Darrick J. Wong 2014-07-28 1211 error = ext4_check_all_de(inode, iloc->bh, 40b163f1c45f52 Darrick J. Wong 2014-07-28 1212 buf + EXT4_INLINE_DOTDOT_SIZE, 40b163f1c45f52 Darrick J. Wong 2014-07-28 1213 inline_size - EXT4_INLINE_DOTDOT_SIZE); 40b163f1c45f52 Darrick J. Wong 2014-07-28 1214 if (error) 40b163f1c45f52 Darrick J. Wong 2014-07-28 1215 goto out; 40b163f1c45f52 Darrick J. Wong 2014-07-28 1216 } 40b163f1c45f52 Darrick J. Wong 2014-07-28 1217 3c47d54170b6a6 Tao Ma 2012-12-10 1218 error = ext4_destroy_inline_data_nolock(handle, inode); 3c47d54170b6a6 Tao Ma 2012-12-10 1219 if (error) 3c47d54170b6a6 Tao Ma 2012-12-10 1220 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1221 3c47d54170b6a6 Tao Ma 2012-12-10 1222 map.m_lblk = 0; 3c47d54170b6a6 Tao Ma 2012-12-10 1223 map.m_len = 1; 3c47d54170b6a6 Tao Ma 2012-12-10 1224 map.m_flags = 0; 3c47d54170b6a6 Tao Ma 2012-12-10 1225 error = ext4_map_blocks(handle, inode, &map, EXT4_GET_BLOCKS_CREATE); 3c47d54170b6a6 Tao Ma 2012-12-10 1226 if (error < 0) 3c47d54170b6a6 Tao Ma 2012-12-10 1227 goto out_restore; 3c47d54170b6a6 Tao Ma 2012-12-10 1228 if (!(map.m_flags & EXT4_MAP_MAPPED)) { 3c47d54170b6a6 Tao Ma 2012-12-10 1229 error = -EIO; 3c47d54170b6a6 Tao Ma 2012-12-10 1230 goto out_restore; 3c47d54170b6a6 Tao Ma 2012-12-10 1231 } 3c47d54170b6a6 Tao Ma 2012-12-10 1232 3c47d54170b6a6 Tao Ma 2012-12-10 1233 data_bh = sb_getblk(inode->i_sb, map.m_pblk); 3c47d54170b6a6 Tao Ma 2012-12-10 1234 if (!data_bh) { 860d21e2c585f7 Theodore Ts'o 2013-01-12 1235 error = -ENOMEM; 3c47d54170b6a6 Tao Ma 2012-12-10 1236 goto out_restore; 3c47d54170b6a6 Tao Ma 2012-12-10 1237 } 3c47d54170b6a6 Tao Ma 2012-12-10 1238 3c47d54170b6a6 Tao Ma 2012-12-10 1239 lock_buffer(data_bh); 188c299e2a26cc Jan Kara 2021-08-16 1240 error = ext4_journal_get_create_access(handle, inode->i_sb, data_bh, 188c299e2a26cc Jan Kara 2021-08-16 1241 EXT4_JTR_NONE); 3c47d54170b6a6 Tao Ma 2012-12-10 1242 if (error) { 3c47d54170b6a6 Tao Ma 2012-12-10 1243 unlock_buffer(data_bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1244 error = -EIO; 3c47d54170b6a6 Tao Ma 2012-12-10 1245 goto out_restore; 3c47d54170b6a6 Tao Ma 2012-12-10 1246 } 3c47d54170b6a6 Tao Ma 2012-12-10 1247 memset(data_bh->b_data, 0, inode->i_sb->s_blocksize); 3c47d54170b6a6 Tao Ma 2012-12-10 1248 3c47d54170b6a6 Tao Ma 2012-12-10 1249 if (!S_ISDIR(inode->i_mode)) { 3c47d54170b6a6 Tao Ma 2012-12-10 1250 memcpy(data_bh->b_data, buf, inline_size); 3c47d54170b6a6 Tao Ma 2012-12-10 1251 set_buffer_uptodate(data_bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1252 error = ext4_handle_dirty_metadata(handle, 3c47d54170b6a6 Tao Ma 2012-12-10 1253 inode, data_bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1254 } else { 3c47d54170b6a6 Tao Ma 2012-12-10 @1255 error = ext4_finish_convert_inline_dir(handle, inode, data_bh, 3c47d54170b6a6 Tao Ma 2012-12-10 1256 buf, inline_size); 3c47d54170b6a6 Tao Ma 2012-12-10 1257 } 3c47d54170b6a6 Tao Ma 2012-12-10 1258 3c47d54170b6a6 Tao Ma 2012-12-10 1259 unlock_buffer(data_bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1260 out_restore: 3c47d54170b6a6 Tao Ma 2012-12-10 1261 if (error) 3c47d54170b6a6 Tao Ma 2012-12-10 1262 ext4_restore_inline_data(handle, inode, iloc, buf, inline_size); 3c47d54170b6a6 Tao Ma 2012-12-10 1263 3c47d54170b6a6 Tao Ma 2012-12-10 1264 out: 3c47d54170b6a6 Tao Ma 2012-12-10 1265 brelse(data_bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1266 kfree(buf); 3c47d54170b6a6 Tao Ma 2012-12-10 1267 return error; 3c47d54170b6a6 Tao Ma 2012-12-10 1268 } 3c47d54170b6a6 Tao Ma 2012-12-10 1269 3c47d54170b6a6 Tao Ma 2012-12-10 1270 /* 3c47d54170b6a6 Tao Ma 2012-12-10 1271 * Try to add the new entry to the inline data. 3c47d54170b6a6 Tao Ma 2012-12-10 1272 * If succeeds, return 0. If not, extended the inline dir and copied data to 3c47d54170b6a6 Tao Ma 2012-12-10 1273 * the new created block. 3c47d54170b6a6 Tao Ma 2012-12-10 1274 */ 5b643f9ce34df9 Theodore Ts'o 2015-05-18 1275 int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname, 56a04915df4e85 Theodore Ts'o 2016-01-08 1276 struct inode *dir, struct inode *inode) 3c47d54170b6a6 Tao Ma 2012-12-10 1277 { 4209ae12b12265 Harshad Shirwadkar 2020-04-26 1278 int ret, ret2, inline_size, no_expand; 3c47d54170b6a6 Tao Ma 2012-12-10 1279 void *inline_start; 3c47d54170b6a6 Tao Ma 2012-12-10 1280 struct ext4_iloc iloc; 3c47d54170b6a6 Tao Ma 2012-12-10 1281 3c47d54170b6a6 Tao Ma 2012-12-10 1282 ret = ext4_get_inode_loc(dir, &iloc); 3c47d54170b6a6 Tao Ma 2012-12-10 1283 if (ret) 3c47d54170b6a6 Tao Ma 2012-12-10 1284 return ret; 3c47d54170b6a6 Tao Ma 2012-12-10 1285 c755e251357a0c Theodore Ts'o 2017-01-11 1286 ext4_write_lock_xattr(dir, &no_expand); 3c47d54170b6a6 Tao Ma 2012-12-10 1287 if (!ext4_has_inline_data(dir)) 3c47d54170b6a6 Tao Ma 2012-12-10 1288 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1289 3c47d54170b6a6 Tao Ma 2012-12-10 1290 inline_start = (void *)ext4_raw_inode(&iloc)->i_block + 3c47d54170b6a6 Tao Ma 2012-12-10 1291 EXT4_INLINE_DOTDOT_SIZE; 3c47d54170b6a6 Tao Ma 2012-12-10 1292 inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE; 3c47d54170b6a6 Tao Ma 2012-12-10 1293 56a04915df4e85 Theodore Ts'o 2016-01-08 1294 ret = ext4_add_dirent_to_inline(handle, fname, dir, inode, &iloc, 3c47d54170b6a6 Tao Ma 2012-12-10 1295 inline_start, inline_size); 3c47d54170b6a6 Tao Ma 2012-12-10 1296 if (ret != -ENOSPC) 3c47d54170b6a6 Tao Ma 2012-12-10 1297 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1298 3c47d54170b6a6 Tao Ma 2012-12-10 1299 /* check whether it can be inserted to inline xattr space. */ 3c47d54170b6a6 Tao Ma 2012-12-10 1300 inline_size = EXT4_I(dir)->i_inline_size - 3c47d54170b6a6 Tao Ma 2012-12-10 1301 EXT4_MIN_INLINE_DATA_SIZE; 3c47d54170b6a6 Tao Ma 2012-12-10 1302 if (!inline_size) { 3c47d54170b6a6 Tao Ma 2012-12-10 1303 /* Try to use the xattr space.*/ 3c47d54170b6a6 Tao Ma 2012-12-10 1304 ret = ext4_update_inline_dir(handle, dir, &iloc); 3c47d54170b6a6 Tao Ma 2012-12-10 1305 if (ret && ret != -ENOSPC) 3c47d54170b6a6 Tao Ma 2012-12-10 1306 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1307 3c47d54170b6a6 Tao Ma 2012-12-10 1308 inline_size = EXT4_I(dir)->i_inline_size - 3c47d54170b6a6 Tao Ma 2012-12-10 1309 EXT4_MIN_INLINE_DATA_SIZE; 3c47d54170b6a6 Tao Ma 2012-12-10 1310 } 3c47d54170b6a6 Tao Ma 2012-12-10 1311 3c47d54170b6a6 Tao Ma 2012-12-10 1312 if (inline_size) { 3c47d54170b6a6 Tao Ma 2012-12-10 1313 inline_start = ext4_get_inline_xattr_pos(dir, &iloc); 3c47d54170b6a6 Tao Ma 2012-12-10 1314 56a04915df4e85 Theodore Ts'o 2016-01-08 1315 ret = ext4_add_dirent_to_inline(handle, fname, dir, 5b643f9ce34df9 Theodore Ts'o 2015-05-18 1316 inode, &iloc, inline_start, 5b643f9ce34df9 Theodore Ts'o 2015-05-18 1317 inline_size); 3c47d54170b6a6 Tao Ma 2012-12-10 1318 3c47d54170b6a6 Tao Ma 2012-12-10 1319 if (ret != -ENOSPC) 3c47d54170b6a6 Tao Ma 2012-12-10 1320 goto out; 3c47d54170b6a6 Tao Ma 2012-12-10 1321 } 3c47d54170b6a6 Tao Ma 2012-12-10 1322 3c47d54170b6a6 Tao Ma 2012-12-10 1323 /* 3c47d54170b6a6 Tao Ma 2012-12-10 1324 * The inline space is filled up, so create a new block for it. 3c47d54170b6a6 Tao Ma 2012-12-10 1325 * As the extent tree will be created, we have to save the inline 3c47d54170b6a6 Tao Ma 2012-12-10 1326 * dir first. 3c47d54170b6a6 Tao Ma 2012-12-10 1327 */ 3c47d54170b6a6 Tao Ma 2012-12-10 1328 ret = ext4_convert_inline_data_nolock(handle, dir, &iloc); 3c47d54170b6a6 Tao Ma 2012-12-10 1329 3c47d54170b6a6 Tao Ma 2012-12-10 1330 out: c755e251357a0c Theodore Ts'o 2017-01-11 1331 ext4_write_unlock_xattr(dir, &no_expand); 4209ae12b12265 Harshad Shirwadkar 2020-04-26 1332 ret2 = ext4_mark_inode_dirty(handle, dir); 4209ae12b12265 Harshad Shirwadkar 2020-04-26 1333 if (unlikely(ret2 && !ret)) 4209ae12b12265 Harshad Shirwadkar 2020-04-26 1334 ret = ret2; 3c47d54170b6a6 Tao Ma 2012-12-10 1335 brelse(iloc.bh); 3c47d54170b6a6 Tao Ma 2012-12-10 1336 return ret; 3c47d54170b6a6 Tao Ma 2012-12-10 1337 } 3c47d54170b6a6 Tao Ma 2012-12-10 1338 8af0f082279770 Tao Ma 2013-04-19 1339 /* 8af0f082279770 Tao Ma 2013-04-19 1340 * This function fills a red-black tree with information from an 8af0f082279770 Tao Ma 2013-04-19 1341 * inlined dir. It returns the number directory entries loaded 8af0f082279770 Tao Ma 2013-04-19 1342 * into the tree. If there is an error it is returned in err. 8af0f082279770 Tao Ma 2013-04-19 1343 */ 7633b08b275051 Theodore Ts'o 2019-06-21 1344 int ext4_inlinedir_to_tree(struct file *dir_file, 8af0f082279770 Tao Ma 2013-04-19 1345 struct inode *dir, ext4_lblk_t block, 8af0f082279770 Tao Ma 2013-04-19 1346 struct dx_hash_info *hinfo, 8af0f082279770 Tao Ma 2013-04-19 1347 __u32 start_hash, __u32 start_minor_hash, 8af0f082279770 Tao Ma 2013-04-19 1348 int *has_inline_data) 8af0f082279770 Tao Ma 2013-04-19 1349 { 8af0f082279770 Tao Ma 2013-04-19 1350 int err = 0, count = 0; 8af0f082279770 Tao Ma 2013-04-19 1351 unsigned int parent_ino; 8af0f082279770 Tao Ma 2013-04-19 1352 int pos; 8af0f082279770 Tao Ma 2013-04-19 1353 struct ext4_dir_entry_2 *de; 8af0f082279770 Tao Ma 2013-04-19 1354 struct inode *inode = file_inode(dir_file); 8af0f082279770 Tao Ma 2013-04-19 1355 int ret, inline_size = 0; 8af0f082279770 Tao Ma 2013-04-19 1356 struct ext4_iloc iloc; 8af0f082279770 Tao Ma 2013-04-19 1357 void *dir_buf = NULL; 8af0f082279770 Tao Ma 2013-04-19 1358 struct ext4_dir_entry_2 fake; a7550b30ab709f Jaegeuk Kim 2016-07-10 1359 struct fscrypt_str tmp_str; 8af0f082279770 Tao Ma 2013-04-19 1360 8af0f082279770 Tao Ma 2013-04-19 1361 ret = ext4_get_inode_loc(inode, &iloc); 8af0f082279770 Tao Ma 2013-04-19 1362 if (ret) 8af0f082279770 Tao Ma 2013-04-19 1363 return ret; 8af0f082279770 Tao Ma 2013-04-19 1364 8af0f082279770 Tao Ma 2013-04-19 1365 down_read(&EXT4_I(inode)->xattr_sem); 8af0f082279770 Tao Ma 2013-04-19 1366 if (!ext4_has_inline_data(inode)) { 8af0f082279770 Tao Ma 2013-04-19 1367 up_read(&EXT4_I(inode)->xattr_sem); 8af0f082279770 Tao Ma 2013-04-19 1368 *has_inline_data = 0; 8af0f082279770 Tao Ma 2013-04-19 1369 goto out; 8af0f082279770 Tao Ma 2013-04-19 1370 } 8af0f082279770 Tao Ma 2013-04-19 1371 8af0f082279770 Tao Ma 2013-04-19 1372 inline_size = ext4_get_inline_size(inode); 8af0f082279770 Tao Ma 2013-04-19 1373 dir_buf = kmalloc(inline_size, GFP_NOFS); 8af0f082279770 Tao Ma 2013-04-19 1374 if (!dir_buf) { 8af0f082279770 Tao Ma 2013-04-19 1375 ret = -ENOMEM; 8af0f082279770 Tao Ma 2013-04-19 1376 up_read(&EXT4_I(inode)->xattr_sem); 8af0f082279770 Tao Ma 2013-04-19 1377 goto out; 8af0f082279770 Tao Ma 2013-04-19 1378 } 8af0f082279770 Tao Ma 2013-04-19 1379 8af0f082279770 Tao Ma 2013-04-19 1380 ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc); 8af0f082279770 Tao Ma 2013-04-19 1381 up_read(&EXT4_I(inode)->xattr_sem); 8af0f082279770 Tao Ma 2013-04-19 1382 if (ret < 0) 8af0f082279770 Tao Ma 2013-04-19 1383 goto out; 8af0f082279770 Tao Ma 2013-04-19 1384 8af0f082279770 Tao Ma 2013-04-19 1385 pos = 0; 8af0f082279770 Tao Ma 2013-04-19 @1386 parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode); 8af0f082279770 Tao Ma 2013-04-19 1387 while (pos < inline_size) { 8af0f082279770 Tao Ma 2013-04-19 1388 /* 8af0f082279770 Tao Ma 2013-04-19 1389 * As inlined dir doesn't store any information about '.' and 8af0f082279770 Tao Ma 2013-04-19 1390 * only the inode number of '..' is stored, we have to handle 8af0f082279770 Tao Ma 2013-04-19 1391 * them differently. 8af0f082279770 Tao Ma 2013-04-19 1392 */ 8af0f082279770 Tao Ma 2013-04-19 1393 if (pos == 0) { 8af0f082279770 Tao Ma 2013-04-19 1394 fake.inode = cpu_to_le32(inode->i_ino); 8af0f082279770 Tao Ma 2013-04-19 1395 fake.name_len = 1; 8af0f082279770 Tao Ma 2013-04-19 1396 strcpy(fake.name, "."); 8af0f082279770 Tao Ma 2013-04-19 1397 fake.rec_len = ext4_rec_len_to_disk( 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1398 ext4_dir_rec_len(fake.name_len, NULL), 8af0f082279770 Tao Ma 2013-04-19 1399 inline_size); 8af0f082279770 Tao Ma 2013-04-19 1400 ext4_set_de_type(inode->i_sb, &fake, S_IFDIR); 8af0f082279770 Tao Ma 2013-04-19 1401 de = &fake; 8af0f082279770 Tao Ma 2013-04-19 1402 pos = EXT4_INLINE_DOTDOT_OFFSET; 8af0f082279770 Tao Ma 2013-04-19 1403 } else if (pos == EXT4_INLINE_DOTDOT_OFFSET) { 8af0f082279770 Tao Ma 2013-04-19 1404 fake.inode = cpu_to_le32(parent_ino); 8af0f082279770 Tao Ma 2013-04-19 1405 fake.name_len = 2; 8af0f082279770 Tao Ma 2013-04-19 1406 strcpy(fake.name, ".."); 8af0f082279770 Tao Ma 2013-04-19 1407 fake.rec_len = ext4_rec_len_to_disk( 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1408 ext4_dir_rec_len(fake.name_len, NULL), 8af0f082279770 Tao Ma 2013-04-19 1409 inline_size); 8af0f082279770 Tao Ma 2013-04-19 1410 ext4_set_de_type(inode->i_sb, &fake, S_IFDIR); 8af0f082279770 Tao Ma 2013-04-19 1411 de = &fake; 8af0f082279770 Tao Ma 2013-04-19 1412 pos = EXT4_INLINE_DOTDOT_SIZE; 8af0f082279770 Tao Ma 2013-04-19 1413 } else { 8af0f082279770 Tao Ma 2013-04-19 1414 de = (struct ext4_dir_entry_2 *)(dir_buf + pos); 8af0f082279770 Tao Ma 2013-04-19 1415 pos += ext4_rec_len_from_disk(de->rec_len, inline_size); 8af0f082279770 Tao Ma 2013-04-19 1416 if (ext4_check_dir_entry(inode, dir_file, de, 8af0f082279770 Tao Ma 2013-04-19 1417 iloc.bh, dir_buf, 8af0f082279770 Tao Ma 2013-04-19 1418 inline_size, pos)) { 8af0f082279770 Tao Ma 2013-04-19 1419 ret = count; 8af0f082279770 Tao Ma 2013-04-19 1420 goto out; 8af0f082279770 Tao Ma 2013-04-19 1421 } 8af0f082279770 Tao Ma 2013-04-19 1422 } 8af0f082279770 Tao Ma 2013-04-19 1423 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1424 if (ext4_hash_in_dirent(dir)) { 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1425 hinfo->hash = EXT4_DIRENT_HASH(de); 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1426 hinfo->minor_hash = EXT4_DIRENT_MINOR_HASH(de); 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1427 } else { b886ee3e778ec2 Gabriel Krisman Bertazi 2019-04-25 1428 ext4fs_dirhash(dir, de->name, de->name_len, hinfo); 471fbbea7ff706 Daniel Rosenberg 2021-03-19 1429 } 8af0f082279770 Tao Ma 2013-04-19 1430 if ((hinfo->hash < start_hash) || 8af0f082279770 Tao Ma 2013-04-19 1431 ((hinfo->hash == start_hash) && 8af0f082279770 Tao Ma 2013-04-19 1432 (hinfo->minor_hash < start_minor_hash))) 8af0f082279770 Tao Ma 2013-04-19 1433 continue; 8af0f082279770 Tao Ma 2013-04-19 1434 if (de->inode == 0) 8af0f082279770 Tao Ma 2013-04-19 1435 continue; 2f61830ae33e29 Theodore Ts'o 2015-04-12 1436 tmp_str.name = de->name; 2f61830ae33e29 Theodore Ts'o 2015-04-12 1437 tmp_str.len = de->name_len; 2f61830ae33e29 Theodore Ts'o 2015-04-12 1438 err = ext4_htree_store_dirent(dir_file, hinfo->hash, 2f61830ae33e29 Theodore Ts'o 2015-04-12 1439 hinfo->minor_hash, de, &tmp_str); 8af0f082279770 Tao Ma 2013-04-19 1440 if (err) { 7a14826ede1d71 Colin Ian King 2019-08-12 1441 ret = err; 8af0f082279770 Tao Ma 2013-04-19 1442 goto out; 8af0f082279770 Tao Ma 2013-04-19 1443 } 8af0f082279770 Tao Ma 2013-04-19 1444 count++; 8af0f082279770 Tao Ma 2013-04-19 1445 } 8af0f082279770 Tao Ma 2013-04-19 1446 ret = count; 8af0f082279770 Tao Ma 2013-04-19 1447 out: 8af0f082279770 Tao Ma 2013-04-19 1448 kfree(dir_buf); 8af0f082279770 Tao Ma 2013-04-19 1449 brelse(iloc.bh); 8af0f082279770 Tao Ma 2013-04-19 1450 return ret; 8af0f082279770 Tao Ma 2013-04-19 1451 } 8af0f082279770 Tao Ma 2013-04-19 1452 :::::: The code at line 1386 was first introduced by commit :::::: 8af0f08227977079f8f227e74d27c59db2ab84f6 ext4: fix readdir error in the case of inline_data+dir_index :::::: TO: Tao Ma :::::: CC: Theodore Ts'o -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests