diff mbox series

[1/1] sandbox: missing return value checks in eth-raw-os

Message ID 20240107082713.41539-1-heinrich.schuchardt@canonical.com
State Accepted
Commit 233c31d7baecd6fdb3e287683019205af02aa221
Delegated to: Tom Rini
Headers show
Series [1/1] sandbox: missing return value checks in eth-raw-os | expand

Commit Message

Heinrich Schuchardt Jan. 7, 2024, 8:27 a.m. UTC
We should check the return value of fcntl().

Addresses-Coverity-ID: 131108 ("Unchecked return value from library")
Addresses-Coverity-ID: 131109 ("Unchecked return value from library")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/sandbox/cpu/eth-raw-os.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Tom Rini April 12, 2024, 6:51 p.m. UTC | #1
On Sun, Jan 07, 2024 at 09:27:12AM +0100, Heinrich Schuchardt wrote:

> We should check the return value of fcntl().
> 
> Addresses-Coverity-ID: 131108 ("Unchecked return value from library")
> Addresses-Coverity-ID: 131109 ("Unchecked return value from library")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..4ef2af0c36 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -105,7 +105,12 @@  static int _raw_packet_start(struct eth_sandbox_raw_priv *priv,
 
 	/* Make the socket non-blocking */
 	flags = fcntl(priv->sd, F_GETFL, 0);
-	fcntl(priv->sd, F_SETFL, flags | O_NONBLOCK);
+	ret = fcntl(priv->sd, F_SETFL, flags | O_NONBLOCK);
+	if (ret == -1) {
+		printf("Failed to make socket non-blocking: %d %s\n", errno,
+		       strerror(errno));
+		return -errno;
+	}
 
 	/* Enable promiscuous mode to receive responses meant for us */
 	mr.mr_ifindex = device->sll_ifindex;
@@ -172,7 +177,12 @@  static int _local_inet_start(struct eth_sandbox_raw_priv *priv)
 
 	/* Make the socket non-blocking */
 	flags = fcntl(priv->sd, F_GETFL, 0);
-	fcntl(priv->sd, F_SETFL, flags | O_NONBLOCK);
+	ret = fcntl(priv->sd, F_SETFL, flags | O_NONBLOCK);
+	if (ret == -1) {
+		printf("Failed to make socket non-blocking: %d %s\n", errno,
+		       strerror(errno));
+		return -errno;
+	}
 
 	/* Include the UDP/IP headers on send and receive */
 	ret = setsockopt(priv->sd, IPPROTO_IP, IP_HDRINCL, &one,