{"id":811284,"url":"http://patchwork.ozlabs.org/api/1.2/patches/811284/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504836324-4871-3-git-send-email-jasowang@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504836324-4871-3-git-send-email-jasowang@redhat.com>","list_archive_url":null,"date":"2017-09-08T02:05:08","name":"[PULL,02/18] net/rocker: Remove the dead error handling","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"0950c416697b08b116f12e3d9e59d02fd111383f","submitter":{"id":5225,"url":"http://patchwork.ozlabs.org/api/1.2/people/5225/?format=json","name":"Jason Wang","email":"jasowang@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1504836324-4871-3-git-send-email-jasowang@redhat.com/mbox/","series":[{"id":2087,"url":"http://patchwork.ozlabs.org/api/1.2/series/2087/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2087","date":"2017-09-08T02:05:06","name":"[PULL,01/18] net/filter-rewriter.c: Fix rewirter checksum bug when use virtio-net","version":1,"mbox":"http://patchwork.ozlabs.org/series/2087/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811284/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811284/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jasowang@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xpLKV1mnRz9sDB\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 12:06:38 +1000 (AEST)","from localhost ([::1]:42944 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dq8gm-00033H-8M\n\tfor incoming@patchwork.ozlabs.org; Thu, 07 Sep 2017 22:06:36 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:60727)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <jasowang@redhat.com>) id 1dq8fv-0002xT-Hq\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:05:48 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <jasowang@redhat.com>) id 1dq8fq-0001y5-3P\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:05:43 -0400","from mx1.redhat.com ([209.132.183.28]:40492)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <jasowang@redhat.com>) id 1dq8fp-0001xd-Pv\n\tfor qemu-devel@nongnu.org; Thu, 07 Sep 2017 22:05:38 -0400","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id CE14B4E909;\n\tFri,  8 Sep 2017 02:05:36 +0000 (UTC)","from jason-ThinkPad-T450s.redhat.com (ovpn-12-98.pek2.redhat.com\n\t[10.72.12.98])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 2E24F600C2;\n\tFri,  8 Sep 2017 02:05:32 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com CE14B4E909","From":"Jason Wang <jasowang@redhat.com>","To":"peter.maydell@linaro.org,\n\tqemu-devel@nongnu.org","Date":"Fri,  8 Sep 2017 10:05:08 +0800","Message-Id":"<1504836324-4871-3-git-send-email-jasowang@redhat.com>","In-Reply-To":"<1504836324-4871-1-git-send-email-jasowang@redhat.com>","References":"<1504836324-4871-1-git-send-email-jasowang@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.38]);\n\tFri, 08 Sep 2017 02:05:36 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PULL 02/18] net/rocker: Remove the dead error handling","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Mao Zhongyi <maozy.fnst@cn.fujitsu.com>, f4bug@amsat.org,\n\tjiri@resnulli.us, jasowang@redhat.com, armbru@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>\n\nMemory allocation functions like world_alloc, desc_ring_alloc etc,\nthey are all wrappers around g_malloc, g_new etc. But g_malloc and\nsimilar functions doesn't return null. Because they ignore the fact\nthat g_malloc() of 0 bytes returns null. So error checks for these\nallocation failure are superfluous. Now, remove them entirely.\n\nCc: jasowang@redhat.com\nCc: jiri@resnulli.us\nCc: armbru@redhat.com\nCc: f4bug@amsat.org\nSigned-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>\nReviewed-by: Markus Armbruster <armbru@redhat.com>\nSigned-off-by: Jason Wang <jasowang@redhat.com>\n---\n hw/net/rocker/rocker.c        | 47 +------------------------------------------\n hw/net/rocker/rocker_desc.c   | 10 ---------\n hw/net/rocker/rocker_fp.c     |  4 ----\n hw/net/rocker/rocker_of_dpa.c | 20 ------------------\n hw/net/rocker/rocker_world.c  | 12 +++++------\n 5 files changed, 6 insertions(+), 87 deletions(-)","diff":"diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c\nindex 4f0f6d7..7496752 100644\n--- a/hw/net/rocker/rocker.c\n+++ b/hw/net/rocker/rocker.c\n@@ -239,10 +239,6 @@ static int tx_consume(Rocker *r, DescInfo *info)\n         }\n         iov[iovcnt].iov_len = frag_len;\n         iov[iovcnt].iov_base = g_malloc(frag_len);\n-        if (!iov[iovcnt].iov_base) {\n-            err = -ROCKER_ENOMEM;\n-            goto err_no_mem;\n-        }\n \n         pci_dma_read(dev, frag_addr, iov[iovcnt].iov_base,\n                      iov[iovcnt].iov_len);\n@@ -259,7 +255,6 @@ static int tx_consume(Rocker *r, DescInfo *info)\n     err = fp_port_eg(r->fp_port[port], iov, iovcnt);\n \n err_too_many_frags:\n-err_no_mem:\n err_bad_attr:\n     for (i = 0; i < ROCKER_TX_FRAGS_MAX; i++) {\n         g_free(iov[i].iov_base);\n@@ -671,10 +666,7 @@ int rx_produce(World *world, uint32_t pport,\n      */\n \n     data = g_malloc(data_size);\n-    if (!data) {\n-        err = -ROCKER_ENOMEM;\n-        goto out;\n-    }\n+\n     iov_to_buf(iov, iovcnt, 0, data, data_size);\n     pci_dma_write(dev, frag_addr, data, data_size);\n     g_free(data);\n@@ -719,11 +711,6 @@ static void rocker_test_dma_ctrl(Rocker *r, uint32_t val)\n \n     buf = g_malloc(r->test_dma_size);\n \n-    if (!buf) {\n-        DPRINTF(\"test dma buffer alloc failed\");\n-        return;\n-    }\n-\n     switch (val) {\n     case ROCKER_TEST_DMA_CTRL_CLEAR:\n         memset(buf, 0, r->test_dma_size);\n@@ -1310,13 +1297,6 @@ static int pci_rocker_init(PCIDevice *dev)\n \n     r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);\n \n-    for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {\n-        if (!r->worlds[i]) {\n-            err = -ENOMEM;\n-            goto err_world_alloc;\n-        }\n-    }\n-\n     if (!r->world_name) {\n         r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));\n     }\n@@ -1393,9 +1373,6 @@ static int pci_rocker_init(PCIDevice *dev)\n     }\n \n     r->rings = g_new(DescRing *, rocker_pci_ring_count(r));\n-    if (!r->rings) {\n-        goto err_rings_alloc;\n-    }\n \n     /* Rings are ordered like this:\n      * - command ring\n@@ -1407,14 +1384,9 @@ static int pci_rocker_init(PCIDevice *dev)\n      * .....\n      */\n \n-    err = -ENOMEM;\n     for (i = 0; i < rocker_pci_ring_count(r); i++) {\n         DescRing *ring = desc_ring_alloc(r, i);\n \n-        if (!ring) {\n-            goto err_ring_alloc;\n-        }\n-\n         if (i == ROCKER_RING_CMD) {\n             desc_ring_set_consume(ring, cmd_consume, ROCKER_MSIX_VEC_CMD);\n         } else if (i == ROCKER_RING_EVENT) {\n@@ -1434,10 +1406,6 @@ static int pci_rocker_init(PCIDevice *dev)\n             fp_port_alloc(r, r->name, &r->fp_start_macaddr,\n                           i, &r->fp_ports_peers[i]);\n \n-        if (!port) {\n-            goto err_port_alloc;\n-        }\n-\n         r->fp_port[i] = port;\n         fp_port_set_world(port, r->world_dflt);\n     }\n@@ -1446,25 +1414,12 @@ static int pci_rocker_init(PCIDevice *dev)\n \n     return 0;\n \n-err_port_alloc:\n-    for (--i; i >= 0; i--) {\n-        FpPort *port = r->fp_port[i];\n-        fp_port_free(port);\n-    }\n-    i = rocker_pci_ring_count(r);\n-err_ring_alloc:\n-    for (--i; i >= 0; i--) {\n-        desc_ring_free(r->rings[i]);\n-    }\n-    g_free(r->rings);\n-err_rings_alloc:\n err_duplicate:\n     rocker_msix_uninit(r);\n err_msix_init:\n     object_unparent(OBJECT(&r->msix_bar));\n     object_unparent(OBJECT(&r->mmio));\n err_world_type_by_name:\n-err_world_alloc:\n     for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {\n         if (r->worlds[i]) {\n             world_free(r->worlds[i]);\ndiff --git a/hw/net/rocker/rocker_desc.c b/hw/net/rocker/rocker_desc.c\nindex 6184c40..b009da4 100644\n--- a/hw/net/rocker/rocker_desc.c\n+++ b/hw/net/rocker/rocker_desc.c\n@@ -65,10 +65,6 @@ char *desc_get_buf(DescInfo *info, bool read_only)\n         info->buf_size = size;\n     }\n \n-    if (!info->buf) {\n-        return NULL;\n-    }\n-\n     pci_dma_read(dev, le64_to_cpu(info->desc.buf_addr), info->buf, size);\n \n     return info->buf;\n@@ -142,9 +138,6 @@ bool desc_ring_set_size(DescRing *ring, uint32_t size)\n     ring->head = ring->tail = 0;\n \n     ring->info = g_renew(DescInfo, ring->info, size);\n-    if (!ring->info) {\n-        return false;\n-    }\n \n     memset(ring->info, 0, size * sizeof(DescInfo));\n \n@@ -345,9 +338,6 @@ DescRing *desc_ring_alloc(Rocker *r, int index)\n     DescRing *ring;\n \n     ring = g_new0(DescRing, 1);\n-    if (!ring) {\n-        return NULL;\n-    }\n \n     ring->r = r;\n     ring->index = index;\ndiff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c\nindex 1305ac3..4b3c984 100644\n--- a/hw/net/rocker/rocker_fp.c\n+++ b/hw/net/rocker/rocker_fp.c\n@@ -226,10 +226,6 @@ FpPort *fp_port_alloc(Rocker *r, char *sw_name,\n {\n     FpPort *port = g_new0(FpPort, 1);\n \n-    if (!port) {\n-        return NULL;\n-    }\n-\n     port->r = r;\n     port->index = index;\n     port->pport = index + 1;\ndiff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c\nindex 9b1e0d2..191a58e 100644\n--- a/hw/net/rocker/rocker_of_dpa.c\n+++ b/hw/net/rocker/rocker_of_dpa.c\n@@ -368,9 +368,6 @@ static OfDpaFlow *of_dpa_flow_alloc(uint64_t cookie)\n     int64_t now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) / 1000;\n \n     flow = g_new0(OfDpaFlow, 1);\n-    if (!flow) {\n-        return NULL;\n-    }\n \n     flow->cookie = cookie;\n     flow->mask.tbl_id = 0xffffffff;\n@@ -813,10 +810,6 @@ static OfDpaGroup *of_dpa_group_alloc(uint32_t id)\n {\n     OfDpaGroup *group = g_new0(OfDpaGroup, 1);\n \n-    if (!group) {\n-        return NULL;\n-    }\n-\n     group->id = id;\n \n     return group;\n@@ -1867,9 +1860,6 @@ static int of_dpa_cmd_flow_add(OfDpa *of_dpa, uint64_t cookie,\n     }\n \n     flow = of_dpa_flow_alloc(cookie);\n-    if (!flow) {\n-        return -ROCKER_ENOMEM;\n-    }\n \n     err = of_dpa_cmd_flow_add_mod(of_dpa, flow, flow_tlvs);\n     if (err) {\n@@ -2040,17 +2030,10 @@ static int of_dpa_cmd_add_l2_flood(OfDpa *of_dpa, OfDpaGroup *group,\n         rocker_tlv_get_le16(group_tlvs[ROCKER_TLV_OF_DPA_GROUP_COUNT]);\n \n     tlvs = g_new0(RockerTlv *, group->l2_flood.group_count + 1);\n-    if (!tlvs) {\n-        return -ROCKER_ENOMEM;\n-    }\n \n     g_free(group->l2_flood.group_ids);\n     group->l2_flood.group_ids =\n         g_new0(uint32_t, group->l2_flood.group_count);\n-    if (!group->l2_flood.group_ids) {\n-        err = -ROCKER_ENOMEM;\n-        goto err_out;\n-    }\n \n     rocker_tlv_parse_nested(tlvs, group->l2_flood.group_count,\n                             group_tlvs[ROCKER_TLV_OF_DPA_GROUP_IDS]);\n@@ -2157,9 +2140,6 @@ static int of_dpa_cmd_group_add(OfDpa *of_dpa, uint32_t group_id,\n     }\n \n     group = of_dpa_group_alloc(group_id);\n-    if (!group) {\n-        return -ROCKER_ENOMEM;\n-    }\n \n     err = of_dpa_cmd_group_do(of_dpa, group_id, group, group_tlvs);\n     if (err) {\ndiff --git a/hw/net/rocker/rocker_world.c b/hw/net/rocker/rocker_world.c\nindex 89777e9..f73c534 100644\n--- a/hw/net/rocker/rocker_world.c\n+++ b/hw/net/rocker/rocker_world.c\n@@ -51,13 +51,11 @@ World *world_alloc(Rocker *r, size_t sizeof_private,\n {\n     World *w = g_malloc0(sizeof(World) + sizeof_private);\n \n-    if (w) {\n-        w->r = r;\n-        w->type = type;\n-        w->ops = ops;\n-        if (w->ops->init) {\n-            w->ops->init(w);\n-        }\n+    w->r = r;\n+    w->type = type;\n+    w->ops = ops;\n+    if (w->ops->init) {\n+        w->ops->init(w);\n     }\n \n     return w;\n","prefixes":["PULL","02/18"]}