[libcamera-devel] [PATCH v7 09/10] libcamera: IPCPipeUnixSocket: Check that insertion succeeds

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Feb 12 02:59:28 CET 2021


Hi Paul,

Thank you for the patch.

On Thu, Feb 11, 2021 at 04:18:04PM +0900, Paul Elder wrote:
> From: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> 
> Make sure the insertion succeeds. This was found by compile tests
> with gcc7 which points out 'success' is not used.

You could squash this with the patch that introduces the problem to
avoid breaking bisection.

> 
>   ../../src/libcamera/ipc_pipe_unixsocket.cpp:119:27: error: unused variable ‘success’ [-Werror=unused-variable]
>     const auto [iter, success] = callData_.insert({ cookie, { response, false } });
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
>  src/libcamera/ipc_pipe_unixsocket.cpp | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/libcamera/ipc_pipe_unixsocket.cpp b/src/libcamera/ipc_pipe_unixsocket.cpp
> index 2bdce29e..cdb7eae0 100644
> --- a/src/libcamera/ipc_pipe_unixsocket.cpp
> +++ b/src/libcamera/ipc_pipe_unixsocket.cpp
> @@ -118,6 +118,11 @@ int IPCPipeUnixSocket::call(const IPCUnixSocket::Payload &message,
>  
>  	const auto [iter, success] = callData_.insert({ cookie, { response, false } });
>  
> +	if (!success) {
> +		LOG(IPCPipe, Error) << "Failed to insert call data";
> +		return -EINVAL;
> +	}

This will only happen if the cookie is already present in the
dictionary, which I don't think can happen. As the goal is to silence a
warning, you could instead write

  	const auto result = callData_.insert({ cookie, { response, false } });
  	const auto &iter = result.first;

> +
>  	ret = socket_->send(message);
>  	if (ret) {
>  		callData_.erase(iter);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list