diff mbox

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

Message ID 1418147090-29055-6-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit ff860ac879483b4a518c3f1e4c9ae35adee678c5
Headers show

Commit Message

Maxim Uvarov Dec. 9, 2014, 5:44 p.m. UTC
Use helper function to get socket fd and add locks.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by: Stuart Haslam <stuart.haslam@arm.com>
---
 platform/linux-generic/odp_packet_io.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

Comments

vkamensky Dec. 9, 2014, 6:11 p.m. UTC | #1
On 9 December 2014 at 09:44, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> Use helper function to get socket fd and add locks.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> Reviewed-by: Stuart Haslam <stuart.haslam@arm.com>

Reviewed-by: Victor Kamensky <victor.kamensky@linaro.org>

> ---
>  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
diff mbox

Patch

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;
 }