Skip to contentSkip to conversation

net: cxgb3: Fix an error code when probing the driver

PATCH Superseded Zheyu Ma 3 participants 5 messages Mar 5, 2022 – Mar 8, 2022

Subsystems (3)
lore
Share & tools
lore

Zheyu Ma

author
#0 lore raw

PATCH 1/1 net: cxgb3: Fix an error code when probing the driver

During the process of driver probing, probe function should return < 0 for failure, otherwise kernel will treat value >= 0 as success.

Therefore, the driver should set 'err' to -EINVAL when 'adapter->registered_device_map' is NULL. Otherwise kernel will assume that the driver has been successfully probed and will cause unexpected errors.

---
 drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +1 -0
index bfffcaeee624..662af61fc723 100644
@@ -3346,6 +3346,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	if (!adapter->registered_device_map) {
 		dev_err(&pdev->dev, "could not register any net devices\n");
+		err = -EINVAL;
 		goto out_free_dev;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 18 lines · Zheyu Ma

During the process of driver probing, probe function should return < 0 for failure, otherwise kernel will treat value >= 0 as success.

Therefore, the driver should set 'err' to -EINVAL when 'adapter->registered_device_map' is NULL. Otherwise kernel will assume that the driver has been successfully probed and will cause unexpected errors.

---
 drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +0 -0
index bfffcaeee624..662af61fc723 100644

drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 3349

Quoted 4 lines
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +1 -0
@@ -3346,6 +3346,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	if (!adapter->registered_device_map) {
 		dev_err(&pdev->dev, "could not register any net devices\n");
+		err = -EINVAL;

ENODEV would be better.

Andrew

author
#2 lore raw

PATCH v2 1/1 net: cxgb3: Fix an error code when probing the driver

In reply to Zheyu Ma

During the process of driver probing, probe function should return < 0 for failure, otherwise kernel will treat value >= 0 as success.

Therefore, the driver should set 'err' to -ENODEV when 'adapter->registered_device_map' is NULL. Otherwise kernel will assume that the driver has been successfully probed and will cause unexpected errors.

---
Changes in v2:
- Change the error code

---
 drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c +1 -0
index bfffcaeee624..0d3325cf2107 100644
@@ -3346,6 +3346,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 	if (!adapter->registered_device_map) {
 		dev_err(&pdev->dev, "could not register any net devices\n");
+		err = -ENODEV;
 		goto out_free_dev;
 	}
 
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 9 lines · Zheyu Ma

During the process of driver probing, probe function should return < 0 for failure, otherwise kernel will treat value >= 0 as success.

Therefore, the driver should set 'err' to -ENODEV when 'adapter->registered_device_map' is NULL. Otherwise kernel will assume that the driver has been successfully probed and will cause unexpected errors.

Andrew

#4 lore raw
In reply to Zheyu Ma
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Sun, 6 Mar 2022 05:56:32 +0000 you wrote:

During the process of driver probing, probe function should return < 0 for failure, otherwise kernel will treat value >= 0 as success.

Therefore, the driver should set 'err' to -ENODEV when 'adapter->registered_device_map' is NULL. Otherwise kernel will assume that the driver has been successfully probed and will cause unexpected errors.

[...]

Here is the summary with links:
- [v2] net: cxgb3: Fix an error code when probing the driver

    https://git.kernel.org/netdev/net-next/c/69adcb988a06

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html