Skip to content

Commit 932c043

Browse files
kashuwongMatthew Chapman
authored andcommitted
driver: fall back to minimal functionality if an error occurs during probe
This patch add the capability to fall back to minimal functionality on error, to allow reflashing cards with broken firmware. It also fixes a kernel panic on remove that previously occurred with unsupported cards.
1 parent 353d49a commit 932c043

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

modules/exanic/exanic-main.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,6 @@ static int exanic_probe(struct pci_dev *pdev,
951951
unsigned port_num;
952952
const char *hw_id_str;
953953
const char *function_str;
954-
bool unsupported_exanic = false;
955954
uint32_t dma_cfg;
956955
u8 mac_addr[ETH_ALEN];
957956

@@ -1051,44 +1050,21 @@ static int exanic_probe(struct pci_dev *pdev,
10511050
"Unsupported exanic interface version: %u (min %u, max %u)\n",
10521051
exanic->pcie_if_ver, MIN_SUPPORTED_PCIE_IF_VER,
10531052
MAX_SUPPORTED_PCIE_IF_VER);
1054-
unsupported_exanic = true;
1053+
goto err_interface_ver;
10551054
}
10561055

10571056
hw_id_str = exanic_hardware_id_str(exanic->hw_id);
10581057
if (hw_id_str == NULL)
10591058
{
10601059
dev_err(dev, "Unsupported hardware type: %u\n", exanic->hw_id);
1061-
unsupported_exanic = true;
1060+
goto err_hw_id;
10621061
}
10631062

10641063
function_str = exanic_function_id_str(exanic->function_id);
10651064
if (function_str == NULL)
10661065
{
10671066
dev_err(dev, "Unsupported function type: %u\n", exanic->function_id);
1068-
unsupported_exanic = true;
1069-
}
1070-
1071-
if (unsupported_exanic)
1072-
{
1073-
/* Minimal support for unsupported cards, to allow firmware update. */
1074-
1075-
/* Register device (misc_dev.minor already initialized) */
1076-
exanic->misc_dev.name = exanic->name;
1077-
exanic->misc_dev.fops = &exanic_fops;
1078-
exanic->unsupported = true;
1079-
exanic->num_ports = 0;
1080-
err = misc_register(&exanic->misc_dev);
1081-
if (err)
1082-
{
1083-
dev_err(dev, "misc_register failed: %d\n", err);
1084-
goto err_unsupported_exanic;
1085-
}
1086-
1087-
dev_info(dev, "Finished probing %s (minor = %u):\n",
1088-
exanic->name, exanic->misc_dev.minor);
1089-
dev_info(dev, " Unknown exanic version, minimal support enabled\n");
1090-
1091-
return 0;
1067+
goto err_function_id;
10921068
}
10931069

10941070
/* Make sure card has completed its startup sequence */
@@ -1801,7 +1777,30 @@ static int exanic_probe(struct pci_dev *pdev,
18011777
iounmap(exanic->tx_region_virt);
18021778
err_dma_mask:
18031779
err_timeout:
1804-
err_unsupported_exanic:
1780+
err_function_id:
1781+
err_hw_id:
1782+
err_interface_ver:
1783+
1784+
/* Minimal support for unsupported cards, to allow firmware update. */
1785+
1786+
/* Register device (misc_dev.minor already initialized) */
1787+
exanic->misc_dev.name = exanic->name;
1788+
exanic->misc_dev.fops = &exanic_fops;
1789+
exanic->unsupported = true;
1790+
exanic->num_ports = 0;
1791+
err = misc_register(&exanic->misc_dev);
1792+
if (!err)
1793+
{
1794+
dev_info(dev, "Finished probing %s (minor = %u):\n",
1795+
exanic->name, exanic->misc_dev.minor);
1796+
dev_info(dev, " Error encountered during probe, minimal support enabled\n");
1797+
return 0;
1798+
}
1799+
else
1800+
dev_err(dev, "misc_register failed: %d\n", err);
1801+
1802+
/* If we get here, no device file was created and we need to error out */
1803+
18051804
iounmap(exanic->regs_virt);
18061805
err_regs_ioremap:
18071806
err_regs_size:
@@ -1906,8 +1905,12 @@ static void exanic_remove(struct pci_dev *pdev)
19061905
if (exanic->tx_region_virt != NULL)
19071906
iounmap(exanic->tx_region_virt);
19081907

1909-
exanic_sysfs_exit(exanic);
1910-
exanic_i2c_exit(exanic);
1908+
if (!exanic->unsupported)
1909+
{
1910+
exanic_sysfs_exit(exanic);
1911+
exanic_i2c_exit(exanic);
1912+
}
1913+
19111914
misc_deregister(&exanic->misc_dev);
19121915

19131916
/* If a card reset has been requested post remove, trigger that just before

0 commit comments

Comments
 (0)