Message ID | 1447102433-20322-1-git-send-email-drjones@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 09/11/15 21:53, Andrew Jones wrote: > It's pretty safe to not even bother checking for NULL when > using malloc and friends, but if we do check, then fail > hard. > > Signed-off-by: Andrew Jones <drjones@redhat.com> > --- > v2: no code in asserts [Thomas Huth] > > lib/virtio-mmio.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/lib/virtio-mmio.c b/lib/virtio-mmio.c > index 043832299174e..5ccbd193a264a 100644 > --- a/lib/virtio-mmio.c > +++ b/lib/virtio-mmio.c > @@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, > > vq = calloc(1, sizeof(*vq)); > queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN); > - if (!vq || !queue) > - return NULL; > + assert(vq && queue); > > writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL); > > @@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid) > return NULL; > > vm_dev = calloc(1, sizeof(*vm_dev)); > - if (!vm_dev) > - return NULL; > + assert(vm_dev != NULL); > > vm_dev->base = info.base; > vm_device_init(vm_dev); Reviewed-by: Thomas Huth <thuth@redhat.com> -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 09/11/2015 21:53, Andrew Jones wrote: > It's pretty safe to not even bother checking for NULL when > using malloc and friends, but if we do check, then fail > hard. > > Signed-off-by: Andrew Jones <drjones@redhat.com> > --- > v2: no code in asserts [Thomas Huth] > > lib/virtio-mmio.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/lib/virtio-mmio.c b/lib/virtio-mmio.c > index 043832299174e..5ccbd193a264a 100644 > --- a/lib/virtio-mmio.c > +++ b/lib/virtio-mmio.c > @@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, > > vq = calloc(1, sizeof(*vq)); > queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN); > - if (!vq || !queue) > - return NULL; > + assert(vq && queue); > > writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL); > > @@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid) > return NULL; > > vm_dev = calloc(1, sizeof(*vm_dev)); > - if (!vm_dev) > - return NULL; > + assert(vm_dev != NULL); > > vm_dev->base = info.base; > vm_device_init(vm_dev); > Applied, thanks. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/lib/virtio-mmio.c b/lib/virtio-mmio.c index 043832299174e..5ccbd193a264a 100644 --- a/lib/virtio-mmio.c +++ b/lib/virtio-mmio.c @@ -54,8 +54,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, vq = calloc(1, sizeof(*vq)); queue = memalign(PAGE_SIZE, VIRTIO_MMIO_QUEUE_SIZE_MIN); - if (!vq || !queue) - return NULL; + assert(vq && queue); writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL); @@ -162,8 +161,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid) return NULL; vm_dev = calloc(1, sizeof(*vm_dev)); - if (!vm_dev) - return NULL; + assert(vm_dev != NULL); vm_dev->base = info.base; vm_device_init(vm_dev);
It's pretty safe to not even bother checking for NULL when using malloc and friends, but if we do check, then fail hard. Signed-off-by: Andrew Jones <drjones@redhat.com> --- v2: no code in asserts [Thomas Huth] lib/virtio-mmio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)