get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 125459,
    "url": "http://patchwork.dpdk.org/api/patches/125459/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20230323152801.27666-1-syalavarthi@marvell.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<20230323152801.27666-1-syalavarthi@marvell.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230323152801.27666-1-syalavarthi@marvell.com",
    "date": "2023-03-23T15:28:01",
    "name": "[1/1] app/mldev: add internal function for file read",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "3ce9851b226a842cb9b04cd9268b359fad260c6b",
    "submitter": {
        "id": 2480,
        "url": "http://patchwork.dpdk.org/api/people/2480/?format=api",
        "name": "Srikanth Yalavarthi",
        "email": "syalavarthi@marvell.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20230323152801.27666-1-syalavarthi@marvell.com/mbox/",
    "series": [
        {
            "id": 27523,
            "url": "http://patchwork.dpdk.org/api/series/27523/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=27523",
            "date": "2023-03-23T15:28:01",
            "name": "[1/1] app/mldev: add internal function for file read",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/27523/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/125459/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/125459/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 EF9A442826;\n\tThu, 23 Mar 2023 16:28:25 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id CE27040689;\n\tThu, 23 Mar 2023 16:28:25 +0100 (CET)",
            "from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com\n [67.231.148.174])\n by mails.dpdk.org (Postfix) with ESMTP id B064F4021E\n for <dev@dpdk.org>; Thu, 23 Mar 2023 16:28:24 +0100 (CET)",
            "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 32NBaCEY024300 for <dev@dpdk.org>; Thu, 23 Mar 2023 08:28:20 -0700",
            "from dc5-exch02.marvell.com ([199.233.59.182])\n by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pg9urc89x-2\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT)\n for <dev@dpdk.org>; Thu, 23 Mar 2023 08:28:14 -0700",
            "from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com\n (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42;\n Thu, 23 Mar 2023 08:28:03 -0700",
            "from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com\n (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend\n Transport; Thu, 23 Mar 2023 08:28:03 -0700",
            "from ml-host-33.caveonetworks.com (unknown [10.110.143.233])\n by maili.marvell.com (Postfix) with ESMTP id D20AA3F7076;\n Thu, 23 Mar 2023 08:28:03 -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 : mime-version : content-type; s=pfpt0220;\n bh=VuzZBen8ktmFrQ3MGRQ/NRl5wJUqg7XY/ouFzYj8pZs=;\n b=MX1D56tTvB54LUBRPquyxjq8b9es33zDeDHhuMaMUCCRs3SOJh4Qln09ZXEhs2L0TgRI\n +E0fWTiUrMjAF4dA1FFCOvcAZouWuKTPn7OgbHa0WAy6aJsBoqYEez06jKfovY5s9Ocy\n P5TRew8876ZfxPXJsT4Jc5FZQNIz+BeeT3vjzk+iOs1cVcwQT073Jct3Ub6jZNtz4vIj\n giW87yXX3+0WsXasfnInOnbVl289PoFOOT1g96rxVcG9iSga5ASEztKwccXztIpLX85F\n y4b8KiDRQZsPsv5zIq3Hw5i4/sqZYA6MvQAlyRchFdSE0m6HWIV6mHJEiboR2QzAl0Ew 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 1/1] app/mldev: add internal function for file read",
        "Date": "Thu, 23 Mar 2023 08:28:01 -0700",
        "Message-ID": "<20230323152801.27666-1-syalavarthi@marvell.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain",
        "X-Proofpoint-GUID": "e4pzS0_bkHYHaY9w1IgOXiVo2QCujgP3",
        "X-Proofpoint-ORIG-GUID": "e4pzS0_bkHYHaY9w1IgOXiVo2QCujgP3",
        "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22\n definitions=2023-03-22_21,2023-03-23_02,2023-02-09_01",
        "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---\n app/test-mldev/test_common.c           | 59 ++++++++++++++++++++++++++\n app/test-mldev/test_common.h           |  2 +\n app/test-mldev/test_inference_common.c | 54 +++++++++--------------\n app/test-mldev/test_model_common.c     | 33 +++-----------\n 4 files changed, 87 insertions(+), 61 deletions(-)",
    "diff": "diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c\nindex 016b31c6ba..3f450d6a4d 100644\n--- a/app/test-mldev/test_common.c\n+++ b/app/test-mldev/test_common.c\n@@ -5,12 +5,71 @@\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+int\n+ml_read_file(char *file, size_t *size, char **buffer)\n+{\n+\tchar *file_buffer = NULL;\n+\tlong file_size = 0;\n+\tint ret = 0;\n+\tFILE *fp;\n+\n+\tfp = fopen(file, \"r\");\n+\tif (fp == NULL) {\n+\t\tml_err(\"Failed to open file: %s\\n\", file);\n+\t\treturn -EIO;\n+\t}\n+\n+\tif (fseek(fp, 0, SEEK_END) == 0) {\n+\t\tfile_size = ftell(fp);\n+\t\tif (file_size == -1) {\n+\t\t\tret = -EIO;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tfile_buffer = rte_malloc(NULL, file_size, RTE_CACHE_LINE_SIZE);\n+\t\tif (file_buffer == NULL) {\n+\t\t\tml_err(\"Failed to allocate memory: %s\\n\", file);\n+\t\t\tret = -ENOMEM;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tif (fseek(fp, 0, SEEK_SET) != 0) {\n+\t\t\tret = -EIO;\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tif (fread(file_buffer, sizeof(char), file_size, fp) != (unsigned long)file_size) {\n+\t\t\tml_err(\"Failed to read file : %s\\n\", file);\n+\t\t\tret = -EIO;\n+\t\t\tgoto error;\n+\t\t}\n+\t\tfclose(fp);\n+\t} else {\n+\t\tret = -EIO;\n+\t\tgoto error;\n+\t}\n+\n+\t*buffer = file_buffer;\n+\t*size = file_size;\n+\n+\treturn 0;\n+\n+error:\n+\trte_free(file_buffer);\n+\n+\tif (fp != NULL)\n+\t\tfclose(fp);\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 a7b2ea652a..7e3634b0c6 100644\n--- a/app/test-mldev/test_common.h\n+++ b/app/test-mldev/test_common.h\n@@ -24,4 +24,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 af831fc1bf..c8cd80d69f 100644\n--- a/app/test-mldev/test_inference_common.c\n+++ b/app/test-mldev/test_inference_common.c\n@@ -604,10 +604,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@@ -647,51 +647,35 @@ 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\trte_free(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 \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\trte_free(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@@ -723,6 +707,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+\trte_free(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..7a8c284d13 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,31 +26,10 @@ 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",
    "prefixes": [
        "1/1"
    ]
}