From patchwork Mon Dec 21 10:56:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 58799 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp2521737lbb; Mon, 21 Dec 2015 03:04:48 -0800 (PST) X-Received: by 10.140.97.2 with SMTP id l2mr23617399qge.30.1450695887892; Mon, 21 Dec 2015 03:04:47 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l74si6147618qgl.121.2015.12.21.03.04.47; Mon, 21 Dec 2015 03:04:47 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 58A2D61733; Mon, 21 Dec 2015 11:04:47 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=KRWopAQp; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A22FD61747; Mon, 21 Dec 2015 10:57:53 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D9BF46174D; Mon, 21 Dec 2015 10:57:38 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id E75B26173B for ; Mon, 21 Dec 2015 10:56:25 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id oh2so12975547lbb.3 for ; Mon, 21 Dec 2015 02:56:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FLEi4BQ8u8fHazauBZ4kVg7kAnxBxD8eu1GbUBhyDyk=; b=KRWopAQp7sXEDkuRn41LW9bU7wqOzpxoI2nTomlyC6WwAvO0DZkVbbbSviTrdkq7p5 3ZXrAPVcxdqlh/h1iRqhO5DUOv3TGqo2NYteDQYeksdtLBpe7V88PYIbK+AfnqYeRPFL QfG1gJNDG+i0bBfYa0FyyaG7bGRRkNiAcUJ6w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FLEi4BQ8u8fHazauBZ4kVg7kAnxBxD8eu1GbUBhyDyk=; b=d8eQpcehsZdbFBFONY0i8kQR9VyQUZFon7yBH2tCo++5W6MjfJa+tsoY2ZsAsILb54 3q5zlusT9umCA9HspOoRrcMDPEJlahdjbKVwzeaM4y/Eedcyzu8W+1UMCTKWGIonRaIO 1frDn68zaRn2Xd2wixqkwP6p/lP7G58QGJcEkvmq1SqeyA3kjofgqmuccTFQo5CErNPb /YWmFIOnTEO1ZikPPsHjQypa5/E9ENgNwSWifJvewhyUL+fqxwpLODpwv23Q6ZGpvYlO GQ9KyXix9KB/FNsbi1GuPzmxZPKlKK9Y+4yJcC7Ue7CtP21Bqgyr7D/Ye3fmkkfr0bZI kYZQ== X-Gm-Message-State: ALoCoQnlWXimDTn8w5kFi3eerwpxSsuH6eVN8omZgXWxA1LWTxxi6xDxunzpbuGsZfLx27baSvD0CTmW2hJKel1zwUnyq7RVIQ== X-Received: by 10.112.198.131 with SMTP id jc3mr1115040lbc.118.1450695384787; Mon, 21 Dec 2015 02:56:24 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id p69sm4856694lfe.42.2015.12.21.02.56.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 02:56:24 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 21 Dec 2015 13:56:09 +0300 Message-Id: <1450695371-11536-8-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450695371-11536-1-git-send-email-maxim.uvarov@linaro.org> References: <1450695371-11536-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv19 7/9] linux-generic: return error for unsupported pktio calls X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" For some pktios like loop and ipc functions like mtu, promisc, and mac addr are not applicable. Instead of crash on deference null pointer just return error if functions are not defined. Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_packet_io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 1e9d08c..c8b6502 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -725,7 +725,7 @@ int pktin_poll(pktio_entry_t *entry) int odp_pktio_mtu(odp_pktio_t id) { pktio_entry_t *entry; - int ret; + int ret = -1; entry = get_pktio_entry(id); if (entry == NULL) { @@ -740,7 +740,9 @@ int odp_pktio_mtu(odp_pktio_t id) ODP_DBG("already freed pktio\n"); return -1; } - ret = entry->s.ops->mtu_get(entry); + + if (entry->s.ops->mtu_get) + ret = entry->s.ops->mtu_get(entry); unlock_entry(entry); return ret; @@ -749,7 +751,7 @@ int odp_pktio_mtu(odp_pktio_t id) int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) { pktio_entry_t *entry; - int ret; + int ret = -1; entry = get_pktio_entry(id); if (entry == NULL) { @@ -769,7 +771,8 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) return -1; } - ret = entry->s.ops->promisc_mode_set(entry, enable); + if (entry->s.ops->promisc_mode_set) + ret = entry->s.ops->promisc_mode_set(entry, enable); unlock_entry(entry); return ret; @@ -778,7 +781,7 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) int odp_pktio_promisc_mode(odp_pktio_t id) { pktio_entry_t *entry; - int ret; + int ret = -1; entry = get_pktio_entry(id); if (entry == NULL) { @@ -794,13 +797,13 @@ int odp_pktio_promisc_mode(odp_pktio_t id) return -1; } - ret = entry->s.ops->promisc_mode_get(entry); + if (entry->s.ops->promisc_mode_get) + ret = entry->s.ops->promisc_mode_get(entry); unlock_entry(entry); return ret; } - int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size) { pktio_entry_t *entry; @@ -825,7 +828,12 @@ int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size) return -1; } - ret = entry->s.ops->mac_get(entry, mac_addr); + if (entry->s.ops->mac_get) { + ret = entry->s.ops->mac_get(entry, mac_addr); + } else { + ODP_DBG("pktio does not support mac addr get\n"); + ret = -1; + } unlock_entry(entry); return ret;