[libcamera-devel,v7,09/10] libcamera: IPCPipeUnixSocket: Check that insertion succeeds
diff mbox series

Message ID 20210211071805.34963-10-paul.elder@ideasonboard.com
State Changes Requested
Headers show
Series
  • IPA isolation: Part 1: Core components
Related show

Commit Message

Paul Elder Feb. 11, 2021, 7:18 a.m. UTC
From: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Make sure the insertion succeeds. This was found by compile tests
with gcc7 which points out 'success' is not used.

  ../../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@ragnatech.se>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/libcamera/ipc_pipe_unixsocket.cpp | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Laurent Pinchart Feb. 12, 2021, 1:59 a.m. UTC | #1
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@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@ragnatech.se>
> Reviewed-by: Paul Elder <paul.elder@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);

Patch
diff mbox series

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;
+	}
+
 	ret = socket_->send(message);
 	if (ret) {
 		callData_.erase(iter);