[PATCH net] net: wan: farsync: reuse card slots after hot-unplug
From: Shirong Zhao
Date: Mon Nov 16 2026 - 23:13:27 EST
farsync keeps fst_card_array[FST_MAX_CARDS] and a file-static
no_of_cards_added counter that is only ever incremented:
fst_card_array[no_of_cards_added] = card;
card->card_no = no_of_cards_added++;
fst_remove_one() clears the array slot but leaves the counter at its
last value, so every probe/remove cycle permanently consumes one slot.
After FST_MAX_CARDS cycles the driver fails probe with "FarSync: too
many cards" even though no card is present. A failed probe after the
slot was claimed leaks the slot the same way.
Pick the first free slot instead of an ever-growing counter so slots
are reused after removal. card->card_no already records the slot that
fst_remove_one() clears, so the rest of the driver is unchanged.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Shirong Zhao <shxzhaosr@xxxxxxx>
---
drivers/net/wan/farsync.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 6508c53..a6fa4d3 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -2325,7 +2325,6 @@ static const struct net_device_ops fst_ops = {
static int
fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
- static int no_of_cards_added;
struct fst_card_info *card;
int err = 0;
int i;
@@ -2466,13 +2465,17 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent)
pci_set_drvdata(pdev, card);
/* Remainder of card setup */
- if (no_of_cards_added >= FST_MAX_CARDS) {
+ for (i = 0; i < FST_MAX_CARDS; i++) {
+ if (!fst_card_array[i])
+ break;
+ }
+ if (i == FST_MAX_CARDS) {
pr_err("FarSync: too many cards\n");
err = -ENOMEM;
goto card_array_fail;
}
- fst_card_array[no_of_cards_added] = card;
- card->card_no = no_of_cards_added++; /* Record instance and bump it */
+ fst_card_array[i] = card;
+ card->card_no = i;
err = fst_init_card(card);
if (err)
goto init_card_fail;