Use helper function to get socket fd and add locks. Signed-off-by: Maxim Uvarov <maxim.uva...@linaro.org> Reviewed-by: Stuart Haslam <stuart.has...@arm.com> --- platform/linux-generic/odp_packet_io.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 3b7869f..c50e76a 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -551,20 +551,27 @@ 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); + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + 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; } @@ -581,19 +588,26 @@ 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); + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + 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; } -- 1.8.5.1.163.gd7aced9 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp