Patch Detail
Show a patch.
GET /api/1.1/patches/20383/?format=api
{ "id": 20383, "url": "https://patchwork.libcamera.org/api/1.1/patches/20383/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20383/", "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": "<20240625073600.1707-1-laurent.pinchart@ideasonboard.com>", "date": "2024-06-25T07:36:00", "name": "[v2] v4l2: v4l2_compat: Move `open*()` flag check into function", "commit_ref": "4d0834ea0adfb5139e0ab83751d3e89d72e0a931", "pull_url": null, "state": "accepted", "archived": false, "hash": "0c7d7f42371712c95782a26efdde89651374cf64", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20383/mbox/", "series": [ { "id": 4415, "url": "https://patchwork.libcamera.org/api/1.1/series/4415/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4415", "date": "2024-06-25T07:36:00", "name": "[v2] v4l2: v4l2_compat: Move `open*()` flag check into function", "version": 2, "mbox": "https://patchwork.libcamera.org/series/4415/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20383/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20383/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 7D43DBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Jun 2024 07:36:24 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43325654A9;\n\tTue, 25 Jun 2024 09:36:23 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CB70C619E8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Jun 2024 09:36:21 +0200 (CEST)", "from pendragon.ideasonboard.com (unknown [193.209.96.36])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3545BC62;\n\tTue, 25 Jun 2024 09:35:58 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gb7bSqBT\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1719300959;\n\tbh=HPQUniMK9jI1NrXMUxN27PGgRe0xUztIVU3dW1N2YRA=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=gb7bSqBTn/SRFGLGTzAcDfKK2ZhbyEE8PFU7j+nAG/vP9h0G8sUN/CVJ9i/pR/Lma\n\tH+gAQkv8dLI/2nsyGuo8I3h/piWh0vaYXGzl/yq04nWCIB1HmeZP5tw2swQElgSwrY\n\tLeCSQHQjYBJmGs7dQuU0PpJheptfwMCb2ww2CVOI=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>", "Subject": "[PATCH v2] v4l2: v4l2_compat: Move `open*()` flag check into\n\tfunction", "Date": "Tue, 25 Jun 2024 10:36:00 +0300", "Message-ID": "<20240625073600.1707-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.44.2", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Barnabás Pőcze <pobrn@protonmail.com>\n\nThis commit moves the check that determines whether the mode argument of\n`open*()` exists into a separate function.\n\nWith that, the check is fixed because previously it failed to account\nfor the fact that `O_TMPFILE` is not a power of two.\n\nFurthermore, add `assert()`s in the fortified variants that ensure that\nno mode is required by the specified flags.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/v4l2/v4l2_compat.cpp | 26 ++++++++++++++++++++++----\n 1 file changed, 22 insertions(+), 4 deletions(-)\n\n\nbase-commit: 2119bdac6a011034cc33584e3303e47db4932313\nprerequisite-patch-id: 0be99aed547971ce06228a939a006fbda1557a7c", "diff": "diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\nindex 8a44403ed51a..bd016cbd53e1 100644\n--- a/src/v4l2/v4l2_compat.cpp\n+++ b/src/v4l2/v4l2_compat.cpp\n@@ -7,6 +7,7 @@\n \n #include \"v4l2_compat_manager.h\"\n \n+#include <assert.h>\n #include <errno.h>\n #include <fcntl.h>\n #include <stdarg.h>\n@@ -28,12 +29,25 @@ using namespace libcamera;\n \tva_end(ap);\t\t\t\\\n }\n \n+namespace {\n+\n+/*\n+ * Determine if the flags require a further mode arguments that needs to be\n+ * parsed from va_args.\n+ */\n+bool needs_mode(int flags)\n+{\n+\treturn (flags & O_CREAT) || ((flags & O_TMPFILE) == O_TMPFILE);\n+}\n+\n+} /* namespace */\n+\n extern \"C\" {\n \n LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)\n {\n \tmode_t mode = 0;\n-\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n+\tif (needs_mode(oflag))\n \t\textract_va_arg(mode_t, mode, oflag);\n \n \treturn V4L2CompatManager::instance()->openat(AT_FDCWD, path,\n@@ -43,6 +57,7 @@ LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)\n /* _FORTIFY_SOURCE redirects open to __open_2 */\n LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n {\n+\tassert(!needs_mode(oflag));\n \treturn open(path, oflag);\n }\n \n@@ -50,7 +65,7 @@ LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n LIBCAMERA_PUBLIC int open64(const char *path, int oflag, ...)\n {\n \tmode_t mode = 0;\n-\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n+\tif (needs_mode(oflag))\n \t\textract_va_arg(mode_t, mode, oflag);\n \n \treturn V4L2CompatManager::instance()->openat(AT_FDCWD, path,\n@@ -59,6 +74,7 @@ LIBCAMERA_PUBLIC int open64(const char *path, int oflag, ...)\n \n LIBCAMERA_PUBLIC int __open64_2(const char *path, int oflag)\n {\n+\tassert(!needs_mode(oflag));\n \treturn open64(path, oflag);\n }\n #endif\n@@ -66,7 +82,7 @@ LIBCAMERA_PUBLIC int __open64_2(const char *path, int oflag)\n LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n {\n \tmode_t mode = 0;\n-\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n+\tif (needs_mode(oflag))\n \t\textract_va_arg(mode_t, mode, oflag);\n \n \treturn V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);\n@@ -74,6 +90,7 @@ LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n \n LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n {\n+\tassert(!needs_mode(oflag));\n \treturn openat(dirfd, path, oflag);\n }\n \n@@ -81,7 +98,7 @@ LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n LIBCAMERA_PUBLIC int openat64(int dirfd, const char *path, int oflag, ...)\n {\n \tmode_t mode = 0;\n-\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n+\tif (needs_mode(oflag))\n \t\textract_va_arg(mode_t, mode, oflag);\n \n \treturn V4L2CompatManager::instance()->openat(dirfd, path,\n@@ -90,6 +107,7 @@ LIBCAMERA_PUBLIC int openat64(int dirfd, const char *path, int oflag, ...)\n \n LIBCAMERA_PUBLIC int __openat64_2(int dirfd, const char *path, int oflag)\n {\n+\tassert(!needs_mode(oflag));\n \treturn openat64(dirfd, path, oflag);\n }\n #endif\n", "prefixes": [ "v2" ] }