diff options
3 files changed, 152 insertions, 0 deletions
diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-media_device-Add-bool-return-type-to-unlock.patch b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-media_device-Add-bool-return-type-to-unlock.patch new file mode 100644 index 0000000000..12f034effd --- /dev/null +++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-media_device-Add-bool-return-type-to-unlock.patch | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | From 6914c4fd3d53c0c6ea304123bf57429bb64ec16f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 31 Jan 2024 21:01:27 -0800 | ||
| 4 | Subject: [PATCH 1/2] media_device: Add bool return type to unlock() | ||
| 5 | |||
| 6 | unlock uses lockf which is marked with __attribute__ | ||
| 7 | ((warn_unused_result)) and compilers warn about it and some treat | ||
| 8 | -Wunused-result as error with -Werror turned on, It would be good to | ||
| 9 | check if lockf failed or succeeded, however, that piece is not changed | ||
| 10 | with this, this fixes build with clang++ 18 | ||
| 11 | |||
| 12 | ../git/src/libcamera/media_device.cpp:167:2: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result] | ||
| 13 | 167 | lockf(fd_.get(), F_ULOCK, 0); | ||
| 14 | | ^~~~~ ~~~~~~~~~~~~~~~~~~~~~ | ||
| 15 | 1 error generated. | ||
| 16 | |||
| 17 | Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2024-February/040380.html] | ||
| 18 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 19 | --- | ||
| 20 | include/libcamera/internal/media_device.h | 2 +- | ||
| 21 | src/libcamera/media_device.cpp | 6 +++--- | ||
| 22 | 2 files changed, 4 insertions(+), 4 deletions(-) | ||
| 23 | |||
| 24 | diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h | ||
| 25 | index eb8cfde4..b09dfd16 100644 | ||
| 26 | --- a/include/libcamera/internal/media_device.h | ||
| 27 | +++ b/include/libcamera/internal/media_device.h | ||
| 28 | @@ -33,7 +33,7 @@ public: | ||
| 29 | bool busy() const { return acquired_; } | ||
| 30 | |||
| 31 | bool lock(); | ||
| 32 | - void unlock(); | ||
| 33 | + bool unlock(); | ||
| 34 | |||
| 35 | int populate(); | ||
| 36 | bool isValid() const { return valid_; } | ||
| 37 | diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp | ||
| 38 | index 2949816b..eaa2fdb0 100644 | ||
| 39 | --- a/src/libcamera/media_device.cpp | ||
| 40 | +++ b/src/libcamera/media_device.cpp | ||
| 41 | @@ -159,12 +159,12 @@ bool MediaDevice::lock() | ||
| 42 | * | ||
| 43 | * \sa lock() | ||
| 44 | */ | ||
| 45 | -void MediaDevice::unlock() | ||
| 46 | +bool MediaDevice::unlock() | ||
| 47 | { | ||
| 48 | if (!fd_.isValid()) | ||
| 49 | - return; | ||
| 50 | + return false; | ||
| 51 | |||
| 52 | - lockf(fd_.get(), F_ULOCK, 0); | ||
| 53 | + return lockf(fd_.get(), F_ULOCK, 0) == 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | -- | ||
| 58 | 2.43.0 | ||
| 59 | |||
diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera/0002-options-Replace-use-of-VLAs-in-C.patch b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0002-options-Replace-use-of-VLAs-in-C.patch new file mode 100644 index 0000000000..95f321782e --- /dev/null +++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0002-options-Replace-use-of-VLAs-in-C.patch | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | From c80d273a57547aec9353d888aa316bf6560cf1ba Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Wed, 31 Jan 2024 21:04:28 -0800 | ||
| 4 | Subject: [PATCH 2/2] options: Replace use of VLAs in C++ | ||
| 5 | |||
| 6 | Clang++ 18 is fussy about this with new warning checks. | ||
| 7 | |||
| 8 | ../git/src/apps/common/options.cpp:882:20: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] | ||
| 9 | 882 | char shortOptions[optionsMap_.size() * 3 + 2]; | ||
| 10 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 11 | |||
| 12 | Therefore replace using VLAs with alloca and malloc/free | ||
| 13 | |||
| 14 | Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2024-February/040381.html] | ||
| 15 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 16 | --- | ||
| 17 | src/apps/common/options.cpp | 4 ++-- | ||
| 18 | src/libcamera/ipc_unixsocket.cpp | 12 ++++++++---- | ||
| 19 | 2 files changed, 10 insertions(+), 6 deletions(-) | ||
| 20 | |||
| 21 | diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp | ||
| 22 | index 4f7e8691..b020f603 100644 | ||
| 23 | --- a/src/apps/common/options.cpp | ||
| 24 | +++ b/src/apps/common/options.cpp | ||
| 25 | @@ -879,8 +879,8 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) | ||
| 26 | * Allocate short and long options arrays large enough to contain all | ||
| 27 | * options. | ||
| 28 | */ | ||
| 29 | - char shortOptions[optionsMap_.size() * 3 + 2]; | ||
| 30 | - struct option longOptions[optionsMap_.size() + 1]; | ||
| 31 | + char *shortOptions = (char*)alloca(optionsMap_.size() * 3 + 2); | ||
| 32 | + struct option *longOptions = (struct option*)alloca(optionsMap_.size() + 1); | ||
| 33 | unsigned int ids = 0; | ||
| 34 | unsigned int idl = 0; | ||
| 35 | |||
| 36 | diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp | ||
| 37 | index 1980d374..3a7f8ee6 100644 | ||
| 38 | --- a/src/libcamera/ipc_unixsocket.cpp | ||
| 39 | +++ b/src/libcamera/ipc_unixsocket.cpp | ||
| 40 | @@ -247,8 +247,8 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, | ||
| 41 | iov[0].iov_base = const_cast<void *>(buffer); | ||
| 42 | iov[0].iov_len = length; | ||
| 43 | |||
| 44 | - char buf[CMSG_SPACE(num * sizeof(uint32_t))]; | ||
| 45 | - memset(buf, 0, sizeof(buf)); | ||
| 46 | + char *buf = (char*)malloc(CMSG_SPACE(num * sizeof(uint32_t))); | ||
| 47 | + memset((void*)buf, 0, sizeof(buf)); | ||
| 48 | |||
| 49 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; | ||
| 50 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); | ||
| 51 | @@ -270,9 +270,11 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, | ||
| 52 | int ret = -errno; | ||
| 53 | LOG(IPCUnixSocket, Error) | ||
| 54 | << "Failed to sendmsg: " << strerror(-ret); | ||
| 55 | + free(buf); | ||
| 56 | return ret; | ||
| 57 | } | ||
| 58 | |||
| 59 | + free(buf); | ||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | @@ -283,8 +285,8 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, | ||
| 64 | iov[0].iov_base = buffer; | ||
| 65 | iov[0].iov_len = length; | ||
| 66 | |||
| 67 | - char buf[CMSG_SPACE(num * sizeof(uint32_t))]; | ||
| 68 | - memset(buf, 0, sizeof(buf)); | ||
| 69 | + char *buf = (char*)malloc(CMSG_SPACE(num * sizeof(uint32_t))); | ||
| 70 | + memset((void*)buf, 0, sizeof(buf)); | ||
| 71 | |||
| 72 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; | ||
| 73 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); | ||
| 74 | @@ -305,12 +307,14 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, | ||
| 75 | if (ret != -EAGAIN) | ||
| 76 | LOG(IPCUnixSocket, Error) | ||
| 77 | << "Failed to recvmsg: " << strerror(-ret); | ||
| 78 | + free(buf); | ||
| 79 | return ret; | ||
| 80 | } | ||
| 81 | |||
| 82 | if (fds) | ||
| 83 | memcpy(fds, CMSG_DATA(cmsg), num * sizeof(uint32_t)); | ||
| 84 | |||
| 85 | + free(buf); | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | -- | ||
| 90 | 2.43.0 | ||
| 91 | |||
diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.2.0.bb b/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.2.0.bb index 3fd17f0a85..5b2e863369 100644 --- a/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.2.0.bb +++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.2.0.bb | |||
| @@ -10,6 +10,8 @@ LIC_FILES_CHKSUM = "\ | |||
| 10 | 10 | ||
| 11 | SRC_URI = " \ | 11 | SRC_URI = " \ |
| 12 | git://git.libcamera.org/libcamera/libcamera.git;protocol=https;branch=master \ | 12 | git://git.libcamera.org/libcamera/libcamera.git;protocol=https;branch=master \ |
| 13 | file://0001-media_device-Add-bool-return-type-to-unlock.patch \ | ||
| 14 | file://0002-options-Replace-use-of-VLAs-in-C.patch \ | ||
| 13 | " | 15 | " |
| 14 | 16 | ||
| 15 | SRCREV = "89227a428a82e724548399d35c98ea89566f9045" | 17 | SRCREV = "89227a428a82e724548399d35c98ea89566f9045" |
