mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: wan: farsync: reuse card slots after hot-unplug
@ 2026-11-17  4:13 Shirong Zhao
  2026-11-17  4:16 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Shirong Zhao @ 2026-11-17  4:13 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel

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@163.com>
---
 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;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17  4:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  4:13 [PATCH net] net: wan: farsync: reuse card slots after hot-unplug Shirong Zhao
2026-11-17  4:16 ` netdev-bot+sinfo
2026-11-17  4:26   ` Shirong Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®