Show a patch.

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

{
    "id": 9374,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/9374/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/9374/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200823182900.18247-1-laurent.pinchart@ideasonboard.com>",
    "date": "2020-08-23T18:29:00",
    "name": "[libcamera-devel] android: camera_device: Hold reference to self when open",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "aeea940fe134621f4016bd36d41832f831d358fd",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": {
        "id": 14,
        "url": "https://patchwork.libcamera.org/api/1.1/users/14/?format=api",
        "username": "pinchartl",
        "first_name": "Laurent",
        "last_name": "Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/9374/mbox/",
    "series": [
        {
            "id": 1238,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1238/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1238",
            "date": "2020-08-23T18:29:00",
            "name": "[libcamera-devel] android: camera_device: Hold reference to self when open",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1238/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/9374/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/9374/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CAB92BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 23 Aug 2020 18:29:26 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 57BBA61ED9;\n\tSun, 23 Aug 2020 20:29:26 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C3D306037F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Aug 2020 20:29:24 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B5BA5279;\n\tSun, 23 Aug 2020 20:29:21 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LYTOdQxo\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1598207361;\n\tbh=3OtNntFbc5bgGwg9uxiY3M/yCcy4H7r/DVHylt2SfCw=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=LYTOdQxoZJhRA6vYOqIpNVYusBgYNJKewBYMNutkqxLF6kiaOj2EoW6DCB01O98Cl\n\tMjGcxHQ1dsmyl//qN/ExjSk8qp/nEfMCsfYuZBjTfb0DqkXSZ/xhbjjNKjFo9e2WLd\n\ts1VH/hjlxtLWQ/4FsPp1TnicO48HN3xVHTvcPJgI=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sun, 23 Aug 2020 21:29:00 +0300",
        "Message-Id": "<20200823182900.18247-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH] android: camera_device: Hold reference to\n\tself when open",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "CameraDevice instances are managed through shared pointers to support\nhptplug. No reference is however taken on the device when opened by the\ncamera service, which could cause an open device to be deleted if\nunplugged, leading to a crash when the device is next accessed.\n\nFix this by taking a reference when opening a device, and releasing it\nat close time. The reference is stored in the CameraDevice instance\nitself, which is more efficient than storing it in a container in the\nCameraHalManager as that would require lookup operations.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.cpp | 12 ++++++++++++\n src/android/camera_device.h   |  4 +++-\n 2 files changed, 15 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex de6f86f7cb9b..52468be70781 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -459,6 +459,12 @@ int CameraDevice::open(const hw_module_t *hardwareModule)\n \tcamera3Device_.ops = &hal_dev_ops;\n \tcamera3Device_.priv = this;\n \n+\t/*\n+\t * Hold a reference to ourselves, to protect against deletion if the\n+\t * camera is unplugged before being closed.\n+\t */\n+\tself_ = shared_from_this();\n+\n \treturn 0;\n }\n \n@@ -468,6 +474,12 @@ void CameraDevice::close()\n \tcamera_->release();\n \n \trunning_ = false;\n+\n+\t/*\n+\t * Drop our self reference. From this point the CameraDevice may get\n+\t * deleted at any time.\n+\t */\n+\tself_.reset();\n }\n \n void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks)\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 3934f194f1b5..fd991c76b90d 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -44,7 +44,8 @@ struct CameraStream {\n \tEncoder *jpeg;\n };\n \n-class CameraDevice : protected libcamera::Loggable\n+class CameraDevice : public std::enable_shared_from_this<CameraDevice>,\n+\t\t     protected libcamera::Loggable\n {\n public:\n \tstatic std::shared_ptr<CameraDevice> create(unsigned int id,\n@@ -104,6 +105,7 @@ private:\n \n \tunsigned int id_;\n \tcamera3_device_t camera3Device_;\n+\tstd::shared_ptr<CameraDevice> self_;\n \n \tbool running_;\n \tstd::shared_ptr<libcamera::Camera> camera_;\n",
    "prefixes": [
        "libcamera-devel"
    ]
}