get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2219703,
    "url": "http://patchwork.ozlabs.org/api/patches/2219703/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260403205011.15962-1-guobin@linux.alibaba.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "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": "<20260403205011.15962-1-guobin@linux.alibaba.com>",
    "list_archive_url": null,
    "date": "2026-04-03T20:50:11",
    "name": "vhost: return early when memslots overflow in vhost_get_free_memslots()",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "5d5ac31ed584d63fcd075e469bc6516145a89426",
    "submitter": {
        "id": 91693,
        "url": "http://patchwork.ozlabs.org/api/people/91693/?format=api",
        "name": "Bin Guo",
        "email": "guobin@linux.alibaba.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260403205011.15962-1-guobin@linux.alibaba.com/mbox/",
    "series": [
        {
            "id": 498676,
            "url": "http://patchwork.ozlabs.org/api/series/498676/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=498676",
            "date": "2026-04-03T20:50:11",
            "name": "vhost: return early when memslots overflow in vhost_get_free_memslots()",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/498676/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2219703/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2219703/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@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com\n header.a=rsa-sha256 header.s=default header.b=KRd3V7Tq;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fnW9d6xfbz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 04 Apr 2026 07:51:48 +1100 (AEDT)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w8lTc-0001MX-C0; Fri, 03 Apr 2026 16:50:48 -0400",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <guobin@linux.alibaba.com>)\n id 1w8lTa-0001M1-AG\n for qemu-devel@nongnu.org; Fri, 03 Apr 2026 16:50:46 -0400",
            "from out30-97.freemail.mail.aliyun.com ([115.124.30.97])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <guobin@linux.alibaba.com>)\n id 1w8lTV-000093-11\n for qemu-devel@nongnu.org; Fri, 03 Apr 2026 16:50:46 -0400",
            "from localhost(mailfrom:guobin@linux.alibaba.com\n fp:SMTPD_---0X0L1tvp_1775249411 cluster:ay36) by smtp.aliyun-inc.com;\n Sat, 04 Apr 2026 04:50:27 +0800"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linux.alibaba.com; s=default;\n t=1775249428; h=From:To:Subject:Date:Message-ID:MIME-Version;\n bh=S0gH1RNVZ2+dFXuhhk/p/ALCB/w4E8iigHAamMgF1fA=;\n b=KRd3V7Tq7twL5/XZS5am9rGYgrgZSDtflH0IFP+AHm7RxCX/kYzf6ebkI9KIA2sj8eAvZMongoyQfzDCoyqX5xkkj4RRtUNWiCmGEfZL8Sbsx9PyxfAoocv+LQeeX2XpQcfeKotgBdKpIpLH1LEfbZ35NNNDzGKkCExtOPrW0ms=",
        "X-Alimail-AntiSpam": "AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green;\n DM=||false|;\n DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam011083073210;\n MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=4; SR=0;\n TI=SMTPD_---0X0L1tvp_1775249411;",
        "From": "Bin Guo <guobin@linux.alibaba.com>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "mst@redhat.com,\n\trichard.henderson@linaro.org,\n\tphilmd@linaro.org",
        "Subject": "[PATCH] vhost: return early when memslots overflow in\n vhost_get_free_memslots()",
        "Date": "Sat,  4 Apr 2026 04:50:11 +0800",
        "Message-ID": "<20260403205011.15962-1-guobin@linux.alibaba.com>",
        "X-Mailer": "git-send-email 2.50.1",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Received-SPF": "pass client-ip=115.124.30.97;\n envelope-from=guobin@linux.alibaba.com;\n helo=out30-97.freemail.mail.aliyun.com",
        "X-Spam_score_int": "-174",
        "X-Spam_score": "-17.5",
        "X-Spam_bar": "-----------------",
        "X-Spam_report": "(-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,\n UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5,\n USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no",
        "X-Spam_action": "no action",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "qemu development <qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<https://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 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"
    },
    "content": "The vhost_get_free_memslots() function continues iterating through all\nvhost devices even after detecting a memslot overflow, which is\nunnecessary since the result is already determined to be 0.\n\nUse early return to immediately exit the loop when overflow is detected,\navoiding redundant iterations and unnecessary arithmetic operations.\nThis optimizes the best case from O(n) to O(1) when the first device\noverflows, and saves n-k iterations on average where k is the position\nof the overflowing device.\n\nSigned-off-by: Bin Guo <guobin@linux.alibaba.com>\n---\n hw/virtio/vhost.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c\nindex b9dc4ed13b..9d1b56fa34 100644\n--- a/hw/virtio/vhost.c\n+++ b/hw/virtio/vhost.c\n@@ -70,15 +70,16 @@ unsigned int vhost_get_free_memslots(void)\n \n     QLIST_FOREACH(hdev, &vhost_devices, entry) {\n         unsigned int r = hdev->vhost_ops->vhost_backend_memslots_limit(hdev);\n-        unsigned int cur_free = r - hdev->mem->nregions;\n+        unsigned int cur_free;\n \n         if (unlikely(r < hdev->mem->nregions)) {\n             warn_report_once(\"used (%u) vhost backend memory slots exceed\"\n                              \" the device limit (%u).\", hdev->mem->nregions, r);\n-            free = 0;\n-        } else {\n-            free = MIN(free, cur_free);\n+            return 0;\n         }\n+\n+        cur_free = r - hdev->mem->nregions;\n+        free = MIN(free, cur_free);\n     }\n     return free;\n }\n",
    "prefixes": []
}