Skip to content

Commit 412e6d3

Browse files
committed
Merge tag 'char-misc-4.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
Pull char/misc driver fixes from Greg KH: "Here are two bugfixes that resolve some reported issues. One in the firmware loader, that should fix the much-reported problem of crashes with it. The other is a hyperv fix for a reported regression. Both have been in linux-next for a week or so with no reported issues" * tag 'char-misc-4.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: Drivers: hv: vmbus: finally fix hv_need_to_signal_on_read() firmware: fix NULL pointer dereference in __fw_load_abort()
2 parents 252bf9f + 433e19c commit 412e6d3

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

drivers/base/firmware_class.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,6 @@ static void fw_load_abort(struct firmware_priv *fw_priv)
558558
struct firmware_buf *buf = fw_priv->buf;
559559

560560
__fw_load_abort(buf);
561-
562-
/* avoid user action after loading abort */
563-
fw_priv->buf = NULL;
564561
}
565562

566563
static LIST_HEAD(pending_fw_head);
@@ -713,7 +710,7 @@ static ssize_t firmware_loading_store(struct device *dev,
713710

714711
mutex_lock(&fw_lock);
715712
fw_buf = fw_priv->buf;
716-
if (!fw_buf)
713+
if (fw_state_is_aborted(&fw_buf->fw_st))
717714
goto out;
718715

719716
switch (loading) {

drivers/hv/ring_buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ int hv_ringbuffer_read(struct vmbus_channel *channel,
383383
return ret;
384384
}
385385

386+
init_cached_read_index(channel);
386387
next_read_location = hv_get_next_read_location(inring_info);
387388
next_read_location = hv_copyfrom_ringbuffer(inring_info, &desc,
388389
sizeof(desc),

drivers/net/hyperv/netvsc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ void netvsc_channel_cb(void *context)
12951295
ndev = hv_get_drvdata(device);
12961296
buffer = get_per_channel_state(channel);
12971297

1298+
/* commit_rd_index() -> hv_signal_on_read() needs this. */
1299+
init_cached_read_index(channel);
1300+
12981301
do {
12991302
desc = get_next_pkt_raw(channel);
13001303
if (desc != NULL) {
@@ -1347,6 +1350,9 @@ void netvsc_channel_cb(void *context)
13471350

13481351
bufferlen = bytes_recvd;
13491352
}
1353+
1354+
init_cached_read_index(channel);
1355+
13501356
} while (1);
13511357

13521358
if (bufferlen > NETVSC_PACKET_SIZE)

include/linux/hyperv.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct hv_ring_buffer_info {
128128
u32 ring_data_startoffset;
129129
u32 priv_write_index;
130130
u32 priv_read_index;
131+
u32 cached_read_index;
131132
};
132133

133134
/*
@@ -180,6 +181,19 @@ static inline u32 hv_get_bytes_to_write(struct hv_ring_buffer_info *rbi)
180181
return write;
181182
}
182183

184+
static inline u32 hv_get_cached_bytes_to_write(
185+
const struct hv_ring_buffer_info *rbi)
186+
{
187+
u32 read_loc, write_loc, dsize, write;
188+
189+
dsize = rbi->ring_datasize;
190+
read_loc = rbi->cached_read_index;
191+
write_loc = rbi->ring_buffer->write_index;
192+
193+
write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
194+
read_loc - write_loc;
195+
return write;
196+
}
183197
/*
184198
* VMBUS version is 32 bit entity broken up into
185199
* two 16 bit quantities: major_number. minor_number.
@@ -1488,7 +1502,7 @@ hv_get_ring_buffer(struct hv_ring_buffer_info *ring_info)
14881502

14891503
static inline void hv_signal_on_read(struct vmbus_channel *channel)
14901504
{
1491-
u32 cur_write_sz;
1505+
u32 cur_write_sz, cached_write_sz;
14921506
u32 pending_sz;
14931507
struct hv_ring_buffer_info *rbi = &channel->inbound;
14941508

@@ -1512,12 +1526,24 @@ static inline void hv_signal_on_read(struct vmbus_channel *channel)
15121526

15131527
cur_write_sz = hv_get_bytes_to_write(rbi);
15141528

1515-
if (cur_write_sz >= pending_sz)
1529+
if (cur_write_sz < pending_sz)
1530+
return;
1531+
1532+
cached_write_sz = hv_get_cached_bytes_to_write(rbi);
1533+
if (cached_write_sz < pending_sz)
15161534
vmbus_setevent(channel);
15171535

15181536
return;
15191537
}
15201538

1539+
static inline void
1540+
init_cached_read_index(struct vmbus_channel *channel)
1541+
{
1542+
struct hv_ring_buffer_info *rbi = &channel->inbound;
1543+
1544+
rbi->cached_read_index = rbi->ring_buffer->read_index;
1545+
}
1546+
15211547
/*
15221548
* An API to support in-place processing of incoming VMBUS packets.
15231549
*/
@@ -1569,6 +1595,8 @@ static inline void put_pkt_raw(struct vmbus_channel *channel,
15691595
* This call commits the read index and potentially signals the host.
15701596
* Here is the pattern for using the "in-place" consumption APIs:
15711597
*
1598+
* init_cached_read_index();
1599+
*
15721600
* while (get_next_pkt_raw() {
15731601
* process the packet "in-place";
15741602
* put_pkt_raw();

0 commit comments

Comments
 (0)