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 F05C5A0547;
	Wed, 21 Apr 2021 15:19:20 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 70B1041AC8;
	Wed, 21 Apr 2021 15:19:20 +0200 (CEST)
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by mails.dpdk.org (Postfix) with ESMTP id 658D9410F9;
 Wed, 21 Apr 2021 15:19:18 +0200 (CEST)
IronPort-SDR: pWtD5ff9bGMdkmY1Ehn/jYxnb41IixKr4XjWxaxswRo7wAhUqr/hw4HLe39uXpHVCWM43rV8yb
 b5CmyU04975g==
X-IronPort-AV: E=McAfee;i="6200,9189,9961"; a="216335691"
X-IronPort-AV: E=Sophos;i="5.82,240,1613462400"; d="scan'208";a="216335691"
Received: from fmsmga002.fm.intel.com ([10.253.24.26])
 by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 21 Apr 2021 06:19:17 -0700
IronPort-SDR: kA2cF04jeq4vJpo2zT/6iFnmROcMKUv6VEMq8+b1ZmjirpDkSZbQFj1yMzlMuVZLEo3ZfiF/e6
 xyfYNQBNZL6Q==
X-IronPort-AV: E=Sophos;i="5.82,240,1613462400"; d="scan'208";a="455338416"
Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.213.206.218])
 ([10.213.206.218])
 by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 21 Apr 2021 06:19:13 -0700
To: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
 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,
 Kevin Traynor <ktraynor@redhat.com>
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: Ferruh Yigit <ferruh.yigit@intel.com>
X-User: ferruhy
Message-ID: <b1234cca-5698-2722-5901-df9a7b95d21c@intel.com>
Date: Wed, 21 Apr 2021 14:19:08 +0100
MIME-Version: 1.0
In-Reply-To: <7b5f899e-aa34-ac36-ace3-7b2830257ff4@oktetlabs.ru>
Content-Type: text/plain; charset=utf-8; format=flowed
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 4/21/2021 12:28 PM, 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
> 
> 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.
> 

Right, above is wrong.

Agree that "fw_version == NULL && fw_size > 0" is error condition,
but is it clear if how this API should behave on
"fw_version == NULL && fw_size == 0"?

Like sfc has following,
  if ((fw_version == NULL) || (fw_size == 0))
  	return -EINVAL;