diff mbox

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

Message ID 1417619157-13690-6-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 3, 2014, 3:05 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

vkamensky Dec. 3, 2014, 11:12 p.m. UTC | #1
On 3 December 2014 at 07:05, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> Socket can be 0 and it's accounted in previews patch. Correct that function too.

This patch does more than above.

It also makes some solidifying changes in odp_pktio_set_mtu and
odp_pktio_mtu functions. BTW both these function have the same
issues that I raised in another two patches: failed to lock entry
and duplciate code that setup sockfd and and ifr structure.

Maybe you need to split this patch in two, and or fold sockfd
check into the first patch of the series.

Thanks,
Victor

>
> 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 900b47c..1a7405e 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -569,12 +569,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);
> @@ -599,12 +600,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) {
> --
> 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 900b47c..1a7405e 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -569,12 +569,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);
@@ -599,12 +600,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) {