Show a patch.

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

{
    "id": 16178,
    "url": "https://patchwork.libcamera.org/api/patches/16178/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16178/",
    "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": "<20220606142743.10104-1-ecurtin@redhat.com>",
    "date": "2022-06-06T14:27:45",
    "name": "[libcamera-devel,v4] cam: drm: Support /dev/dri cards other than 0",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1cf3669ebc79e44e5eedd5cd562aecf282fae77f",
    "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/16178/mbox/",
    "series": [
        {
            "id": 3164,
            "url": "https://patchwork.libcamera.org/api/series/3164/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3164",
            "date": "2022-06-06T14:27:45",
            "name": "[libcamera-devel,v4] cam: drm: Support /dev/dri cards other than 0",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/3164/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16178/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16178/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 C2946BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Jun 2022 14:37:24 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 156B96559A;\n\tMon,  6 Jun 2022 16:37:24 +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 01891633A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Jun 2022 16:37:21 +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-546-5Z3qzFWaPH2HfqRC3RMaNQ-1; Mon, 06 Jun 2022 10:37:19 -0400",
            "by mail-wm1-f69.google.com with SMTP id\n\tk5-20020a05600c1c8500b003974c5d636dso7807069wms.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 06 Jun 2022 07:37:19 -0700 (PDT)",
            "from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tf6-20020a05600c154600b00397402ae674sm23454274wmg.11.2022.06.06.07.37.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 06 Jun 2022 07:37:17 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654526244;\n\tbh=sWl4DGzQEQnl1S51AcMjzWRVRieIHU4KR80MPi7uYmA=;\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=cBIvOOek4GL1zVcpD4kMH3wttpahsgv/Cx0akHQpOiUHqyHFvLdlNCommvjzbLu0g\n\tsw/orxUUXb8xyz2+EOy0N2hkXDjbxHmbFvfZpwYr/NIJNeDVx1p5JjNh+jIUNuNUU2\n\tXPutqOEGP6QG1yuPfh6u6y73UEnzBGV7HJETG6HR83gUR5/jY5WvvC+HHttdR4xnMc\n\tCrHoBccXeKw/TvTV7QrQ5VbX2h/cAQSEBMVJAzPswqN07GIdI3dmpYKl1YSqGriRZ+\n\tlfjdBfj/l+mNpBU8tyzi8WHxUISf07cKVBtWWArwOr9VQ4YxwFihsQ8ksmXNieBfSe\n\tKaMwGgFm/NBpQ==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1654526240;\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=DEYiMRrUYvHvMPOK9LrW7DcjnyOcBu7oUMDbhYTaMgs=;\n\tb=Lk5uq8IFTodrKJ29DEj6IZe2zjqBARSYpWvPjGEflyYuWfU3T5MXtWNVE7VtYI8mAyxLi9\n\tifEwsrwqZOKyNM40KVlkBfJ1enQUZd6npafOi5lPfABhOCJc/HfwiWOYBiQ6OaszBF6sTB\n\tLL5aPYVyKIkM4+F4oElA2cA49l7dGn8="
        ],
        "Authentication-Results": [
            "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"Lk5uq8IF\"; \n\tdkim-atps=neutral",
            "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"
        ],
        "X-MC-Unique": "5Z3qzFWaPH2HfqRC3RMaNQ-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=DEYiMRrUYvHvMPOK9LrW7DcjnyOcBu7oUMDbhYTaMgs=;\n\tb=rWVSYD/F4Jtj/1VOh3cU4y97GkpUkEtdEaAy9fwXCqPwrTk52xFUEGmHsjQ6HFHzz3\n\tvNSxc2zKHFqqFCBRQJ+I65or/n1K+dtJtHc+S4sRVq+o5uqlu7+DR0A/wwm8lRmWCdwF\n\tO0v4wixhntOE2Om21EGGYJCaUIee2nx3+nqFXv3BhBJ37YfWI0b9rZmf6VzbGqqKzwty\n\tAKFGF3SweMJfjenxwUjLBHFC7z6brBV75J9ivnZU1PjXHUXiSe4VHgrWK7usvEQcWB35\n\ttqRJ52bGcuOFj3BANYRg4DVcDfvpOP7ZbIH0ESrAU3NN9fYsU/dp0iPCxnItHhvP53/J\n\tdEfA==",
        "X-Gm-Message-State": "AOAM532AUqQLFbmNVf0BlKntlOETOfiW+Z6SRwrbW3frfQwD4QbqTSB9\n\t21v8nX50Xwiyzk5AZb8iPWt10U5SujhVh/GFG/jF8s3GfOzYiKz89z7xNZvae7pxG4pPBx/mrkr\n\t/z4wfirv/GOT+9ogLy+zVxAiPOQZ2qlzo03a2CeuuNall7oAH4UPGGqvcLv3wi8zPG7fi0O58iH\n\tDCm5KKK2yk",
        "X-Received": [
            "by 2002:a5d:598e:0:b0:20f:c2fd:de44 with SMTP id\n\tn14-20020a5d598e000000b0020fc2fdde44mr21991994wri.178.1654526237984; \n\tMon, 06 Jun 2022 07:37:17 -0700 (PDT)",
            "by 2002:a5d:598e:0:b0:20f:c2fd:de44 with SMTP id\n\tn14-20020a5d598e000000b0020fc2fdde44mr21991940wri.178.1654526237509; \n\tMon, 06 Jun 2022 07:37:17 -0700 (PDT)"
        ],
        "X-Google-Smtp-Source": "ABdhPJwdNl2xYRmbj8JUOwHwhGj4jfduyVPQJYHGo1/3BaM/kLMaYgI/2xbtyaUOWG8aniKc2XOvtg==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  6 Jun 2022 15:27:45 +0100",
        "Message-Id": "<20220606142743.10104-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 v4] 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>,\n\tJavier Martinez Canillas <fmartine@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>\nTested-by: Ian Mullins <imullins@redhat.com>\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\n\n---\nChanges in v4:\n- added Tested-by tag\n- std::stringified things\n- changed if conditions to reduce indentations\n- constexpr sizes now don't include null terminator\n- just return -ENOENT if no device was successfully opened. \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, 37 insertions(+), 9 deletions(-)",
    "diff": "diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\nindex 42c5a3b1..d05b7f5f 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,15 @@ 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/\") - 1;\n+\tconstexpr size_t PRE_NODE_NAME_MAX = sizeof(\"card\") - 1;\n+\tconstexpr size_t POST_NODE_NAME_MAX = sizeof(\"255\") - 1;\n+\tconstexpr size_t NODE_NAME_MAX =\n+\t\tDIR_NAME_MAX + PRE_NODE_NAME_MAX + POST_NODE_NAME_MAX;\n+\tstd::string name;\n+\tname.reserve(NODE_NAME_MAX);\n+\tname = \"/dev/dri/\";\n+\tint ret = 0;\n \n \t/*\n \t * Open the first DRM/KMS device. The libdrm drmOpen*() functions\n@@ -404,16 +411,37 @@ 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-\tif (fd_ < 0) {\n+\tDIR *folder = opendir(name.c_str());\n+\tif (!folder) {\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\tstd::cerr << \"Failed to open \" << name\n+\t\t\t  << \" directory: \" << strerror(-ret) << std::endl;\n \t\treturn ret;\n \t}\n \n+\tname += \"card\";\n+\tfor (struct dirent *res; (res = readdir(folder));) {\n+\t\tif (!strncmp(res->d_name, \"card\", 4)) {\n+\t\t\tname += res->d_name + PRE_NODE_NAME_MAX;\n+\t\t\tfd_ = open(name.c_str(), O_RDWR | O_CLOEXEC);\n+\t\t\tif (fd_ >= 0) {\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tret = -errno;\n+\t\t\tstd::cerr << \"Failed to open DRM/KMS device \" << name\n+\t\t\t\t  << \": \" << strerror(-ret) << std::endl;\n+\t\t\tname.resize(DIR_NAME_MAX + PRE_NODE_NAME_MAX);\n+\t\t}\n+\t}\n+\n+\tclosedir(folder);\n+\n+\tif (fd_ < 0) {\n+\t\tstd::cerr << \"Failed to open any DRM/KMS device\" << std::endl;\n+\t\treturn -ENOENT;\n+\t}\n+\n \t/*\n \t * Enable the atomic APIs. This also automatically enables the\n \t * universal planes API.\n",
    "prefixes": [
        "libcamera-devel",
        "v4"
    ]
}