Skip to content

Commit fc96df1

Browse files
dcuiSasha Levin
authored andcommitted
Drivers: hv: vmbus: Return -EINVAL for the sys files for unopened channels
Before 98f4c65, we returned zeros for unopened channels. With 98f4c65, we started to return random on-stack values. We'd better return -EINVAL instead. Fixes: 98f4c65 ("hv: move ringbuffer bus attributes to dev_groups") Cc: stable@vger.kernel.org Cc: K. Y. Srinivasan <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Stephen Hemminger <sthemmin@microsoft.com> Signed-off-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c629421 commit fc96df1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ static ssize_t out_intr_mask_show(struct device *dev,
316316

317317
if (!hv_dev->channel)
318318
return -ENODEV;
319+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
320+
return -EINVAL;
319321
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
320322
return sprintf(buf, "%d\n", outbound.current_interrupt_mask);
321323
}
@@ -329,6 +331,8 @@ static ssize_t out_read_index_show(struct device *dev,
329331

330332
if (!hv_dev->channel)
331333
return -ENODEV;
334+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
335+
return -EINVAL;
332336
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
333337
return sprintf(buf, "%d\n", outbound.current_read_index);
334338
}
@@ -343,6 +347,8 @@ static ssize_t out_write_index_show(struct device *dev,
343347

344348
if (!hv_dev->channel)
345349
return -ENODEV;
350+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
351+
return -EINVAL;
346352
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
347353
return sprintf(buf, "%d\n", outbound.current_write_index);
348354
}
@@ -357,6 +363,8 @@ static ssize_t out_read_bytes_avail_show(struct device *dev,
357363

358364
if (!hv_dev->channel)
359365
return -ENODEV;
366+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
367+
return -EINVAL;
360368
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
361369
return sprintf(buf, "%d\n", outbound.bytes_avail_toread);
362370
}
@@ -371,6 +379,8 @@ static ssize_t out_write_bytes_avail_show(struct device *dev,
371379

372380
if (!hv_dev->channel)
373381
return -ENODEV;
382+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
383+
return -EINVAL;
374384
hv_ringbuffer_get_debuginfo(&hv_dev->channel->outbound, &outbound);
375385
return sprintf(buf, "%d\n", outbound.bytes_avail_towrite);
376386
}
@@ -384,6 +394,8 @@ static ssize_t in_intr_mask_show(struct device *dev,
384394

385395
if (!hv_dev->channel)
386396
return -ENODEV;
397+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
398+
return -EINVAL;
387399
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
388400
return sprintf(buf, "%d\n", inbound.current_interrupt_mask);
389401
}
@@ -397,6 +409,8 @@ static ssize_t in_read_index_show(struct device *dev,
397409

398410
if (!hv_dev->channel)
399411
return -ENODEV;
412+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
413+
return -EINVAL;
400414
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
401415
return sprintf(buf, "%d\n", inbound.current_read_index);
402416
}
@@ -410,6 +424,8 @@ static ssize_t in_write_index_show(struct device *dev,
410424

411425
if (!hv_dev->channel)
412426
return -ENODEV;
427+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
428+
return -EINVAL;
413429
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
414430
return sprintf(buf, "%d\n", inbound.current_write_index);
415431
}
@@ -424,6 +440,8 @@ static ssize_t in_read_bytes_avail_show(struct device *dev,
424440

425441
if (!hv_dev->channel)
426442
return -ENODEV;
443+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
444+
return -EINVAL;
427445
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
428446
return sprintf(buf, "%d\n", inbound.bytes_avail_toread);
429447
}
@@ -438,6 +456,8 @@ static ssize_t in_write_bytes_avail_show(struct device *dev,
438456

439457
if (!hv_dev->channel)
440458
return -ENODEV;
459+
if (hv_dev->channel->state != CHANNEL_OPENED_STATE)
460+
return -EINVAL;
441461
hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
442462
return sprintf(buf, "%d\n", inbound.bytes_avail_towrite);
443463
}

0 commit comments

Comments
 (0)