Show a patch.

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

{
    "id": 16135,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16135/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16135/",
    "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": "<20220602100017.22272-1-ecurtin@redhat.com>",
    "date": "2022-06-02T10:00:17",
    "name": "[libcamera-devel,v3] cam: drm: Support /dev/dri cards other than 0",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "c447e19f8362ff5e49757270978490469595ea63",
    "submitter": {
        "id": 101,
        "url": "https://patchwork.libcamera.org/api/1.1/people/101/?format=api",
        "name": "Eric Curtin",
        "email": "ecurtin@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16135/mbox/",
    "series": [
        {
            "id": 3155,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3155/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3155",
            "date": "2022-06-02T10:00:17",
            "name": "[libcamera-devel,v3] cam: drm: Support /dev/dri cards other than 0",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3155/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16135/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16135/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 D713BBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jun 2022 10:00:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 719BB65635;\n\tThu,  2 Jun 2022 12:00:29 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88E02633A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jun 2022 12:00:27 +0200 (CEST)",
            "from mail-wm1-f69.google.com (mail-wm1-f69.google.com\n\t[209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-212-la6_YWNVNXmH_aQ2ry5PIQ-1; Thu, 02 Jun 2022 06:00:25 -0400",
            "by mail-wm1-f69.google.com with SMTP id\n\ti1-20020a05600c354100b003976fc71579so2579818wmq.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 02 Jun 2022 03:00:25 -0700 (PDT)",
            "from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\ti6-20020adffc06000000b0020c5253d8dasm3817399wrr.38.2022.06.02.03.00.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 02 Jun 2022 03:00:23 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654164029;\n\tbh=ORhX90oO6yHDqotqCkeXZCAj0s7D7SN8zoPSChOy3fA=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=hRxxOCyP4UhU0s6/HVeqHKqNE9YLFabCWYbBqr/H8+yvRitGbIpsQCTSE+a02QQXc\n\t5GrfrJiGYTwm2qS96GrOKL/niIGAg+bYlcpyfgaqAOV4g80bSEvRUcKv5N9MOY35Je\n\tNoQry9i/979QN2MfC2rIXkGT6FQ0CTKI9DuLdUiqP8l2iaYzxdNC0FqYSTBGov8k4h\n\t7wJlp0t4wBdlYzGo5RZKiNvYMDB5yYKI6Z9NS64Gcqk4uYxZeZNAZR5X0krCXO9Ako\n\tPPKayMllBS8BDDFXOpzOjFsYbvNCgXs2rtVDIM3rm5PRE/3AZbMcH2PCsx2GMnmLvp\n\tvvOvlgtWROSvA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1654164026;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding;\n\tbh=kwMK0gDjxJBGBavll6W7NXHanlMiYF6Z5+Ii/2fUkAM=;\n\tb=GApJglPo8RDWp0g/kYVm78ogttPEXgBQAq9BYlH1ZM80zIGoFK7Con69ulw0BLAfEa30uG\n\tf/ev2yL9utbpwMeMyTm/IjT1SUXyFAJlzEMeWeLmz5R+Qdoo2jaCsclcx8gSUOiFcND978\n\tbE7WJRVMKdI9LPAcwDG7+cyBqMUq9ck="
        ],
        "Authentication-Results": [
            "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"GApJglPo\"; \n\tdkim-atps=neutral",
            "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"
        ],
        "X-MC-Unique": "la6_YWNVNXmH_aQ2ry5PIQ-1",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=kwMK0gDjxJBGBavll6W7NXHanlMiYF6Z5+Ii/2fUkAM=;\n\tb=wuxAVsm3LGyIC0XgzbZfskbGWlpKKBQRFqgwrLWir0x0CgRg+hB/K52YGx3J5obGjY\n\tH7pOJD75KtRhU6oik9Kovihi2nSvFC3d+L5FpC5fZqOYxotSZWsqM6T82xtuelyqijIr\n\tIFpTzEclpVvPzMLzuNyEc5cDCRHG2Njm+JQvzdDvqNAgDIAqVVh42UFsl+s05a1BO0+c\n\tvBuWz8pwjprkEjUtdS4E4Qg7lUODwTF9032dFN0i12IUurhl2L03yPzbguCfPjCG4T3W\n\tke0++UqRPwQf8t5OWLJHa2LVA3Z010ha5bZt9jBF3Pi3htaqJLkPgH6YxJnk5A4LOxPo\n\tmtzw==",
        "X-Gm-Message-State": "AOAM531ASprO/wQ93C0kJNYSrlKQTM4BmNDZvG3fD26p+YaSLUwSfwsF\n\tXfXaGD3eET8XBW5r2jm3YGL5mRqY6p1Ca4xmO5kcAycADRk9tMCYh2zW1SHjZse1V13PBOPq3pK\n\t7l3bB5xL+G70Kp4ZeB5bBc7gWBxRLVzdm+CC/yFPacrxBteJUP6feTECL276+z7tigpAz7o8sLa\n\tEdZVqZPUjx",
        "X-Received": [
            "by 2002:a7b:c4ca:0:b0:397:3bac:9b2a with SMTP id\n\tg10-20020a7bc4ca000000b003973bac9b2amr32102324wmk.154.1654164024163; \n\tThu, 02 Jun 2022 03:00:24 -0700 (PDT)",
            "by 2002:a7b:c4ca:0:b0:397:3bac:9b2a with SMTP id\n\tg10-20020a7bc4ca000000b003973bac9b2amr32102293wmk.154.1654164023830; \n\tThu, 02 Jun 2022 03:00:23 -0700 (PDT)"
        ],
        "X-Google-Smtp-Source": "ABdhPJz2q7oWC04x69LDoKsKDh5tLxrSKrb2EWgBU7saOy6JAQnhYJaZRTYbiwoLQCuLANFpfd1PYA==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  2 Jun 2022 11:00:17 +0100",
        "Message-Id": "<20220602100017.22272-1-ecurtin@redhat.com>",
        "X-Mailer": "git-send-email 2.35.3",
        "MIME-Version": "1.0",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "Subject": "[libcamera-devel] [PATCH v3] cam: drm: Support /dev/dri cards other\n\tthan 0",
        "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>",
        "From": "Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Eric Curtin <ecurtin@redhat.com>",
        "Cc": "Ian Mullins <imullins@redhat.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Existing code is hardcoded to card0. Since recent fedora upgrades, we\nhave noticed on more than one machine that card1 is present as the\nlowest numbered device, could theoretically be higher. This technique\ntries every file starting with card and continue only when we have\nsuccessfully opened one. These devices with card1 as the lowest device\nwere simply failing when they do not see a /dev/dri/card0 file present.\n\nReported-by: Ian Mullins <imullins@redhat.com>\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\n\n---\nChanges in v3:\n- switch back to memcpy, strncpy causing false compiler issue\n\nChanges in v2:\n- return if no valid card found, or directory could not be opened etc.\n- memcpy to strncpy for safety\n- only adjust the numerical bytes for each iteration of loop since\n  /dev/dri/card won't change\n- initialize ret to zero\n---\n src/cam/drm.cpp | 46 ++++++++++++++++++++++++++++++++++++----------\n 1 file changed, 36 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\nindex 42c5a3b1..7975a502 100644\n--- a/src/cam/drm.cpp\n+++ b/src/cam/drm.cpp\n@@ -8,6 +8,7 @@\n #include \"drm.h\"\n \n #include <algorithm>\n+#include <dirent.h>\n #include <errno.h>\n #include <fcntl.h>\n #include <iostream>\n@@ -393,9 +394,13 @@ Device::~Device()\n \n int Device::init()\n {\n-\tconstexpr size_t NODE_NAME_MAX = sizeof(\"/dev/dri/card255\");\n-\tchar name[NODE_NAME_MAX];\n-\tint ret;\n+\tconstexpr size_t DIR_NAME_MAX = sizeof(\"/dev/dri/\");\n+\tconstexpr size_t PRE_NODE_NAME_MAX = sizeof(\"card\");\n+\tconstexpr size_t POST_NODE_NAME_MAX = sizeof(\"255\");\n+\tconstexpr size_t NODE_NAME_MAX =\n+\t\tDIR_NAME_MAX + PRE_NODE_NAME_MAX + POST_NODE_NAME_MAX - 2;\n+\tchar name[NODE_NAME_MAX] = \"/dev/dri/\";\n+\tint ret = 0;\n \n \t/*\n \t * Open the first DRM/KMS device. The libdrm drmOpen*() functions\n@@ -404,14 +409,35 @@ int Device::init()\n \t * from drmOpen() is of no practical use as any modern system will\n \t * handle that through udev or an equivalent component.\n \t */\n-\tsnprintf(name, sizeof(name), \"/dev/dri/card%u\", 0);\n-\tfd_ = open(name, O_RDWR | O_CLOEXEC);\n+\tDIR *folder = opendir(name);\n+\tmemcpy(name + DIR_NAME_MAX - 1, \"card\", PRE_NODE_NAME_MAX);\n+\tif (folder) {\n+\t\tfor (struct dirent *res; (res = readdir(folder));) {\n+\t\t\tif (!strncmp(res->d_name, \"card\", 4)) {\n+\t\t\t\tmemcpy(name + DIR_NAME_MAX +\n+\t\t\t\t\t\tPRE_NODE_NAME_MAX - 2,\n+\t\t\t\t\tres->d_name + PRE_NODE_NAME_MAX - 1,\n+\t\t\t\t\tPOST_NODE_NAME_MAX);\n+\t\t\t\tfd_ = open(name, O_RDWR | O_CLOEXEC);\n+\t\t\t\tif (fd_ < 0) {\n+\t\t\t\t\tret = -errno;\n+\t\t\t\t\tstd::cerr\n+\t\t\t\t\t\t<< \"Failed to open DRM/KMS device \"\n+\t\t\t\t\t\t<< name << \": \"\n+\t\t\t\t\t\t<< strerror(-ret) << std::endl;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t\tclosedir(folder);\n+\t}\n+\n \tif (fd_ < 0) {\n-\t\tret = -errno;\n-\t\tstd::cerr\n-\t\t\t<< \"Failed to open DRM/KMS device \" << name << \": \"\n-\t\t\t<< strerror(-ret) << std::endl;\n-\t\treturn ret;\n+\t\tstd::cerr << \"Unable to open any DRM/KMS device\" << std::endl;\n+\t\treturn ret ? ret : -ENOENT;\n \t}\n \n \t/*\n",
    "prefixes": [
        "libcamera-devel",
        "v3"
    ]
}