[02/11] net/tap: check if name is null

Message ID 20221121204015.1135573-3-okaya@kernel.org (mailing list archive)
State Superseded, archived
Headers
Series codeql fixes for various subsystems |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Sinan Kaya Nov. 21, 2022, 8:40 p.m. UTC
  From: Sinan Kaya <okaya@kernel.org>

In rte_pmd_tun_probe result of call to rte_vdev_device_name is
dereferenced here and may be null.

Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
 drivers/net/tap/rte_eth_tap.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Thomas Monjalon Nov. 21, 2022, 9:41 p.m. UTC | #1
21/11/2022 21:40, okaya@kernel.org:
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -2340,6 +2340,10 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
>  	struct rte_eth_dev *eth_dev;
>  
>  	name = rte_vdev_device_name(dev);
> +	if (!name) {

Please it is preferred to check against NULL,
because name is not a boolean, thanks.
I know it's longer but it is more explicit.

Thanks for the fixes in this series.
  
Sinan Kaya Nov. 21, 2022, 10:03 p.m. UTC | #2
On Mon, 2022-11-21 at 22:41 +0100, Thomas Monjalon wrote:
> 21/11/2022 21:40, okaya@kernel.org:
> > --- a/drivers/net/tap/rte_eth_tap.c+++
> > b/drivers/net/tap/rte_eth_tap.c@@ -2340,6 +2340,10 @@
> > rte_pmd_tun_probe(struct rte_vdev_device *dev) 	struct
> > rte_eth_dev *eth_dev;  	name = rte_vdev_device_name(dev);+	if
> > (!name) {
> 
> Please it is preferred to check against NULL,because name is not a
> boolean, thanks.I know it's longer but it is more explicit.

Sure, I can do that. Getting used to dpdk coding style. I wasn't sure
what to do with braces on single line too. At least, I got a warning on
that too.

> Thanks for the fixes in this series.
> 

Cheers
  
Ferruh Yigit Nov. 21, 2022, 10:57 p.m. UTC | #3
On 11/21/2022 10:03 PM, Sinan Kaya wrote:
> On Mon, 2022-11-21 at 22:41 +0100, Thomas Monjalon wrote:
>> 21/11/2022 21:40, 
>> okaya@kernel.org
>>  <mailto:okaya@kernel.org>
>> :
>>> --- a/drivers/net/tap/rte_eth_tap.c
>>> +++ b/drivers/net/tap/rte_eth_tap.c
>>> @@ -2340,6 +2340,10 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev)
>>>  	struct rte_eth_dev *eth_dev;
>>>  
>>>  	name = rte_vdev_device_name(dev);
>>> +	if (!name) {
>>
>> Please it is preferred to check against NULL,
>> because name is not a boolean, thanks.
>> I know it's longer but it is more explicit.
> 
> Sure, I can do that. Getting used to dpdk coding style. I wasn't sure
> what to do with braces on single line too. At least, I got a warning on
> that too.
> 

DPDK coding convention is documented if it helps:
https://doc.dpdk.org/guides/contributing/coding_style.html

>>
>> Thanks for the fixes in this series.
>>
>>
> 
> Cheers
>
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index f2a6c33a19..aa640f8acc 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -2340,6 +2340,10 @@  rte_pmd_tun_probe(struct rte_vdev_device *dev)
 	struct rte_eth_dev *eth_dev;
 
 	name = rte_vdev_device_name(dev);
+	if (!name) {
+		return -1;
+	}
+
 	params = rte_vdev_device_args(dev);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);