get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/6183/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 6183,
    "url": "https://patches.dpdk.org/api/patches/6183/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1436351693-2349-4-git-send-email-mukawa@igel.co.jp/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1436351693-2349-4-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1436351693-2349-4-git-send-email-mukawa@igel.co.jp",
    "date": "2015-07-08T10:34:44",
    "name": "[dpdk-dev,v9,03/12] eal: Fix memory leaks and needless increment of pci_map_addr",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "30cadd5eeee5505f5e7a7738b3cd098d4fa822bd",
    "submitter": {
        "id": 64,
        "url": "https://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1436351693-2349-4-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/6183/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/6183/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id CCE275A68;\n\tWed,  8 Jul 2015 12:35:43 +0200 (CEST)",
            "from mail-pa0-f48.google.com (mail-pa0-f48.google.com\n\t[209.85.220.48]) by dpdk.org (Postfix) with ESMTP id DE07F68A5\n\tfor <dev@dpdk.org>; Wed,  8 Jul 2015 12:35:41 +0200 (CEST)",
            "by pactm7 with SMTP id tm7so129696729pac.2\n\tfor <dev@dpdk.org>; Wed, 08 Jul 2015 03:35:41 -0700 (PDT)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby smtp.gmail.com with ESMTPSA id\n\txf2sm2043139pab.25.2015.07.08.03.35.39\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 08 Jul 2015 03:35:40 -0700 (PDT)"
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=V3bHaxMbdTlSBgDfOw91SfWVRyql0ASPdWF7hTnk01g=;\n\tb=Qi4jtp97NxIjRCLNMgtBW4DU9IvTXdw3lDLsbhNPdEiImj4UyZHWeUbp6LrXG4sT3Y\n\trMFZDWz6HxhhoGRyZXURpvGS5brX+VSlKbk8/O741zam9nRzee992onpVNjx84exl4+a\n\toBd+7LQ9+dBoYVfgu4hwLxh5quXgPs78hJQ/xXNNz1WL9/w2XwotjL+pgnO57UtklM4D\n\t7zInPqzJ6kriBaoMS8BE3Rv7BjstvFEejnfnr9y6IeOuReDhX7PizIN3Ct5csKhQ7T54\n\t+Tnx0pnD4z09AZygYOU4oSZZdJEx1taYiUOyy47lcGTnN5k1MH0SeaqSj4xUGbqUIFG2\n\ti7rw==",
        "X-Gm-Message-State": "ALoCoQlMf/Fz7o257BMMeGhSgxo7EClKY1jCbDnTBJxrH3u99bMnWNAFRPqG77H4SB9UytPK5Eas",
        "X-Received": "by 10.70.35.201 with SMTP id k9mr18967627pdj.128.1436351741255; \n\tWed, 08 Jul 2015 03:35:41 -0700 (PDT)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org",
        "Date": "Wed,  8 Jul 2015 19:34:44 +0900",
        "Message-Id": "<1436351693-2349-4-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 2.1.4",
        "In-Reply-To": "<1436351693-2349-1-git-send-email-mukawa@igel.co.jp>",
        "References": "<1435652668-3380-12-git-send-email-mukawa@igel.co.jp>\n\t<1436351693-2349-1-git-send-email-mukawa@igel.co.jp>",
        "Subject": "[dpdk-dev] [PATCH v9 03/12] eal: Fix memory leaks and needless\n\tincrement of pci_map_addr",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: \"Tetsuya.Mukawa\" <mukawa@igel.co.jp>\n\nThis patch fixes following memory leaks.\n- When open() is failed, uio_res and fds won't be freed in\n  pci_uio_map_resource().\n- When pci_map_resource() is failed but path is allocated correctly,\n  path and fds won't be freed in pci_uio_map_recource().\n  Also, some mapped resources should be freed.\n- When pci_uio_unmap() is called, path should be freed.\n\nAlso, fixes below.\n- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.\n  In this case, pci_map_addr should not be incremented in\n  pci_uio_map_resource().\n- To shrink code, move close().\n- Remove fail variable.\n\nSigned-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>\nAcked-by: Bernard Iremonger <bernard.iremonger@intel.com>\n---\n lib/librte_eal/bsdapp/eal/eal_pci.c       | 18 ++++++---\n lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 63 ++++++++++++++++++++-----------\n 2 files changed, 53 insertions(+), 28 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c\nindex a63d450..da17685 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_pci.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c\n@@ -202,7 +202,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tuint64_t offset;\n \tuint64_t pagesz;\n \tstruct rte_pci_addr *loc = &dev->addr;\n-\tstruct uio_resource *uio_res;\n+\tstruct uio_resource *uio_res = NULL;\n \tstruct uio_res_list *uio_res_list =\n \t\t\tRTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list);\n \tstruct uio_map *maps;\n@@ -228,7 +228,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (dev->intr_handle.fd < 0) {\n \t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\tdevname, strerror(errno));\n-\t\treturn -1;\n+\t\tgoto error;\n \t}\n \tdev->intr_handle.type = RTE_INTR_HANDLE_UIO;\n \n@@ -236,7 +236,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif ((uio_res = rte_zmalloc(\"UIO_RES\", sizeof (*uio_res), 0)) == NULL) {\n \t\tRTE_LOG(ERR, EAL,\n \t\t\t\"%s(): cannot store uio mmap details\\n\", __func__);\n-\t\treturn -1;\n+\t\tgoto error;\n \t}\n \n \tsnprintf(uio_res->path, sizeof(uio_res->path), \"%s\", devname);\n@@ -263,8 +263,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\t    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,\n \t\t\t\t\t\t(size_t)maps[j].size)\n \t\t    ) == NULL) {\n-\t\t\trte_free(uio_res);\n-\t\t\treturn -1;\n+\t\t\tgoto error;\n \t\t}\n \n \t\tmaps[j].addr = mapaddr;\n@@ -275,6 +274,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tTAILQ_INSERT_TAIL(uio_res_list, uio_res, next);\n \n \treturn 0;\n+\n+error:\n+\trte_free(uio_res);\n+\tif (dev->intr_handle.fd >= 0) {\n+\t\tclose(dev->intr_handle.fd);\n+\t\tdev->intr_handle.fd = -1;\n+\t\tdev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;\n+\t}\n+\treturn -1;\n }\n \n /* Scan one pci sysfs entry, and fill the devices list from it. */\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\nindex 37dc936..838b851 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\n@@ -265,7 +265,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,\n int\n pci_uio_map_resource(struct rte_pci_device *dev)\n {\n-\tint i, map_idx;\n+\tint i, map_idx = 0;\n \tchar dirname[PATH_MAX];\n \tchar cfgname[PATH_MAX];\n \tchar devname[PATH_MAX]; /* contains the /dev/uioX */\n@@ -273,7 +273,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tint uio_num;\n \tuint64_t phaddr;\n \tstruct rte_pci_addr *loc = &dev->addr;\n-\tstruct mapped_pci_resource *uio_res;\n+\tstruct mapped_pci_resource *uio_res = NULL;\n \tstruct mapped_pci_res_list *uio_res_list =\n \t\t\tRTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);\n \tstruct pci_map *maps;\n@@ -300,7 +300,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (dev->intr_handle.fd < 0) {\n \t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\tdevname, strerror(errno));\n-\t\treturn -1;\n+\t\tgoto error;\n \t}\n \n \tsnprintf(cfgname, sizeof(cfgname),\n@@ -309,7 +309,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (dev->intr_handle.uio_cfg_fd < 0) {\n \t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\tcfgname, strerror(errno));\n-\t\treturn -1;\n+\t\tgoto error;\n \t}\n \n \tif (dev->kdrv == RTE_KDRV_IGB_UIO)\n@@ -320,7 +320,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\t/* set bus master that is not done by uio_pci_generic */\n \t\tif (pci_uio_set_bus_master(dev->intr_handle.uio_cfg_fd)) {\n \t\t\tRTE_LOG(ERR, EAL, \"Cannot set up bus mastering!\\n\");\n-\t\t\treturn -1;\n+\t\t\tgoto error;\n \t\t}\n \t}\n \n@@ -329,7 +329,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (uio_res == NULL) {\n \t\tRTE_LOG(ERR, EAL,\n \t\t\t\"%s(): cannot store uio mmap details\\n\", __func__);\n-\t\treturn -1;\n+\t\tgoto error;\n \t}\n \n \tsnprintf(uio_res->path, sizeof(uio_res->path), \"%s\", devname);\n@@ -337,9 +337,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \n \t/* Map all BARs */\n \tmaps = uio_res->maps;\n-\tfor (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {\n+\tfor (i = 0; i != PCI_MAX_RESOURCE; i++) {\n \t\tint fd;\n-\t\tint fail = 0;\n \n \t\t/* skip empty BAR */\n \t\tphaddr = dev->mem_resource[i].phys_addr;\n@@ -353,6 +352,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\t\t\tloc->domain, loc->bus, loc->devid, loc->function,\n \t\t\t\ti);\n \n+\t\t/* allocate memory to keep path */\n+\t\tmaps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);\n+\t\tif (maps[map_idx].path == NULL)\n+\t\t\tgoto error;\n+\n \t\t/*\n \t\t * open resource file, to mmap it\n \t\t */\n@@ -360,7 +364,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\tif (fd < 0) {\n \t\t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\t\t\tdevname, strerror(errno));\n-\t\t\treturn -1;\n+\t\t\trte_free(maps[map_idx].path);\n+\t\t\tgoto error;\n \t\t}\n \n \t\t/* try mapping somewhere close to the end of hugepages */\n@@ -369,23 +374,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \n \t\tmapaddr = pci_map_resource(pci_map_addr, fd, 0,\n \t\t\t\t(size_t)dev->mem_resource[i].len, 0);\n-\t\tif (mapaddr == MAP_FAILED)\n-\t\t\tfail = 1;\n+\t\tclose(fd);\n+\t\tif (mapaddr == MAP_FAILED) {\n+\t\t\trte_free(maps[map_idx].path);\n+\t\t\tgoto error;\n+\t\t}\n \n \t\tpci_map_addr = RTE_PTR_ADD(mapaddr,\n \t\t\t\t(size_t)dev->mem_resource[i].len);\n \n-\t\tmaps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);\n-\t\tif (maps[map_idx].path == NULL)\n-\t\t\tfail = 1;\n-\n-\t\tif (fail) {\n-\t\t\trte_free(uio_res);\n-\t\t\tclose(fd);\n-\t\t\treturn -1;\n-\t\t}\n-\t\tclose(fd);\n-\n \t\tmaps[map_idx].phaddr = dev->mem_resource[i].phys_addr;\n \t\tmaps[map_idx].size = dev->mem_resource[i].len;\n \t\tmaps[map_idx].addr = mapaddr;\n@@ -400,6 +397,24 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tTAILQ_INSERT_TAIL(uio_res_list, uio_res, next);\n \n \treturn 0;\n+\n+error:\n+\tfor (i = 0; i < map_idx; i++) {\n+\t\tpci_unmap_resource(uio_res->maps[i].addr,\n+\t\t\t\t(size_t)uio_res->maps[i].size);\n+\t\trte_free(maps[i].path);\n+\t}\n+\trte_free(uio_res);\n+\tif (dev->intr_handle.uio_cfg_fd >= 0) {\n+\t\tclose(dev->intr_handle.uio_cfg_fd);\n+\t\tdev->intr_handle.uio_cfg_fd = -1;\n+\t}\n+\tif (dev->intr_handle.fd >= 0) {\n+\t\tclose(dev->intr_handle.fd);\n+\t\tdev->intr_handle.fd = -1;\n+\t\tdev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;\n+\t}\n+\treturn -1;\n }\n \n #ifdef RTE_LIBRTE_EAL_HOTPLUG\n@@ -411,9 +426,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)\n \tif (uio_res == NULL)\n \t\treturn;\n \n-\tfor (i = 0; i != uio_res->nb_maps; i++)\n+\tfor (i = 0; i != uio_res->nb_maps; i++) {\n \t\tpci_unmap_resource(uio_res->maps[i].addr,\n \t\t\t\t(size_t)uio_res->maps[i].size);\n+\t\trte_free(uio_res->maps[i].path);\n+\t}\n }\n \n static struct mapped_pci_resource *\n",
    "prefixes": [
        "dpdk-dev",
        "v9",
        "03/12"
    ]
}