Commit f7315408 authored by Jeremy Sowden's avatar Jeremy Sowden Committed by Greg Kroah-Hartman

staging: kpc2000: use IDA to assign card numbers.

Previously the next card number was assigned from a static int local
variable.  Replaced it with an IDA.  Avoids the assignment of ever-
increasing card-numbers by allowing them to be reused.

Updated TODO.

Corrected format-specifier for unsigned pcard->card_num.
Signed-off-by: default avatarJeremy Sowden <jeremy@azazel.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 80bcd6cc
- the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel... - the kpc_spi driver doesn't seem to let multiple transactions (to different instances of the core) happen in parallel...
- The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton. It functions against current hardware though. - The kpc_i2c driver is a hot mess, it should probably be cleaned up a ton. It functions against current hardware though.
- pcard->card_num in kp2000_pcie_probe() is a global variable and needs atomic / locking / something better.
- would be nice if the AIO fileops in kpc_dma could be made to work - would be nice if the AIO fileops in kpc_dma could be made to work
- probably want to add a CONFIG_ option to control compilation of the AIO functions - probably want to add a CONFIG_ option to control compilation of the AIO functions
- if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too - if the AIO fileops in kpc_dma start working, next would be making iov_count > 1 work too
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/idr.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
...@@ -25,6 +26,8 @@ ...@@ -25,6 +26,8 @@
#include "pcie.h" #include "pcie.h"
#include "uapi.h" #include "uapi.h"
static DEFINE_IDA(card_num_ida);
/******************************************************* /*******************************************************
* SysFS Attributes * SysFS Attributes
******************************************************/ ******************************************************/
...@@ -388,7 +391,6 @@ static int kp2000_pcie_probe(struct pci_dev *pdev, ...@@ -388,7 +391,6 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
{ {
int err = 0; int err = 0;
struct kp2000_device *pcard; struct kp2000_device *pcard;
static int card_count = 1;
int rv; int rv;
unsigned long reg_bar_phys_addr; unsigned long reg_bar_phys_addr;
unsigned long reg_bar_phys_len; unsigned long reg_bar_phys_len;
...@@ -414,9 +416,14 @@ static int kp2000_pcie_probe(struct pci_dev *pdev, ...@@ -414,9 +416,14 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
/* /*
* Step 2: Initialize trivial pcard elements * Step 2: Initialize trivial pcard elements
*/ */
pcard->card_num = card_count; err = ida_simple_get(&card_num_ida, 1, INT_MAX, GFP_KERNEL);
card_count++; if (err < 0) {
scnprintf(pcard->name, 16, "kpcard%d", pcard->card_num); dev_err(&pdev->dev, "probe: failed to get card number (%d)\n",
err);
goto out2;
}
pcard->card_num = err;
scnprintf(pcard->name, 16, "kpcard%u", pcard->card_num);
mutex_init(&pcard->sem); mutex_init(&pcard->sem);
mutex_lock(&pcard->sem); mutex_lock(&pcard->sem);
...@@ -630,6 +637,8 @@ static int kp2000_pcie_probe(struct pci_dev *pdev, ...@@ -630,6 +637,8 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
pci_disable_device(pcard->pdev); pci_disable_device(pcard->pdev);
out3: out3:
mutex_unlock(&pcard->sem); mutex_unlock(&pcard->sem);
ida_simple_remove(&card_num_ida, pcard->card_num);
out2:
kfree(pcard); kfree(pcard);
return err; return err;
} }
...@@ -663,6 +672,7 @@ static void kp2000_pcie_remove(struct pci_dev *pdev) ...@@ -663,6 +672,7 @@ static void kp2000_pcie_remove(struct pci_dev *pdev)
pci_disable_device(pcard->pdev); pci_disable_device(pcard->pdev);
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
mutex_unlock(&pcard->sem); mutex_unlock(&pcard->sem);
ida_simple_remove(&card_num_ida, pcard->card_num);
kfree(pcard); kfree(pcard);
} }
...@@ -698,6 +708,7 @@ static void __exit kp2000_pcie_exit(void) ...@@ -698,6 +708,7 @@ static void __exit kp2000_pcie_exit(void)
{ {
pci_unregister_driver(&kp2000_driver_inst); pci_unregister_driver(&kp2000_driver_inst);
class_destroy(kpc_uio_class); class_destroy(kpc_uio_class);
ida_destroy(&card_num_ida);
} }
module_exit(kp2000_pcie_exit); module_exit(kp2000_pcie_exit);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment