From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3A3AAA0A02;
	Wed,  7 Apr 2021 13:28:26 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 8630D4069F;
	Wed,  7 Apr 2021 13:28:25 +0200 (CEST)
Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191])
 by mails.dpdk.org (Postfix) with ESMTP id CC87E4013F
 for <dev@dpdk.org>; Wed,  7 Apr 2021 13:28:23 +0200 (CEST)
Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58])
 by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FFhst6XTTzyNfc;
 Wed,  7 Apr 2021 19:26:10 +0800 (CST)
Received: from [10.67.103.128] (10.67.103.128) by
 DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id
 14.3.498.0; Wed, 7 Apr 2021 19:28:17 +0800
To: "dev@dpdk.org" <dev@dpdk.org>, Ferruh Yigit <ferruh.yigit@intel.com>,
 Andrew Rybchenko <Andrew.Rybchenko@oktetlabs.ru>, Thomas Monjalon
 <thomas@monjalon.net>
From: "Min Hu (Connor)" <humin29@huawei.com>
Message-ID: <6114bde2-423a-da82-ac4d-608141235e39@huawei.com>
Date: Wed, 7 Apr 2021 19:28:18 +0800
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
 Thunderbird/68.3.1
MIME-Version: 1.0
Content-Type: text/plain; charset="gbk"; format=flowed
Content-Transfer-Encoding: 7bit
X-Originating-IP: [10.67.103.128]
X-CFilter-Loop: Reflected
Subject: [dpdk-dev] Questions about API with no parameter check
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Hi, all,
	Many APIs in DPDK does not check if the pointer parameter is
NULL or not. For example, in 'rte_ethdev.c':
int
rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
		       uint16_t nb_rx_desc, unsigned int socket_id,
		       const struct rte_eth_rxconf *rx_conf,
		       struct rte_mempool *mp)

int
rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)

int
rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)

int
rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)

As these APIs could be used by any APPs, if the APP give NULL as
the pointer parameter, segmetation default will occur.

So, my question is, should we add check in the API? like that,
int rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
{
	if (stats == NULL)
		return -EINVAL;
	...
}

Or, that is redundant, the parameter correctness should be guaranteed by
the APP?

What's your opinion? Hope for your reply.
	Thanks.