Patch Detail
Show a patch.
GET /api/patches/20353/?format=api
{ "id": 20353, "url": "https://patchwork.libcamera.org/api/patches/20353/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20353/", "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": "<20240618010653.2346969-1-pobrn@protonmail.com>", "date": "2024-06-18T01:06:55", "name": "[v1] v4l2: v4l2_compat: Move `open*()` flag check into function", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "39a77f74439f4315f87ff0bef9edb49a8d5c17b3", "submitter": { "id": 133, "url": "https://patchwork.libcamera.org/api/people/133/?format=api", "name": "Pőcze Barnabás", "email": "pobrn@protonmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20353/mbox/", "series": [ { "id": 4406, "url": "https://patchwork.libcamera.org/api/series/4406/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4406", "date": "2024-06-18T01:06:55", "name": "[v1] v4l2: v4l2_compat: Move `open*()` flag check into function", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4406/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20353/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20353/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 815ECBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 18 Jun 2024 01:07:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1D292654A5;\n\tTue, 18 Jun 2024 03:07:02 +0200 (CEST)", "from mail-40134.protonmail.ch (mail-40134.protonmail.ch\n\t[185.70.40.134])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E78C5619F6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 18 Jun 2024 03:07:00 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"aK002GfU\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1718672820; x=1718932020;\n\tbh=XcquBwmotK+rCmriO0e7Rc0o7fyhxBlQ76xRGLmTduY=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;\n\tb=aK002GfUHxHMcwVRSr3Ep+5HffQ8RI1fHxjyvVR5JRpCTvgFuxwrpU8aCrpN5zuiR\n\tvJKP3v6J/1FEJs2iKV6zcYpsj8M53j+TFiBjp+pc8yGXZDu8y3zZz3bq5Aryjswt+3\n\tGhmkcWp9hjvNAqzuXh9lMR8U7bVfe4LVJfUVKb6TZZLS05mgK49I5kf0xs0afreA/I\n\t7U5l9IGxjvn9NntQLKlz/bkfPFupR46412l4gAqxGNWuCGc6ujY1kh6k5xHDq7xQIo\n\tubam9QXhyxSdqw/c0TcGeyxkiCDBLp3hxYfqLrrvNirwdrc+DfUthyiVGLLtd99klj\n\tmZJkeWU3bssqA==", "Date": "Tue, 18 Jun 2024 01:06:55 +0000", "To": "libcamera-devel@lists.libcamera.org", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>", "Subject": "[PATCH v1] v4l2: v4l2_compat: Move `open*()` flag check into\n\tfunction", "Message-ID": "<20240618010653.2346969-1-pobrn@protonmail.com>", "Feedback-ID": "20568564:user:proton", "X-Pm-Message-ID": "37fff4d260ace952993c6d7353e5d72553bc313c", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=utf-8", "Content-Transfer-Encoding": "quoted-printable", "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": "This commit moves the check that determines whether the\nmode argument of `open*()` exists into a separate function.\n\nWith that, the check is fixed because previously it failed to\naccount for the fact that `O_TMPFILE` is not a power of two.\n\nFurthermore, add `asserts()` in the fortified variants that\nensure that no mode is required by the specified flags.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n src/v4l2/v4l2_compat.cpp | 18 ++++++++++++++----\n 1 file changed, 14 insertions(+), 4 deletions(-)", "diff": "diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\nindex 8a44403e..5c6f925e 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,17 @@ using namespace libcamera;\n \tva_end(ap);\t\t\t\\\n }\n \n+static inline bool needs_mode(int flags)\n+{\n+\treturn (flags & O_CREAT) || ((flags & O_TMPFILE) == O_TMPFILE);\n+}\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 +49,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 +57,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 +66,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 +74,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 +82,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 +90,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 +99,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": [ "v1" ] }