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

Configure Feed

Select the types of activity you want to include in your feed.

ntfs: fix invalid PTR_ERR() usage in __ntfs_bitmap_set_bits_in_run()

The Smatch reported a warning in __ntfs_bitmap_set_bits_in_run():
"warn: passing a valid pointer to 'PTR_ERR'"

This occurs because the 'folio' variable might contain a valid pointer
when jumping to the 'rollback' label, specifically when 'cnt <= 0' is
detected during the subsequent page mapping loop. In such cases,
calling PTR_ERR(folio) is incorrect as it does not contain an error
code.

Fix this by introducing an explicit 'err' variable to track the error
status. This ensures that the rollback logic and the return value
consistently use a proper error code regardless of the state of the
folio pointer.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

+11 -8
+11 -8
fs/ntfs/bitmap.c
··· 125 125 struct address_space *mapping; 126 126 struct folio *folio; 127 127 u8 *kaddr; 128 - int pos, len; 128 + int pos, len, err; 129 129 u8 bit; 130 130 struct ntfs_inode *ni = NTFS_I(vi); 131 131 struct ntfs_volume *vol = ni->vol; ··· 201 201 202 202 /* If we are not in the last page, deal with all subsequent pages. */ 203 203 while (index < end_index) { 204 - if (cnt <= 0) 204 + if (cnt <= 0) { 205 + err = -EIO; 205 206 goto rollback; 207 + } 206 208 207 209 /* Update @index and get the next folio. */ 208 210 folio_mark_dirty(folio); ··· 216 214 ntfs_error(vi->i_sb, 217 215 "Failed to map subsequent page (error %li), aborting.", 218 216 PTR_ERR(folio)); 217 + err = PTR_ERR(folio); 219 218 goto rollback; 220 219 } 221 220 ··· 268 265 * - @count - @cnt is the number of bits that have been modified 269 266 */ 270 267 if (is_rollback) 271 - return PTR_ERR(folio); 268 + return err; 272 269 if (count != cnt) 273 270 pos = __ntfs_bitmap_set_bits_in_run(vi, start_bit, count - cnt, 274 271 value ? 0 : 1, true); ··· 277 274 if (!pos) { 278 275 /* Rollback was successful. */ 279 276 ntfs_error(vi->i_sb, 280 - "Failed to map subsequent page (error %li), aborting.", 281 - PTR_ERR(folio)); 277 + "Failed to map subsequent page (error %i), aborting.", 278 + err); 282 279 } else { 283 280 /* Rollback failed. */ 284 281 ntfs_error(vi->i_sb, 285 - "Failed to map subsequent page (error %li) and rollback failed (error %i). Aborting and leaving inconsistent metadata. Unmount and run chkdsk.", 286 - PTR_ERR(folio), pos); 282 + "Failed to map subsequent page (error %i) and rollback failed (error %i). Aborting and leaving inconsistent metadata. Unmount and run chkdsk.", 283 + err, pos); 287 284 NVolSetErrors(NTFS_SB(vi->i_sb)); 288 285 } 289 - return PTR_ERR(folio); 286 + return err; 290 287 }