Skip to content

Commit 0487426

Browse files
shemmingerdavem330
authored andcommitted
vmbus: make hv_get_ringbuffer_availbytes local
The last use of hv_get_ringbuffer_availbytes in drivers is now gone. Only used by the debug info routine so make it static. Also, add READ_ONCE() to avoid any possible issues with potentially volatile index values. Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f5a2255 commit 0487426

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

drivers/hv/ring_buffer.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ static u32 hv_copyto_ringbuffer(
140140
return start_write_offset;
141141
}
142142

143+
/*
144+
*
145+
* hv_get_ringbuffer_availbytes()
146+
*
147+
* Get number of bytes available to read and to write to
148+
* for the specified ring buffer
149+
*/
150+
static void
151+
hv_get_ringbuffer_availbytes(const struct hv_ring_buffer_info *rbi,
152+
u32 *read, u32 *write)
153+
{
154+
u32 read_loc, write_loc, dsize;
155+
156+
/* Capture the read/write indices before they changed */
157+
read_loc = READ_ONCE(rbi->ring_buffer->read_index);
158+
write_loc = READ_ONCE(rbi->ring_buffer->write_index);
159+
dsize = rbi->ring_datasize;
160+
161+
*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
162+
read_loc - write_loc;
163+
*read = dsize - *write;
164+
}
165+
143166
/* Get various debug metrics for the specified ring buffer. */
144167
void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
145168
struct hv_ring_buffer_debug_info *debug_info)

include/linux/hyperv.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,6 @@ struct hv_ring_buffer_info {
127127
u32 priv_read_index;
128128
};
129129

130-
/*
131-
*
132-
* hv_get_ringbuffer_availbytes()
133-
*
134-
* Get number of bytes available to read and to write to
135-
* for the specified ring buffer
136-
*/
137-
static inline void
138-
hv_get_ringbuffer_availbytes(const struct hv_ring_buffer_info *rbi,
139-
u32 *read, u32 *write)
140-
{
141-
u32 read_loc, write_loc, dsize;
142-
143-
/* Capture the read/write indices before they changed */
144-
read_loc = rbi->ring_buffer->read_index;
145-
write_loc = rbi->ring_buffer->write_index;
146-
dsize = rbi->ring_datasize;
147-
148-
*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
149-
read_loc - write_loc;
150-
*read = dsize - *write;
151-
}
152130

153131
static inline u32 hv_get_bytes_to_read(const struct hv_ring_buffer_info *rbi)
154132
{

0 commit comments

Comments
 (0)