* [patch] virtio: silence uninitialized variable warnings
@ 2016-04-01 11:02 Dan Carpenter
2016-04-15 14:45 ` [patch] virtio: Silence uninitialized variable warning Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-04-01 11:02 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: virtualization, linux-kernel, kernel-janitors
Most ->get() functions seem to call BUG_ON() if offset + len is out of
range, but rproc_virtio_get() returns early without initializing ret.
Presumably it can't actually happen but it leads to a static checker
warning. Let's just initialize "ret".
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 6e6cb0c9..597dbef 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -334,7 +334,7 @@ static inline void virtio_cread_bytes(struct virtio_device *vdev,
static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
{
- u8 ret;
+ u8 ret = 0;
vdev->config->get(vdev, offset, &ret, sizeof(ret));
return ret;
}
@@ -348,7 +348,7 @@ static inline void virtio_cwrite8(struct virtio_device *vdev,
static inline u16 virtio_cread16(struct virtio_device *vdev,
unsigned int offset)
{
- u16 ret;
+ u16 ret = 0;
vdev->config->get(vdev, offset, &ret, sizeof(ret));
return virtio16_to_cpu(vdev, (__force __virtio16)ret);
}
@@ -363,7 +363,7 @@ static inline void virtio_cwrite16(struct virtio_device *vdev,
static inline u32 virtio_cread32(struct virtio_device *vdev,
unsigned int offset)
{
- u32 ret;
+ u32 ret = 0;
vdev->config->get(vdev, offset, &ret, sizeof(ret));
return virtio32_to_cpu(vdev, (__force __virtio32)ret);
}
@@ -378,7 +378,7 @@ static inline void virtio_cwrite32(struct virtio_device *vdev,
static inline u64 virtio_cread64(struct virtio_device *vdev,
unsigned int offset)
{
- u64 ret;
+ u64 ret = 0;
__virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
return virtio64_to_cpu(vdev, (__force __virtio64)ret);
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [patch] virtio: Silence uninitialized variable warning
2016-04-01 11:02 [patch] virtio: silence uninitialized variable warnings Dan Carpenter
@ 2016-04-15 14:45 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2016-04-15 14:45 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: virtualization, linux-kernel, kernel-janitors
Smatch complains that we might not initialize "queue". The issue is
callers like setup_vq() from virtio_pci_modern.c where "num" could be
something like 2 and "vring_align" is 64. In that case, vring_size() is
less than PAGE_SIZE. It won't happen in real life, but we're getting
the value of "num" from a register so it's not really possible to tell
what value it holds with static analysis.
Let's just silence the warning.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 5c802d4..ca6bfdd 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1006,7 +1006,7 @@ struct virtqueue *vring_create_virtqueue(
const char *name)
{
struct virtqueue *vq;
- void *queue;
+ void *queue = NULL;
dma_addr_t dma_addr;
size_t queue_size_in_bytes;
struct vring vring;
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-04-15 14:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-01 11:02 [patch] virtio: silence uninitialized variable warnings Dan Carpenter
2016-04-15 14:45 ` [patch] virtio: Silence uninitialized variable warning Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).