diff options
2 files changed, 76 insertions, 30 deletions
diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-rpi-Use-alloca-instead-of-variable-length-arrays.patch b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-rpi-Use-alloca-instead-of-variable-length-arrays.patch index a6526d5903..c336e92548 100644 --- a/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-rpi-Use-alloca-instead-of-variable-length-arrays.patch +++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-rpi-Use-alloca-instead-of-variable-length-arrays.patch | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From 7982e55ce3a8b3c60a47258ff7d37d0dd78c303d Mon Sep 17 00:00:00 2001 | 1 | From 11cc6dbd45f0880beea64cdc514f57484b90bc39 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Tue, 20 Feb 2024 18:44:23 -0800 | 3 | Date: Tue, 20 Feb 2024 18:44:23 -0800 |
| 4 | Subject: [PATCH] rpi: Use alloca instead of variable length arrays | 4 | Subject: [PATCH] rpi: Use malloc instead of variable length arrays |
| 5 | 5 | ||
| 6 | Clang-18+ diagnoses this as error | 6 | Clang-18+ diagnoses this as error |
| 7 | 7 | ||
| @@ -10,12 +10,14 @@ Clang-18+ diagnoses this as error | |||
| 10 | 10 | ||
| 11 | Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2024-February/040529.html] | 11 | Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2024-February/040529.html] |
| 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 13 | |||
| 14 | s | ||
| 13 | --- | 15 | --- |
| 14 | src/ipa/rpi/controller/rpi/alsc.cpp | 4 ++-- | 16 | src/ipa/rpi/controller/rpi/alsc.cpp | 7 +++++-- |
| 15 | 1 file changed, 2 insertions(+), 2 deletions(-) | 17 | 1 file changed, 5 insertions(+), 2 deletions(-) |
| 16 | 18 | ||
| 17 | diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp | 19 | diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp |
| 18 | index 8a205c60..8c0ae8eb 100644 | 20 | index 8a205c60..a7d42614 100644 |
| 19 | --- a/src/ipa/rpi/controller/rpi/alsc.cpp | 21 | --- a/src/ipa/rpi/controller/rpi/alsc.cpp |
| 20 | +++ b/src/ipa/rpi/controller/rpi/alsc.cpp | 22 | +++ b/src/ipa/rpi/controller/rpi/alsc.cpp |
| 21 | @@ -496,8 +496,8 @@ void resampleCalTable(const Array2D<double> &calTableIn, | 23 | @@ -496,8 +496,8 @@ void resampleCalTable(const Array2D<double> &calTableIn, |
| @@ -24,11 +26,18 @@ index 8a205c60..8c0ae8eb 100644 | |||
| 24 | */ | 26 | */ |
| 25 | - int xLo[X], xHi[X]; | 27 | - int xLo[X], xHi[X]; |
| 26 | - double xf[X]; | 28 | - double xf[X]; |
| 27 | + int *xLo = (int*)alloca(X), *xHi = (int*)alloca(X); | 29 | + int *xLo = (int*)malloc(X), *xHi = (int*)malloc(X); |
| 28 | + double *xf = (double*)alloca(X); | 30 | + double *xf = (double*)malloc(X); |
| 29 | double scaleX = cameraMode.sensorWidth / | 31 | double scaleX = cameraMode.sensorWidth / |
| 30 | (cameraMode.width * cameraMode.scaleX); | 32 | (cameraMode.width * cameraMode.scaleX); |
| 31 | double xOff = cameraMode.cropX / (double)cameraMode.sensorWidth; | 33 | double xOff = cameraMode.cropX / (double)cameraMode.sensorWidth; |
| 32 | -- | 34 | @@ -539,6 +539,9 @@ void resampleCalTable(const Array2D<double> &calTableIn, |
| 33 | 2.43.2 | 35 | *(out++) = above * (1 - yf) + below * yf; |
| 34 | 36 | } | |
| 37 | } | ||
| 38 | + free(xf); | ||
| 39 | + free(xHi); | ||
| 40 | + free(xLo); | ||
| 41 | } | ||
| 42 | |||
| 43 | /* Calculate chrominance statistics (R/G and B/G) for each region. */ | ||
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 index 95f321782e..473820653e 100644 --- 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 | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | From c80d273a57547aec9353d888aa316bf6560cf1ba Mon Sep 17 00:00:00 2001 | 1 | From 6e4736180fcaffdb06acf52fd3eb50ba5baa3d2a Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 31 Jan 2024 21:04:28 -0800 | 3 | Date: Wed, 31 Jan 2024 21:04:28 -0800 |
| 4 | Subject: [PATCH 2/2] options: Replace use of VLAs in C++ | 4 | Subject: [PATCH] options: Replace use of VLAs in C++ |
| 5 | 5 | ||
| 6 | Clang++ 18 is fussy about this with new warning checks. | 6 | Clang++ 18 is fussy about this with new warning checks. |
| 7 | 7 | ||
| @@ -14,12 +14,12 @@ Therefore replace using VLAs with alloca and malloc/free | |||
| 14 | Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2024-February/040381.html] | 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> | 15 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 16 | --- | 16 | --- |
| 17 | src/apps/common/options.cpp | 4 ++-- | 17 | src/apps/common/options.cpp | 12 ++++++++++-- |
| 18 | src/libcamera/ipc_unixsocket.cpp | 12 ++++++++---- | 18 | src/libcamera/ipc_unixsocket.cpp | 13 +++++++++---- |
| 19 | 2 files changed, 10 insertions(+), 6 deletions(-) | 19 | 2 files changed, 19 insertions(+), 6 deletions(-) |
| 20 | 20 | ||
| 21 | diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp | 21 | diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp |
| 22 | index 4f7e8691..b020f603 100644 | 22 | index 4f7e8691..3656f3c1 100644 |
| 23 | --- a/src/apps/common/options.cpp | 23 | --- a/src/apps/common/options.cpp |
| 24 | +++ b/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) | 25 | @@ -879,8 +879,8 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) |
| @@ -28,16 +28,56 @@ index 4f7e8691..b020f603 100644 | |||
| 28 | */ | 28 | */ |
| 29 | - char shortOptions[optionsMap_.size() * 3 + 2]; | 29 | - char shortOptions[optionsMap_.size() * 3 + 2]; |
| 30 | - struct option longOptions[optionsMap_.size() + 1]; | 30 | - struct option longOptions[optionsMap_.size() + 1]; |
| 31 | + char *shortOptions = (char*)alloca(optionsMap_.size() * 3 + 2); | 31 | + char *shortOptions = (char*)malloc(optionsMap_.size() * 3 + 2); |
| 32 | + struct option *longOptions = (struct option*)alloca(optionsMap_.size() + 1); | 32 | + struct option *longOptions = (struct option*)malloc(sizeof(struct option) * (optionsMap_.size() + 1)); |
| 33 | unsigned int ids = 0; | 33 | unsigned int ids = 0; |
| 34 | unsigned int idl = 0; | 34 | unsigned int idl = 0; |
| 35 | 35 | ||
| 36 | @@ -935,12 +935,16 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) | ||
| 37 | std::cerr << argv[optind - 1] << std::endl; | ||
| 38 | |||
| 39 | usage(); | ||
| 40 | + free(shortOptions); | ||
| 41 | + free(longOptions); | ||
| 42 | return options; | ||
| 43 | } | ||
| 44 | |||
| 45 | const Option &option = *optionsMap_[c]; | ||
| 46 | if (!parseValue(option, optarg, &options)) { | ||
| 47 | usage(); | ||
| 48 | + free(shortOptions); | ||
| 49 | + free(longOptions); | ||
| 50 | return options; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | @@ -949,10 +953,14 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) | ||
| 54 | std::cerr << "Invalid non-option argument '" << argv[optind] | ||
| 55 | << "'" << std::endl; | ||
| 56 | usage(); | ||
| 57 | + free(shortOptions); | ||
| 58 | + free(longOptions); | ||
| 59 | return options; | ||
| 60 | } | ||
| 61 | |||
| 62 | options.valid_ = true; | ||
| 63 | + free(shortOptions); | ||
| 64 | + free(longOptions); | ||
| 65 | return options; | ||
| 66 | } | ||
| 67 | |||
| 36 | diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp | 68 | diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp |
| 37 | index 1980d374..3a7f8ee6 100644 | 69 | index 1980d374..3bd861cb 100644 |
| 38 | --- a/src/libcamera/ipc_unixsocket.cpp | 70 | --- a/src/libcamera/ipc_unixsocket.cpp |
| 39 | +++ b/src/libcamera/ipc_unixsocket.cpp | 71 | +++ b/src/libcamera/ipc_unixsocket.cpp |
| 40 | @@ -247,8 +247,8 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, | 72 | @@ -8,6 +8,7 @@ |
| 73 | #include "libcamera/internal/ipc_unixsocket.h" | ||
| 74 | |||
| 75 | #include <array> | ||
| 76 | +#include <cstdint> | ||
| 77 | #include <poll.h> | ||
| 78 | #include <string.h> | ||
| 79 | #include <sys/socket.h> | ||
| 80 | @@ -247,8 +248,8 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, | ||
| 41 | iov[0].iov_base = const_cast<void *>(buffer); | 81 | iov[0].iov_base = const_cast<void *>(buffer); |
| 42 | iov[0].iov_len = length; | 82 | iov[0].iov_len = length; |
| 43 | 83 | ||
| @@ -48,19 +88,19 @@ index 1980d374..3a7f8ee6 100644 | |||
| 48 | 88 | ||
| 49 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; | 89 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; |
| 50 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); | 90 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); |
| 51 | @@ -270,9 +270,11 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, | 91 | @@ -270,9 +271,11 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, |
| 52 | int ret = -errno; | 92 | int ret = -errno; |
| 53 | LOG(IPCUnixSocket, Error) | 93 | LOG(IPCUnixSocket, Error) |
| 54 | << "Failed to sendmsg: " << strerror(-ret); | 94 | << "Failed to sendmsg: " << strerror(-ret); |
| 55 | + free(buf); | 95 | + free(buf); |
| 56 | return ret; | 96 | return ret; |
| 57 | } | 97 | } |
| 58 | 98 | ||
| 59 | + free(buf); | 99 | + free(buf); |
| 60 | return 0; | 100 | return 0; |
| 61 | } | 101 | } |
| 62 | 102 | ||
| 63 | @@ -283,8 +285,8 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, | 103 | @@ -283,8 +286,8 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, |
| 64 | iov[0].iov_base = buffer; | 104 | iov[0].iov_base = buffer; |
| 65 | iov[0].iov_len = length; | 105 | iov[0].iov_len = length; |
| 66 | 106 | ||
| @@ -71,21 +111,18 @@ index 1980d374..3a7f8ee6 100644 | |||
| 71 | 111 | ||
| 72 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; | 112 | struct cmsghdr *cmsg = (struct cmsghdr *)buf; |
| 73 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); | 113 | cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); |
| 74 | @@ -305,12 +307,14 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, | 114 | @@ -305,12 +308,14 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, |
| 75 | if (ret != -EAGAIN) | 115 | if (ret != -EAGAIN) |
| 76 | LOG(IPCUnixSocket, Error) | 116 | LOG(IPCUnixSocket, Error) |
| 77 | << "Failed to recvmsg: " << strerror(-ret); | 117 | << "Failed to recvmsg: " << strerror(-ret); |
| 78 | + free(buf); | 118 | + free(buf); |
| 79 | return ret; | 119 | return ret; |
| 80 | } | 120 | } |
| 81 | 121 | ||
| 82 | if (fds) | 122 | if (fds) |
| 83 | memcpy(fds, CMSG_DATA(cmsg), num * sizeof(uint32_t)); | 123 | memcpy(fds, CMSG_DATA(cmsg), num * sizeof(uint32_t)); |
| 84 | 124 | ||
| 85 | + free(buf); | 125 | + free(buf); |
| 86 | return 0; | 126 | return 0; |
| 87 | } | 127 | } |
| 88 | 128 | ||
| 89 | -- | ||
| 90 | 2.43.0 | ||
| 91 | |||
