diff mbox

[PATCHv4,09/11] linux-generic: correct socket get for mtu functions

Message ID 1417450537-7640-10-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 1, 2014, 4:15 p.m. UTC
Socket can be 0 and it's accounted in previews patch. Correct that function too.

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

Comments

Ciprian Barbu Dec. 5, 2014, 11:10 a.m. UTC | #1
On Mon, Dec 1, 2014 at 6:15 PM, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> Socket can be 0 and it's accounted in previews patch. Correct that function too.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  platform/linux-generic/odp_packet_io.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index 8dc4fb1..6c8307e 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -561,12 +561,13 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu)
>                 return -1;
>         }
>
> -       if (entry->s.pkt_sock_mmap.sockfd)
> +       if (entry->s.pkt_sock_mmap.sockfd > -1)
>                 sockfd = entry->s.pkt_sock_mmap.sockfd;
>         else
>                 sockfd = entry->s.pkt_sock.sockfd;
>
> -       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
> +       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);
> @@ -591,12 +592,13 @@ int odp_pktio_mtu(odp_pktio_t id)
>                 return -1;
>         }
>
> -       if (entry->s.pkt_sock_mmap.sockfd)
> +       if (entry->s.pkt_sock_mmap.sockfd > -1)

nit: yhy don't you just say entry->s.plt_sock_mmap.sockfd >=0 ? It's
the common way of describing a positive number.

>                 sockfd = entry->s.pkt_sock_mmap.sockfd;
>         else
>                 sockfd = entry->s.pkt_sock.sockfd;
>
> -       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
> +       strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
> +       ifr.ifr_name[IFNAMSIZ - 1] = 0;
>
>         ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
>         if (ret < 0) {
> --
> 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 8dc4fb1..6c8307e 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -561,12 +561,13 @@  int odp_pktio_set_mtu(odp_pktio_t id, int mtu)
 		return -1;
 	}
 
-	if (entry->s.pkt_sock_mmap.sockfd)
+	if (entry->s.pkt_sock_mmap.sockfd > -1)
 		sockfd = entry->s.pkt_sock_mmap.sockfd;
 	else
 		sockfd = entry->s.pkt_sock.sockfd;
 
-	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+	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);
@@ -591,12 +592,13 @@  int odp_pktio_mtu(odp_pktio_t id)
 		return -1;
 	}
 
-	if (entry->s.pkt_sock_mmap.sockfd)
+	if (entry->s.pkt_sock_mmap.sockfd > -1)
 		sockfd = entry->s.pkt_sock_mmap.sockfd;
 	else
 		sockfd = entry->s.pkt_sock.sockfd;
 
-	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ);
+	strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
+	ifr.ifr_name[IFNAMSIZ - 1] = 0;
 
 	ret = ioctl(sockfd, SIOCGIFMTU, &ifr);
 	if (ret < 0) {