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 442F9A0547;
	Wed, 21 Apr 2021 14:39:10 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 00B9C41ACA;
	Wed, 21 Apr 2021 14:39:10 +0200 (CEST)
Received: from us-smtp-delivery-124.mimecast.com
 (us-smtp-delivery-124.mimecast.com [216.205.24.124])
 by mails.dpdk.org (Postfix) with ESMTP id 8040A410F9
 for <dev@dpdk.org>; Wed, 21 Apr 2021 14:39:08 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1619008747;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=WpZZjlKTuwshWqk9d/6t9kkXbKfCf9CWOuSTJrrALns=;
 b=WB1VvnAQVt9mvXarkvZeahkorxtMUCwJUyFvw+s5koz6EN6+M7egHMhGWeTnV5FbMZWBJy
 BJe4P6DJxhY1ZLZ91V1jNefBc084k1LoljRMwSbSKg8geL3pZ5JkoHwijGmepGvcHpSkv/
 3bnNWMY9WMGTMPXsNSrdpNmFyg9AabY=
Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com
 [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-525-Bd4xGunUPvGrUorVGhMFfw-1; Wed, 21 Apr 2021 08:39:03 -0400
X-MC-Unique: Bd4xGunUPvGrUorVGhMFfw-1
Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com
 [10.5.11.15])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E656E19253CC;
 Wed, 21 Apr 2021 12:39:00 +0000 (UTC)
Received: from [10.36.112.162] (ovpn-112-162.ams2.redhat.com [10.36.112.162])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 1A6875D6A1;
 Wed, 21 Apr 2021 12:38:56 +0000 (UTC)
To: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
 Ferruh Yigit <ferruh.yigit@intel.com>, Thomas Monjalon
 <thomas@monjalon.net>, Gaetan Rivet <grive@u256.net>,
 Stephen Hemminger <stephen@networkplumber.org>,
 Qi Zhang <qi.z.zhang@intel.com>, Ali Alnubani <alialnu@mellanox.com>,
 Yuanhan Liu <yuanhan.liu@linux.intel.com>, Matan Azrad <matan@mellanox.com>,
 Konstantin Ananyev <konstantin.ananyev@intel.com>,
 Zhiyong Yang <zhiyong.yang@intel.com>,
 Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: dev@dpdk.org, "Min Hu (Connor)" <humin29@huawei.com>, stable@dpdk.org
References: <1618645179-11582-1-git-send-email-humin29@huawei.com>
 <20210421023700.1640488-1-ferruh.yigit@intel.com>
 <7b5f899e-aa34-ac36-ace3-7b2830257ff4@oktetlabs.ru>
From: Kevin Traynor <ktraynor@redhat.com>
Message-ID: <b54e54e5-ddaa-10ce-2538-8ab49c61d862@redhat.com>
Date: Wed, 21 Apr 2021 13:38:55 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
 Thunderbird/78.8.1
MIME-Version: 1.0
In-Reply-To: <7b5f899e-aa34-ac36-ace3-7b2830257ff4@oktetlabs.ru>
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15
Authentication-Results: relay.mimecast.com;
 auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Subject: Re: [dpdk-dev] [PATCH v9] ethdev: add sanity checks in control APIs
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>

On 21/04/2021 12:28, Andrew Rybchenko wrote:
> On 4/21/21 5:36 AM, Ferruh Yigit wrote:
>> From: "Min Hu (Connor)" <humin29@huawei.com>
>>
>> This patch adds more sanity checks in control path APIs.
>>
>> Fixes: 214ed1acd125 ("ethdev: add iterator to match devargs input")
>> Fixes: 3d98f921fbe9 ("ethdev: unify prefix for static functions and variables")
>> Fixes: 0366137722a0 ("ethdev: check for invalid device name")
>> Fixes: d948f596fee2 ("ethdev: fix port data mismatched in multiple process model")
>> Fixes: 5b7ba31148a8 ("ethdev: add port ownership")
>> Fixes: f8244c6399d9 ("ethdev: increase port id range")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
>> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> 
> Few nits below.
> Other than that I confirm my "Reviewed-by".
> 
> The patch is really long. It would be better to split it into
> few:
>  - relocate dev assignment
>  - empty lines mangling (when it is unrelated to previous item)
>  - ops check before usage (combined with related style checks)
>  - error logs refinement
> 

+1

> However, since the patch is already reviewed this way, may
> be it is better to push as is after review notes processing.
> 
>> @@ -817,7 +859,12 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
>>  	uint16_t pid;
>>  
>>  	if (name == NULL) {
>> -		RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name");
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (port_id == NULL) {
>> +		RTE_ETHDEV_LOG(ERR, "Cannot get port ID to NULL\n");
> 
> Since name is already checked above, I think it would be useful
> to log 'name' here to provide context.
> 
>>  		return -EINVAL;
>>  	}
>>  
> 
> [snip]
> 
>> @@ -3256,6 +3370,20 @@ rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
>>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>  	dev = &rte_eth_devices[port_id];
>>  
>> +	if (fw_version == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (fw_size == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u FW version to buffer with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The only error condition is NULL fw_version with positive
> fw_size. Othwerwise, it could be just a call to get required
> size of buffer for FW version.
> 
>>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP);
>>  	return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev,
>>  							fw_version, fw_size));
> 
> [snip]
> 
>> @@ -3323,6 +3457,21 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
>>  
>>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>  	dev = &rte_eth_devices[port_id];
>> +
>> +	if (ptypes == NULL) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to NULL\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (num == 0) {
>> +		RTE_ETHDEV_LOG(ERR,
>> +			"Cannot get ethdev port %u supported packet types to array with zero size\n",
>> +			port_id);
>> +		return -EINVAL;
>> +	}
>> +
> 
> The error condition is "ptypes == NULL && num > 0".
> Otherwise, if num == 0 (regardless ptypes) it is just
> a call to get size of required buffer. Same as below.
> 
>>  	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0);
>>  	all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev);
>>  
> 

nice catch for these.

> [snip]
>