diff mbox

[PATCHv7,5/6] linux-generic: correct socket get for mtu functions

Message ID 1418050713-29694-7-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 8, 2014, 2:58 p.m. UTC
Use helper function to get socket fd and add locks.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_packet_io.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 8a86421..4399ef9 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -546,20 +546,21 @@  int odp_pktio_set_mtu(odp_pktio_t id, int mtu)
 		return -1;
 	}
 
-	if (entry->s.pkt_sock_mmap.sockfd)
-		sockfd = entry->s.pkt_sock_mmap.sockfd;
-	else
-		sockfd = entry->s.pkt_sock.sockfd;
+	lock_entry(entry);
 
-	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+	sockfd = sockfd_from_pktio_entry(entry);
+	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
+	ifr.ifr_name[IFNAMSIZ - 1] = 0;
 	ifr.ifr_mtu = mtu;
 
 	ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr);
 	if (ret < 0) {
 		ODP_DBG("ioctl SIOCSIFMTU error\n");
+		unlock_entry(entry);
 		return -1;
 	}
 
+	unlock_entry(entry);
 	return 0;
 }
 
@@ -576,19 +577,20 @@  int odp_pktio_mtu(odp_pktio_t id)
 		return -1;
 	}
 
-	if (entry->s.pkt_sock_mmap.sockfd)
-		sockfd = entry->s.pkt_sock_mmap.sockfd;
-	else
-		sockfd = entry->s.pkt_sock.sockfd;
+	lock_entry(entry);
 
-	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+	sockfd = sockfd_from_pktio_entry(entry);
+	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
+	ifr.ifr_name[IFNAMSIZ - 1] = 0;
 
 	ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
 	if (ret < 0) {
 		ODP_DBG("ioctl SIOCGIFMTU error\n");
+		unlock_entry(entry);
 		return -1;
 	}
 
+	unlock_entry(entry);
 	return ifr.ifr_mtu;
 }