Skip to content

Commit 37d369f

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
fs: Add uoff_t
In a recent commit, I inadvertently changed a comparison from being an unsigned comparison (on 64-bit systems) to being a signed comparison (which it had always been on 32-bit systems). This led to a sporadic fstests failure. To make sure this comparison is always unsigned, introduce a new type, uoff_t which is the unsigned version of loff_t. Generally file sizes are restricted to being a signed integer, but in these two places it is convenient to pass -1 to indicate "up to the end of the file". Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Link: https://patch.msgid.link/20251123220518.1447261-1-willy@infradead.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a77a595 commit 37d369f

6 files changed

Lines changed: 11 additions & 9 deletions

File tree

include/linux/mm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,10 +3495,10 @@ struct vm_unmapped_area_info {
34953495
extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info);
34963496

34973497
/* truncate.c */
3498-
extern void truncate_inode_pages(struct address_space *, loff_t);
3499-
extern void truncate_inode_pages_range(struct address_space *,
3500-
loff_t lstart, loff_t lend);
3501-
extern void truncate_inode_pages_final(struct address_space *);
3498+
void truncate_inode_pages(struct address_space *mapping, loff_t lstart);
3499+
void truncate_inode_pages_range(struct address_space *mapping, loff_t lstart,
3500+
uoff_t lend);
3501+
void truncate_inode_pages_final(struct address_space *mapping);
35023502

35033503
/* generic vm_area_ops exported for stackable file systems */
35043504
extern vm_fault_t filemap_fault(struct vm_fault *vmf);

include/linux/shmem_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
111111
pgoff_t index, gfp_t gfp_mask);
112112
int shmem_writeout(struct folio *folio, struct swap_iocb **plug,
113113
struct list_head *folio_list);
114-
void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);
114+
void shmem_truncate_range(struct inode *inode, loff_t start, uoff_t end);
115115
int shmem_unuse(unsigned int type);
116116

117117
#ifdef CONFIG_TRANSPARENT_HUGEPAGE

include/linux/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef __kernel_old_gid_t old_gid_t;
5050

5151
#if defined(__GNUC__)
5252
typedef __kernel_loff_t loff_t;
53+
typedef __kernel_uoff_t uoff_t;
5354
#endif
5455

5556
/*

include/uapi/asm-generic/posix_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ typedef struct {
8686
*/
8787
typedef __kernel_long_t __kernel_off_t;
8888
typedef long long __kernel_loff_t;
89+
typedef unsigned long long __kernel_uoff_t;
8990
typedef __kernel_long_t __kernel_old_time_t;
9091
#ifndef __KERNEL__
9192
typedef __kernel_long_t __kernel_time_t;

mm/shmem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index)
10761076
* Remove range of pages and swap entries from page cache, and free them.
10771077
* If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate.
10781078
*/
1079-
static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
1079+
static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend,
10801080
bool unfalloc)
10811081
{
10821082
struct address_space *mapping = inode->i_mapping;
@@ -1227,7 +1227,7 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
12271227
shmem_recalc_inode(inode, 0, -nr_swaps_freed);
12281228
}
12291229

1230-
void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
1230+
void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
12311231
{
12321232
shmem_undo_range(inode, lstart, lend, false);
12331233
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
@@ -5776,7 +5776,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
57765776
}
57775777
#endif
57785778

5779-
void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)
5779+
void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
57805780
{
57815781
truncate_inode_pages_range(inode->i_mapping, lstart, lend);
57825782
}

mm/truncate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ long mapping_evict_folio(struct address_space *mapping, struct folio *folio)
339339
* page aligned properly.
340340
*/
341341
void truncate_inode_pages_range(struct address_space *mapping,
342-
loff_t lstart, loff_t lend)
342+
loff_t lstart, uoff_t lend)
343343
{
344344
pgoff_t start; /* inclusive */
345345
pgoff_t end; /* exclusive */

0 commit comments

Comments
 (0)