From patchwork Tue Dec 9 17:44:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 42068 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 76D5C244AC for ; Tue, 9 Dec 2014 17:45:39 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf1133584wiw.0 for ; Tue, 09 Dec 2014 09:45:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=pyw6j+pqJEc1NzkwyxpdxylQNIVz6AEHpW8c/cRiZu0=; b=bGuZithFufcs35tRFhzzQAukkMu5+VC2TX55I+7VbLNHID/v+KfsF/xDjnncgnxpEv 9zZx0yVQz2Sz1rzpkNoH0lj4mxZ2kCmJ+Q01SH3T/CEqt5RfTUWFQ9AbI3YoAuk30Akp jPRCkd4MqxFhaKCubYXMUPalfcBnUJG7t2iisbjE3KDbEvsBYwEd9ZBkhbouNlY12Qbi S/J4BUBa25TYWDX2FkdXwY0B0uywhPa3+GhQvJJgKiwja3gfPA4VhpWw3/w3U6nl2iqh M7s6s3GCkCsi+lV8sYlKam75CJcy2/FFOnf6ZRCCbyHJRLGW6/QPwU90ulGwhcx811uj RHkA== X-Gm-Message-State: ALoCoQmCoV9mSHttR+daLRHDk/GaR1r5V8mbWOjE95xcOFK2GPT9i9eVQvdjENx7Vmd5xvGGhROc X-Received: by 10.194.71.48 with SMTP id r16mr17384wju.7.1418147138801; Tue, 09 Dec 2014 09:45:38 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.135 with SMTP id s7ls74309las.33.gmail; Tue, 09 Dec 2014 09:45:38 -0800 (PST) X-Received: by 10.112.180.198 with SMTP id dq6mr22589920lbc.56.1418147138544; Tue, 09 Dec 2014 09:45:38 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id to1si1958377lbb.133.2014.12.09.09.45.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 09:45:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id hs14so937048lab.8 for ; Tue, 09 Dec 2014 09:45:38 -0800 (PST) X-Received: by 10.152.3.67 with SMTP id a3mr23047595laa.56.1418147138124; Tue, 09 Dec 2014 09:45:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp786943lbc; Tue, 9 Dec 2014 09:45:37 -0800 (PST) X-Received: by 10.224.22.6 with SMTP id l6mr7819834qab.31.1418147136539; Tue, 09 Dec 2014 09:45:36 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id w32si1910025qge.62.2014.12.09.09.45.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Dec 2014 09:45:36 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XyOqr-0005VF-Nb; Tue, 09 Dec 2014 17:45:33 +0000 Received: from mail-lb0-f173.google.com ([209.85.217.173]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XyOqT-0005Qe-Fe for lng-odp@lists.linaro.org; Tue, 09 Dec 2014 17:45:09 +0000 Received: by mail-lb0-f173.google.com with SMTP id z12so921186lbi.32 for ; Tue, 09 Dec 2014 09:45:03 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr22884672lbc.3.1418147103843; Tue, 09 Dec 2014 09:45:03 -0800 (PST) Received: from localhost.localdomain (ppp91-76-163-205.pppoe.mtu-net.ru. [91.76.163.205]) by mx.google.com with ESMTPSA id m9sm10385laa.28.2014.12.09.09.45.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Dec 2014 09:45:03 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 9 Dec 2014 20:44:49 +0300 Message-Id: <1418147090-29055-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1418147090-29055-1-git-send-email-maxim.uvarov@linaro.org> References: <1418147090-29055-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv8 5/6] linux-generic: correct socket get for mtu functions X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Use helper function to get socket fd and add locks. Signed-off-by: Maxim Uvarov Reviewed-by: Stuart Haslam Reviewed-by: Victor Kamensky --- 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; }