Show a patch.

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

{
    "id": 16134,
    "url": "https://patchwork.libcamera.org/api/patches/16134/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16134/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20220602085548.13630-1-ecurtin@redhat.com>",
    "date": "2022-06-02T08:55:48",
    "name": "[libcamera-devel,v2] cam: drm: Support /dev/dri cards other than 0",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1a41f114de2343f970d526559b92c784777d41fe",
    "submitter": {
        "id": 101,
        "url": "https://patchwork.libcamera.org/api/people/101/?format=api",
        "name": "Eric Curtin",
        "email": "ecurtin@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16134/mbox/",
    "series": [
        {
            "id": 3154,
            "url": "https://patchwork.libcamera.org/api/series/3154/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3154",
            "date": "2022-06-02T08:55:48",
            "name": "[libcamera-devel,v2] cam: drm: Support /dev/dri cards other than 0",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3154/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16134/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16134/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 BEEA2BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jun 2022 08:56:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1702665638;\n\tThu,  2 Jun 2022 10:56:06 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A7C4165632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jun 2022 10:56:04 +0200 (CEST)",
            "from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) 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-543-AW3VN2LpM4ap5zv9V43CVA-1; Thu, 02 Jun 2022 04:56:02 -0400",
            "by mail-wr1-f70.google.com with SMTP id\n\te7-20020adfa747000000b0020fe61b0c62so640659wrd.22\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 02 Jun 2022 01:56:02 -0700 (PDT)",
            "from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tm129-20020a1ca387000000b003948f4e750fsm7533135wme.23.2022.06.02.01.55.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 02 Jun 2022 01:56:00 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654160166;\n\tbh=2Lnwh1BQO0z8DQF053R24ZL2BCsDYuYv0VMseletmj8=;\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=kYXOsPopsGE1gKs9mvtvXxlzpnl1nzV548SEYUJH2EoB9fvwIitHCOogLEKNwjNSr\n\tB3YjOGQzQUgjSg3Z6sTe3WumLmvTs90BcGj+R3OyF94Ol7Ww2CwxvxoF5GCwdGby5m\n\tIZgugJAr/4klzEhyxFKsgN3dr87ArC1mRO/u9lqYFHzJaO4EuCMpQ6fj+FFgQbOwqo\n\tC/Mgf41BByX9NiNPSyPYsb5TYNhTpfc51HLk1wpxC4Nydp80+p6rN8gGHkechw3vxC\n\tO1ir0DzKjocBgJFbD/CV7ZPchobSyf8xod/BbxbGaiUOqQ/tcCwOsmoyw+TgdWxl+a\n\t0IXue/8rdEhwA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1654160163;\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=EBunYZ86J1L10zUlRGAMD4SCoHnge2SSMW9zjMQdNK0=;\n\tb=g/wANHavJpOWKbw5qN6cL9zXLUXuVZNwNJ95FBLMVpzaHb/X7iax26Er0VZGpSd4wenstB\n\tG6YLL6mPuCuyWjXmvOo9+0N+WDQOcRa4tdfTNbApG5NsTIH53NOvB5XFSKhc+2pKMPfKaU\n\tcrteTSIgZGh/iJ1b4DfaCPQ9dy8AAL8="
        ],
        "Authentication-Results": [
            "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"g/wANHav\"; \n\tdkim-atps=neutral",
            "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"
        ],
        "X-MC-Unique": "AW3VN2LpM4ap5zv9V43CVA-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=EBunYZ86J1L10zUlRGAMD4SCoHnge2SSMW9zjMQdNK0=;\n\tb=Mtdo67Bu4YVx95Hb/h8K+KC0dDrGj70sGWJYrjYIIYD2+8A5PBPyhksY1ARwnLdsZw\n\t5Xu8jVRJ2TbJOgQ80lkFe6v3epyW703QbUcjj6MKXXvGJV+kcRcLOZQYZ1Aw2Ejhwrno\n\tNxXrRKwmk+DNs9WeICZhTEkA2eb8yYp4tsyd65bU2A4+7UqTkujZGciiXBWakxDnSwmz\n\t/2ursoNEYy4NQv6Be8uK160yKPQWD9MXV8X/QuDCG4DGA7f+zjn9QonCRxq5ewkrcsqV\n\t+RO+L2pHqIoVlBdjkN6cD9Kh86s5p+PwMqDEdm7exttgErZb43DHDI1eOakCW3vomYna\n\tE1wQ==",
        "X-Gm-Message-State": "AOAM533KUWaQbqDKE7WmlfAislNvfRU+HhiLeu0+IZYlWcCGR3enyOUv\n\tFWjw7ycZ6pVaINzhWq4U+Fn18mipJoazUhjjw36ED7T6mfNbZqOFX6al7fYmtPlmP4Jgq3Y4Fgd\n\trpFk4IzpFsytInNRk+M5/cXgyHaouYaquBpz0B7iy5XCfjW0f28GzMdidy8MLT7d/+JT4iLqZB6\n\tmk6XyAFdck",
        "X-Received": [
            "by 2002:a5d:4e48:0:b0:210:18bb:6aa1 with SMTP id\n\tr8-20020a5d4e48000000b0021018bb6aa1mr2825490wrt.62.1654160161020; \n\tThu, 02 Jun 2022 01:56:01 -0700 (PDT)",
            "by 2002:a5d:4e48:0:b0:210:18bb:6aa1 with SMTP id\n\tr8-20020a5d4e48000000b0021018bb6aa1mr2825475wrt.62.1654160160785; \n\tThu, 02 Jun 2022 01:56:00 -0700 (PDT)"
        ],
        "X-Google-Smtp-Source": "ABdhPJwDf2Z6Z93ZJlpPCXS82EsUhOjjy+z0Lcw0dzG7oMCCEXyLdFb7JtJHS8/kGvym2dBO1OiUAw==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  2 Jun 2022 09:55:48 +0100",
        "Message-Id": "<20220602085548.13630-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 v2] 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 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..47d9d50c 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+\tstrncpy(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\tstrncpy(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",
        "v2"
    ]
}