Skip to content

Commit 0e7bd77

Browse files
torvaldsopsiff
authored andcommitted
fs/pipe: Fix pipe_occupancy() with 16-bit indexes
mainline inclusion from mainline-v6.14-rc6 category: bugfix The pipe_occupancy() logic implicitly relied on the natural unsigned modulo arithmetic in C, but that doesn't work for the new 'pipe_index_t' case, since any arithmetic will be done in 'int' (and here we had also made it 'unsigned int' due to the function call boundary). So make the modulo arithmetic explicit by casting the result to the proper type. Cc: Oleg Nesterov <oleg@redhat.com> Cc: Mateusz Guzik <mjguzik@gmail.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Swapnil Sapkal <swapnil.sapkal@amd.com> Cc: Alexey Gladkov <legion@kernel.org> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Link: https://lore.kernel.org/all/CAHk-=wjyHsGLx=rxg6PKYBNkPYAejgo7=CbyL3=HGLZLsAaJFQ@mail.gmail.com/ Fixes: 3d25216 ("fs/pipe: Read pipe->{head,tail} atomically outside pipe->mutex") Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry picked from commit c27c66a) Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Change-Id: I0d0bb4c768cd56ae5054a972a70d432a1099fd83
1 parent 2380c48 commit 0e7bd77

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

include/linux/pipe_fs_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static inline bool pipe_empty(unsigned int head, unsigned int tail)
192192
*/
193193
static inline unsigned int pipe_occupancy(unsigned int head, unsigned int tail)
194194
{
195-
return head - tail;
195+
return (pipe_index_t)(head - tail);
196196
}
197197

198198
/**

0 commit comments

Comments
 (0)