get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 806972,
    "url": "http://patchwork.ozlabs.org/api/patches/806972/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/skiboot/patch/20170829062506.8317-12-cyril.bur@au1.ibm.com/",
    "project": {
        "id": 44,
        "url": "http://patchwork.ozlabs.org/api/projects/44/?format=api",
        "name": "skiboot firmware development",
        "link_name": "skiboot",
        "list_id": "skiboot.lists.ozlabs.org",
        "list_email": "skiboot@lists.ozlabs.org",
        "web_url": "http://github.com/open-power/skiboot",
        "scm_url": "http://github.com/open-power/skiboot",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20170829062506.8317-12-cyril.bur@au1.ibm.com>",
    "list_archive_url": null,
    "date": "2017-08-29T06:25:04",
    "name": "[RFC,11/13] libflash/libffs: Refcount ffs entries",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": false,
    "hash": "5d7e078d0458728e4830689698b3f392c67f9695",
    "submitter": {
        "id": 64738,
        "url": "http://patchwork.ozlabs.org/api/people/64738/?format=api",
        "name": "Cyril Bur",
        "email": "cyril.bur@au1.ibm.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/skiboot/patch/20170829062506.8317-12-cyril.bur@au1.ibm.com/mbox/",
    "series": [
        {
            "id": 313,
            "url": "http://patchwork.ozlabs.org/api/series/313/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/skiboot/list/?series=313",
            "date": "2017-08-29T06:24:53",
            "name": "Rework flash TOC generation",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/313/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/806972/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/806972/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "skiboot@lists.ozlabs.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@bilbo.ozlabs.org",
            "skiboot@lists.ozlabs.org"
        ],
        "Received": [
            "from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xhJwq5ws0z9ryr\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 16:42:51 +1000 (AEST)",
            "from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xhJwq4HXQzDqZB\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 16:42:51 +1000 (AEST)",
            "from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com\n\t[148.163.156.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xhJY65Y3yzDqb5\n\tfor <skiboot@lists.ozlabs.org>; Tue, 29 Aug 2017 16:25:46 +1000 (AEST)",
            "from pps.filterd (m0098394.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv7T6OWCG120155\n\tfor <skiboot@lists.ozlabs.org>; Tue, 29 Aug 2017 02:25:41 -0400",
            "from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2cn1kje0kp-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <skiboot@lists.ozlabs.org>; Tue, 29 Aug 2017 02:25:40 -0400",
            "from localhost\n\tby e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <skiboot@lists.ozlabs.org> from <cyril.bur@au1.ibm.com>;\n\tTue, 29 Aug 2017 16:25:38 +1000",
            "from d23relay07.au.ibm.com (202.81.31.226)\n\tby e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tTue, 29 Aug 2017 16:25:37 +1000",
            "from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\n\tby d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n\tv7T6Pabe37355602\n\tfor <skiboot@lists.ozlabs.org>; Tue, 29 Aug 2017 16:25:36 +1000",
            "from d23av04.au.ibm.com (localhost [127.0.0.1])\n\tby d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id\n\tv7T6PbgY017789\n\tfor <skiboot@lists.ozlabs.org>; Tue, 29 Aug 2017 16:25:37 +1000",
            "from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14])\n\tby d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id\n\tv7T6PaBg017744; Tue, 29 Aug 2017 16:25:36 +1000",
            "from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114])\n\t(using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby ozlabs.au.ibm.com (Postfix) with ESMTPSA id 9C76DA0259;\n\tTue, 29 Aug 2017 16:25:35 +1000 (AEST)"
        ],
        "From": "Cyril Bur <cyril.bur@au1.ibm.com>",
        "To": "skiboot@lists.ozlabs.org, stewart@linux.vnet.ibm.com",
        "Date": "Tue, 29 Aug 2017 16:25:04 +1000",
        "X-Mailer": "git-send-email 2.14.1",
        "In-Reply-To": "<20170829062506.8317-1-cyril.bur@au1.ibm.com>",
        "References": "<20170829062506.8317-1-cyril.bur@au1.ibm.com>",
        "X-TM-AS-MML": "disable",
        "x-cbid": "17082906-0012-0000-0000-0000025A9F5B",
        "X-IBM-AV-DETECTION": "SAVI=unused REMOTE=unused XFE=unused",
        "x-cbparentid": "17082906-0013-0000-0000-0000077669DE",
        "Message-Id": "<20170829062506.8317-12-cyril.bur@au1.ibm.com>",
        "X-Proofpoint-Virus-Version": "vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-08-29_01:, , signatures=0",
        "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1708290096",
        "Subject": "[Skiboot] [RFC PATCH 11/13] libflash/libffs: Refcount ffs entries",
        "X-BeenThere": "skiboot@lists.ozlabs.org",
        "X-Mailman-Version": "2.1.23",
        "Precedence": "list",
        "List-Id": "Mailing list for skiboot development <skiboot.lists.ozlabs.org>",
        "List-Unsubscribe": "<https://lists.ozlabs.org/options/skiboot>,\n\t<mailto:skiboot-request@lists.ozlabs.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.ozlabs.org/pipermail/skiboot/>",
        "List-Post": "<mailto:skiboot@lists.ozlabs.org>",
        "List-Help": "<mailto:skiboot-request@lists.ozlabs.org?subject=help>",
        "List-Subscribe": "<https://lists.ozlabs.org/listinfo/skiboot>,\n\t<mailto:skiboot-request@lists.ozlabs.org?subject=subscribe>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "base64",
        "Errors-To": "skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org",
        "Sender": "\"Skiboot\"\n\t<skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"
    },
    "content": "Currently consumers can add an new ffs entry to multiple headers, this\nis fine but freeing any of the headers will cause the entry to be freed,\nthis causes double free problems.\n\nEven if only one header is uses, the consumer of the library still has a\nreference to the entry, which they may well reuse at some other point.\n\nlibffs will now refcount entries and only free when there are no more\nreferences.\n\nThis patch also removes the pointless return value of ffs_hdr_free()\n\nSigned-off-by: Cyril Bur <cyril.bur@au1.ibm.com>\n---\n external/ffspart/ffspart.c |  2 +-\n external/pflash/pflash.c   |  2 ++\n libflash/ffs.h             |  2 ++\n libflash/libffs.c          | 38 +++++++++++++++++++++++++++++++-------\n libflash/libffs.h          |  4 +++-\n 5 files changed, 39 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c\nindex 74e12ff6..cd944651 100644\n--- a/external/ffspart/ffspart.c\n+++ b/external/ffspart/ffspart.c\n@@ -338,7 +338,7 @@ out_if:\n \n \t\tcontinue;\n out_while:\n-\t\tfree(new_entry);\n+\t\tffs_entry_put(new_entry);\n \t\tgoto out_close_bl;\n \t}\n \ndiff --git a/external/pflash/pflash.c b/external/pflash/pflash.c\nindex 3be43ac0..f7610710 100644\n--- a/external/pflash/pflash.c\n+++ b/external/pflash/pflash.c\n@@ -116,6 +116,7 @@ static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc)\n \t\t}\n \n \t\tuser = ffs_entry_user_get(ent);\n+\t\tffs_entry_put(ent);\n \t\tflags = ffs_entry_user_to_string(&user);\n \t\tif (!flags)\n \t\t\tgoto out;\n@@ -567,6 +568,7 @@ static void print_partition_detail(struct ffs_handle *ffsh, uint32_t part_id)\n \t\t\thas_flag(ent, FFS_MISCFLAGS_BACKUP) ? \"BACKUP [B]\\n\" : \"\",\n \t\t\thas_flag(ent, FFS_MISCFLAGS_REPROVISION) ?\n \t\t\t\t\t\"REPROVISION [F]\\n\" : \"\");\n+\tffs_entry_put(ent);\n \tif (l < 0) {\n \t\tfprintf(stderr, \"Memory allocation failure printing flags!\\n\");\n \t\tgoto out;\ndiff --git a/libflash/ffs.h b/libflash/ffs.h\nindex 7a362215..6a5ad49f 100644\n--- a/libflash/ffs.h\n+++ b/libflash/ffs.h\n@@ -149,6 +149,7 @@ struct __ffs_entry {\n  * @type:\tDescribe type of partition\n  * @flags:\tPartition attributes (optional)\n  * @user:\tUser data (optional)\n+ * @ref:\tRefcount\n  */\n struct ffs_entry {\n \tchar name[FFS_PART_NAME_MAX + 1];\n@@ -159,6 +160,7 @@ struct ffs_entry {\n \tenum ffs_type type;\n \tuint32_t flags;\n \tstruct ffs_entry_user user;\n+\tunsigned int ref;\n };\n \n \ndiff --git a/libflash/libffs.c b/libflash/libffs.c\nindex 8c46ce7e..a9a2b961 100644\n--- a/libflash/libffs.c\n+++ b/libflash/libffs.c\n@@ -268,13 +268,35 @@ bool has_flag(struct ffs_entry *ent, uint16_t flag)\n \treturn ((ent->user.miscflags & flag) != 0);\n }\n \n-struct ffs_entry *ffs_entry_get(struct ffs_handle *ffs, uint32_t index)\n+static struct ffs_entry *__ffs_entry_get(struct ffs_handle *ffs, uint32_t index)\n {\n-\tif (!ffs || index >= ffs->hdr.count)\n+\tif (index >= ffs->hdr.count)\n \t\treturn NULL;\n \treturn ffs->hdr.entries[index];\n }\n \n+struct ffs_entry *ffs_entry_get(struct ffs_handle *ffs, uint32_t index)\n+{\n+\tstruct ffs_entry *ret = __ffs_entry_get(ffs, index);\n+\tif (ret)\n+\t\tret->ref++;\n+\treturn ret;\n+}\n+\n+struct ffs_entry *ffs_entry_put(struct ffs_entry *ent)\n+{\n+\tif (!ent)\n+\t\treturn NULL;\n+\n+\tent->ref--;\n+\tif (ent->ref == 0) {\n+\t\tfree(ent);\n+\t\tent = NULL;\n+\t}\n+\n+\treturn ent;\n+}\n+\n bool has_ecc(struct ffs_entry *ent)\n {\n \treturn ((ent->user.datainteg & FFS_ENRY_INTEG_ECC) != 0);\n@@ -390,6 +412,7 @@ int ffs_init(uint32_t offset, uint32_t max_size, struct blocklevel_device *bl,\n \t\t}\n \n \t\tf->hdr.entries[f->hdr.count++] = ent;\n+\t\tent->ref = 1;\n \t\trc = ffs_entry_to_cpu(&f->hdr, ent, &f->cache->entries[i]);\n \t\tif (rc) {\n \t\t\tFL_DBG(\"FFS: Failed checksum for partition %s\\n\",\n@@ -424,15 +447,14 @@ static void __hdr_free(struct ffs_hdr *hdr)\n \t\treturn;\n \n \tfor (i = 0; i < hdr->count; i++)\n-\t\tfree(hdr->entries[i]);\n+\t\tffs_entry_put(hdr->entries[i]);\n \tfree(hdr->entries);\n }\n \n-int ffs_hdr_free(struct ffs_hdr *hdr)\n+void ffs_hdr_free(struct ffs_hdr *hdr)\n {\n \t__hdr_free(hdr);\n \tfree(hdr);\n-\treturn 0;\n }\n \n void ffs_close(struct ffs_handle *ffs)\n@@ -471,7 +493,7 @@ int ffs_part_info(struct ffs_handle *ffs, uint32_t part_idx,\n \tstruct ffs_entry *ent;\n \tchar *n;\n \n-\tent = ffs_entry_get(ffs, part_idx);\n+\tent = __ffs_entry_get(ffs, part_idx);\n \tif (!ent)\n \t\treturn FFS_ERR_PART_NOT_FOUND;\n \n@@ -597,6 +619,7 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry)\n \t\t}\n \t\thdr->entries_size += HDR_ENTRIES_NUM;\n \t}\n+\tentry->ref++;\n \thdr->entries[hdr->count++] = entry;\n \n \treturn 0;\n@@ -714,6 +737,7 @@ int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_ent\n \tret->actual = size;\n \tret->pid = FFS_PID_TOPLEVEL;\n \tret->type = FFS_TYPE_DATA;\n+\tret->ref = 1;\n \n \t*r = ret;\n \treturn 0;\n@@ -776,7 +800,7 @@ int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx,\n \tuint32_t offset;\n \tint rc;\n \n-\tent = ffs_entry_get(ffs, part_idx);\n+\tent = __ffs_entry_get(ffs, part_idx);\n \tif (!ent) {\n \t\tFL_DBG(\"FFS: Entry not found\\n\");\n \t\treturn FFS_ERR_PART_NOT_FOUND;\ndiff --git a/libflash/libffs.h b/libflash/libffs.h\nindex 56428a2c..eabca23a 100644\n--- a/libflash/libffs.h\n+++ b/libflash/libffs.h\n@@ -145,6 +145,8 @@ int ffs_hdr_add_side(struct ffs_hdr *hdr);\n \n int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_entry **r);\n \n+struct ffs_entry *ffs_entry_put(struct ffs_entry *ent);\n+\n int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user);\n \n int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size);\n@@ -156,5 +158,5 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry);\n \n int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr);\n \n-int ffs_hdr_free(struct ffs_hdr *hdr);\n+void ffs_hdr_free(struct ffs_hdr *hdr);\n #endif /* __LIBFFS_H */\n",
    "prefixes": [
        "RFC",
        "11/13"
    ]
}