summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-17 17:06:25 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-28 11:29:33 +0200
commitff24be7022b39533cce219468b6fa3ce84460f94 (patch)
tree3e2e547dcbf049951864644b3be2a1c695ca512d
parent11fd9f171e88464ad1e9121a2f1271906bf31518 (diff)
libcamera: camera: Check requests before queueing them
Make sure all requests queued to a camera only contain streams which have been configured and belong to the camera. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--src/libcamera/camera.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 655996f2..9cea3fd0 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -732,6 +732,7 @@ Request *Camera::createRequest()
* \return 0 on success or a negative error code otherwise
* \retval -ENODEV The camera has been disconnected from the system
* \retval -EACCES The camera is not running so requests can't be queued
+ * \retval -EINVAL The request is invalid
*/
int Camera::queueRequest(Request *request)
{
@@ -741,6 +742,14 @@ int Camera::queueRequest(Request *request)
if (!stateIs(CameraRunning))
return -EACCES;
+ for (auto const &it : request->buffers()) {
+ Stream *stream = it.first;
+ if (activeStreams_.find(stream) == activeStreams_.end()) {
+ LOG(Camera, Error) << "Invalid request";
+ return -EINVAL;
+ }
+ }
+
int ret = request->prepare();
if (ret) {
LOG(Camera, Error) << "Failed to prepare request";
6 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * span.cpp - Span tests
 */

/*
 * Include first to ensure the header is self-contained, as there's no span.cpp
 * in libcamera.
 */
#include <libcamera/base/span.h>

#include <array>
#include <iostream>
#include <vector>

#include "test.h"

using namespace std;
using namespace libcamera;

class SpanTest : public Test
{
protected:
	int run()
	{
		int i[4]{ 1, 2, 3, 4 };
		std::array<int, 4> a{ 1, 2, 3, 4 };
		const std::array<int, 4> ca{ 1, 2, 3, 4 };
		std::vector<int> v{ 1, 2, 3, 4 };
		const std::vector<int> cv{ 1, 2, 3, 4 };

		/*
		 * Compile-test construction and usage of spans with static
		 * extent. Commented-out tests are expected not to compile, or
		 * to generate undefined behaviour.
		 */

		Span<int, 0>{};
		/* Span<int, 4>{}; */

		Span<int, 4>{ &i[0], 4 };
		Span<int, 4>{ &i[0], &i[3] };

		Span<int, 4>{ i };
		/* Span<float, 4>{ i }; */
		/* Span<int, 2>{ i }; */

		Span<int, 4>{ a };
		Span<const int, 4>{ a };
		/* Span<float, 4>{ a }; */