Skip to content

Commit c27c66a

Browse files
committed
fs/pipe: Fix pipe_occupancy() with 16-bit indexes
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 <[email protected]> Cc: Mateusz Guzik <[email protected]> Cc: Manfred Spraul <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Swapnil Sapkal <[email protected]> Cc: Alexey Gladkov <[email protected]> Cc: K Prateek Nayak <[email protected]> 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 <[email protected]>
1 parent bb2281f commit c27c66a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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)