get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 128355,
    "url": "http://patches.dpdk.org/api/patches/128355/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230607172415.21945-1-syalavarthi@marvell.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<20230607172415.21945-1-syalavarthi@marvell.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230607172415.21945-1-syalavarthi@marvell.com",
    "date": "2023-06-07T17:24:15",
    "name": "[v6] app/mldev: add internal function for file read",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "a84ddd9f06a277cf01b00f5d33d6510ced66f254",
    "submitter": {
        "id": 2480,
        "url": "http://patches.dpdk.org/api/people/2480/?format=api",
        "name": "Srikanth Yalavarthi",
        "email": "syalavarthi@marvell.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20230607172415.21945-1-syalavarthi@marvell.com/mbox/",
    "series": [
        {
            "id": 28394,
            "url": "http://patches.dpdk.org/api/series/28394/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=28394",
            "date": "2023-06-07T17:24:15",
            "name": "[v6] app/mldev: add internal function for file read",
            "version": 6,
            "mbox": "http://patches.dpdk.org/series/28394/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/128355/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/128355/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id F30E642C52;\n\tWed,  7 Jun 2023 19:24:38 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 8DDDA42C4D;\n\tWed,  7 Jun 2023 19:24:38 +0200 (CEST)",
            "from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com\n [67.231.148.174])\n by mails.dpdk.org (Postfix) with ESMTP id 0047D41611\n for <dev@dpdk.org>; Wed,  7 Jun 2023 19:24:36 +0200 (CEST)",
            "from pps.filterd (m0045849.ppops.net [127.0.0.1])\n by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id\n 357DvhJi028140 for <dev@dpdk.org>; Wed, 7 Jun 2023 10:24:36 -0700",
            "from dc5-exch01.marvell.com ([199.233.59.181])\n by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3r2a7bvs26-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT)\n for <dev@dpdk.org>; Wed, 07 Jun 2023 10:24:35 -0700",
            "from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com\n (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48;\n Wed, 7 Jun 2023 10:24:19 -0700",
            "from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com\n (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend\n Transport; Wed, 7 Jun 2023 10:24:19 -0700",
            "from ml-host-33.caveonetworks.com (unknown [10.110.143.233])\n by maili.marvell.com (Postfix) with ESMTP id AEE7E3F7088;\n Wed,  7 Jun 2023 10:24:17 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;\n h=from : to : cc :\n subject : date : message-id : in-reply-to : references : mime-version :\n content-type; s=pfpt0220; bh=2JK7VU3NIlqeCL+nVaw+5mVaWFWJPJWAVgpZ6jz//Is=;\n b=gS1SOEJqrpdM8sYJQISLWgznAdmJkFlWREWWddu6XzegLHa9QMRJuPBB1NQKWfv9nUZb\n 2ywMLvX800em4jHTEseLzas8iV7ufWP+FmaaameeUpxbLgvJl6Ysn/FVkMbcW67X1LFK\n kXUTt0q8zkx6HyO8qEEAlpC0gC9IQNoZG04RJy2tSoZoPh492yWOztjl0+XXqLN7GTdN\n hKKeRtg36nht2iIk5q7FctG3Jo2MkbCVQNJaTEj3hJ5Y9BVC9Dnrq7atc37zic/Y8M63\n OfFO7U036rgE3+pTctFo93mme9vmZvDNQjvxqTXzokVP7+8vfdWHD7vK3D9X43SCVshc 8g==",
        "From": "Srikanth Yalavarthi <syalavarthi@marvell.com>",
        "To": "Srikanth Yalavarthi <syalavarthi@marvell.com>, Anup Prabhu\n <aprabhu@marvell.com>",
        "CC": "<dev@dpdk.org>, <sshankarnara@marvell.com>, <ptakkar@marvell.com>",
        "Subject": "[PATCH v6] app/mldev: add internal function for file read",
        "Date": "Wed, 7 Jun 2023 10:24:15 -0700",
        "Message-ID": "<20230607172415.21945-1-syalavarthi@marvell.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20230323152801.27666-1-syalavarthi@marvell.com>",
        "References": "<20230323152801.27666-1-syalavarthi@marvell.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain",
        "X-Proofpoint-ORIG-GUID": "0iualm5eAuHjW-FZ5P2C3rXq91x5mFrh",
        "X-Proofpoint-GUID": "0iualm5eAuHjW-FZ5P2C3rXq91x5mFrh",
        "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26\n definitions=2023-06-07_09,2023-06-07_01,2023-05-22_02",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "Added internal function to read model, input and reference\nfiles with required error checks. This change fixes the\nunchecked return value and improper use of negative value\nissues reported by coverity scan for file read operations.\n\nCoverity issue: 383742, 383743\nFixes: f6661e6d9a3a (\"app/mldev: validate model operations\")\nFixes: da6793390596 (\"app/mldev: support inference validation\")\n\nSigned-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>\n---\nv6:\n* Addressed additional review comments\n\nv5:\n* Updated as per review comments\n\nv4:\n* Drop use of fread and replace with system calls\n\nv3:\n* Fix incorrect use of rte_free with free\n\nv2:\n* Replace rte_malloc in ml_read_file with malloc\n\n app/test-mldev/test_common.c           | 56 ++++++++++++++++++++++++++\n app/test-mldev/test_common.h           |  2 +\n app/test-mldev/test_inference_common.c | 55 ++++++++++---------------\n app/test-mldev/test_model_common.c     | 39 +++++-------------\n 4 files changed, 88 insertions(+), 64 deletions(-)",
    "diff": "diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c\nindex 016b31c6ba..891e8d0ca8 100644\n--- a/app/test-mldev/test_common.c\n+++ b/app/test-mldev/test_common.c\n@@ -5,12 +5,68 @@\n #include <errno.h>\n \n #include <rte_common.h>\n+#include <rte_malloc.h>\n #include <rte_memory.h>\n #include <rte_mldev.h>\n \n #include \"ml_common.h\"\n #include \"test_common.h\"\n \n+#include <fcntl.h>\n+#include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <unistd.h>\n+\n+int\n+ml_read_file(char *file, size_t *size, char **buffer)\n+{\n+\tchar *file_buffer = NULL;\n+\tstruct stat file_stat;\n+\tchar *file_map;\n+\tint ret;\n+\tint fd;\n+\n+\tfd = open(file, O_RDONLY);\n+\tif (fd == -1) {\n+\t\tml_err(\"Failed to open file: %s\\n\", file);\n+\t\treturn -errno;\n+\t}\n+\n+\tif (fstat(fd, &file_stat) != 0) {\n+\t\tml_err(\"fstat failed for file: %s\\n\", file);\n+\t\treturn -errno;\n+\t}\n+\n+\tfile_buffer = malloc(file_stat.st_size);\n+\tif (file_buffer == NULL) {\n+\t\tml_err(\"Failed to allocate memory: %s\\n\", file);\n+\t\tret = -ENOMEM;\n+\t\tgoto error;\n+\t}\n+\n+\tfile_map = mmap(0, file_stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\tif (file_map == MAP_FAILED) {\n+\t\tml_err(\"Failed to map file: %s\\n\", file);\n+\t\tret = -errno;\n+\t\tgoto error;\n+\t}\n+\n+\trte_memcpy(file_buffer, file_map, file_stat.st_size);\n+\tmunmap(file_map, file_stat.st_size);\n+\tclose(fd);\n+\n+\t*size = file_stat.st_size;\n+\t*buffer = file_buffer;\n+\n+\treturn 0;\n+\n+error:\n+\tfree(file_buffer);\n+\tclose(fd);\n+\n+\treturn ret;\n+}\n+\n bool\n ml_test_cap_check(struct ml_options *opt)\n {\ndiff --git a/app/test-mldev/test_common.h b/app/test-mldev/test_common.h\nindex def108d5b2..793841a917 100644\n--- a/app/test-mldev/test_common.h\n+++ b/app/test-mldev/test_common.h\n@@ -27,4 +27,6 @@ int ml_test_device_close(struct ml_test *test, struct ml_options *opt);\n int ml_test_device_start(struct ml_test *test, struct ml_options *opt);\n int ml_test_device_stop(struct ml_test *test, struct ml_options *opt);\n \n+int ml_read_file(char *file, size_t *size, char **buffer);\n+\n #endif /* TEST_COMMON_H */\ndiff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c\nindex d929ff6e61..231ef2defa 100644\n--- a/app/test-mldev/test_inference_common.c\n+++ b/app/test-mldev/test_inference_common.c\n@@ -599,10 +599,10 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t\n \tchar mp_name[RTE_MEMPOOL_NAMESIZE];\n \tconst struct rte_memzone *mz;\n \tuint64_t nb_buffers;\n+\tchar *buffer = NULL;\n \tuint32_t buff_size;\n \tuint32_t mz_size;\n-\tuint32_t fsize;\n-\tFILE *fp;\n+\tsize_t fsize;\n \tint ret;\n \n \t/* get input buffer size */\n@@ -642,51 +642,36 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t\n \t\tt->model[fid].reference = NULL;\n \n \t/* load input file */\n-\tfp = fopen(opt->filelist[fid].input, \"r\");\n-\tif (fp == NULL) {\n-\t\tml_err(\"Failed to open input file : %s\\n\", opt->filelist[fid].input);\n-\t\tret = -errno;\n+\tret = ml_read_file(opt->filelist[fid].input, &fsize, &buffer);\n+\tif (ret != 0)\n \t\tgoto error;\n-\t}\n \n-\tfseek(fp, 0, SEEK_END);\n-\tfsize = ftell(fp);\n-\tfseek(fp, 0, SEEK_SET);\n-\tif (fsize != t->model[fid].inp_dsize) {\n-\t\tml_err(\"Invalid input file, size = %u (expected size = %\" PRIu64 \")\\n\", fsize,\n+\tif (fsize == t->model[fid].inp_dsize) {\n+\t\trte_memcpy(t->model[fid].input, buffer, fsize);\n+\t\tfree(buffer);\n+\t} else {\n+\t\tml_err(\"Invalid input file, size = %zu (expected size = %\" PRIu64 \")\\n\", fsize,\n \t\t       t->model[fid].inp_dsize);\n \t\tret = -EINVAL;\n-\t\tfclose(fp);\n-\t\tgoto error;\n-\t}\n-\n-\tif (fread(t->model[fid].input, 1, t->model[fid].inp_dsize, fp) != t->model[fid].inp_dsize) {\n-\t\tml_err(\"Failed to read input file : %s\\n\", opt->filelist[fid].input);\n-\t\tret = -errno;\n-\t\tfclose(fp);\n \t\tgoto error;\n \t}\n-\tfclose(fp);\n \n \t/* load reference file */\n+\tbuffer = NULL;\n \tif (t->model[fid].reference != NULL) {\n-\t\tfp = fopen(opt->filelist[fid].reference, \"r\");\n-\t\tif (fp == NULL) {\n-\t\t\tml_err(\"Failed to open reference file : %s\\n\",\n-\t\t\t       opt->filelist[fid].reference);\n-\t\t\tret = -errno;\n+\t\tret = ml_read_file(opt->filelist[fid].reference, &fsize, &buffer);\n+\t\tif (ret != 0)\n \t\t\tgoto error;\n-\t\t}\n \n-\t\tif (fread(t->model[fid].reference, 1, t->model[fid].out_dsize, fp) !=\n-\t\t    t->model[fid].out_dsize) {\n-\t\t\tml_err(\"Failed to read reference file : %s\\n\",\n-\t\t\t       opt->filelist[fid].reference);\n-\t\t\tret = -errno;\n-\t\t\tfclose(fp);\n+\t\tif (fsize == t->model[fid].out_dsize) {\n+\t\t\trte_memcpy(t->model[fid].reference, buffer, fsize);\n+\t\t\tfree(buffer);\n+\t\t} else {\n+\t\t\tml_err(\"Invalid reference file, size = %zu (expected size = %\" PRIu64 \")\\n\",\n+\t\t\t       fsize, t->model[fid].out_dsize);\n+\t\t\tret = -EINVAL;\n \t\t\tgoto error;\n \t\t}\n-\t\tfclose(fp);\n \t}\n \n \t/* create mempool for quantized input and output buffers. ml_request_initialize is\n@@ -718,6 +703,8 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t\n \t\tt->model[fid].io_pool = NULL;\n \t}\n \n+\tfree(buffer);\n+\n \treturn ret;\n }\n \ndiff --git a/app/test-mldev/test_model_common.c b/app/test-mldev/test_model_common.c\nindex c28e452f29..8dbb0ff89f 100644\n--- a/app/test-mldev/test_model_common.c\n+++ b/app/test-mldev/test_model_common.c\n@@ -14,11 +14,11 @@\n int\n ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *model, uint16_t fid)\n {\n-\tstruct test_common *t = ml_test_priv(test);\n \tstruct rte_ml_model_params model_params;\n-\tFILE *fp;\n \tint ret;\n \n+\tRTE_SET_USED(test);\n+\n \tif (model->state == MODEL_LOADED)\n \t\treturn 0;\n \n@@ -26,43 +26,22 @@ ml_model_load(struct ml_test *test, struct ml_options *opt, struct ml_model *mod\n \t\treturn -EINVAL;\n \n \t/* read model binary */\n-\tfp = fopen(opt->filelist[fid].model, \"r\");\n-\tif (fp == NULL) {\n-\t\tml_err(\"Failed to open model file : %s\\n\", opt->filelist[fid].model);\n-\t\treturn -1;\n-\t}\n-\n-\tfseek(fp, 0, SEEK_END);\n-\tmodel_params.size = ftell(fp);\n-\tfseek(fp, 0, SEEK_SET);\n-\n-\tmodel_params.addr = rte_malloc_socket(\"ml_model\", model_params.size,\n-\t\t\t\t\t      t->dev_info.min_align_size, opt->socket_id);\n-\tif (model_params.addr == NULL) {\n-\t\tml_err(\"Failed to allocate memory for model: %s\\n\", opt->filelist[fid].model);\n-\t\tfclose(fp);\n-\t\treturn -ENOMEM;\n-\t}\n-\n-\tif (fread(model_params.addr, 1, model_params.size, fp) != model_params.size) {\n-\t\tml_err(\"Failed to read model file : %s\\n\", opt->filelist[fid].model);\n-\t\trte_free(model_params.addr);\n-\t\tfclose(fp);\n-\t\treturn -1;\n-\t}\n-\tfclose(fp);\n+\tret = ml_read_file(opt->filelist[fid].model, &model_params.size,\n+\t\t\t   (char **)&model_params.addr);\n+\tif (ret != 0)\n+\t\treturn ret;\n \n \t/* load model to device */\n \tret = rte_ml_model_load(opt->dev_id, &model_params, &model->id);\n \tif (ret != 0) {\n \t\tml_err(\"Failed to load model : %s\\n\", opt->filelist[fid].model);\n \t\tmodel->state = MODEL_ERROR;\n-\t\trte_free(model_params.addr);\n+\t\tfree(model_params.addr);\n \t\treturn ret;\n \t}\n \n-\t/* release mz */\n-\trte_free(model_params.addr);\n+\t/* release buffer */\n+\tfree(model_params.addr);\n \n \t/* get model info */\n \tret = rte_ml_model_info_get(opt->dev_id, model->id, &model->info);\n",
    "prefixes": [
        "v6"
    ]
}