* [PATCH linux dev-4.7 v3] drivers: fsi: Use kernel ida to manage device indexes
@ 2017-02-17 21:38 Eddie James
2017-02-20 6:56 ` Jeremy Kerr
0 siblings, 1 reply; 3+ messages in thread
From: Eddie James @ 2017-02-17 21:38 UTC (permalink / raw)
To: openbmc; +Cc: joel, cbostic, Edward A. James
From: "Edward A. James" <eajames@us.ibm.com>
Fixes bad device indexes and duplicates after fsi rescan
Signed-off-by: Edward A. James <eajames@us.ibm.com>
---
drivers/fsi/fsi-core.c | 10 ++++++++--
drivers/fsi/fsi-master-gpio.c | 1 +
drivers/fsi/fsi-scom.c | 9 +++++++--
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index e8a3618..d63a892 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -15,6 +15,7 @@
#include <linux/device.h>
#include <linux/fsi.h>
+#include <linux/idr.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -46,7 +47,7 @@ static const int engine_page_size = 0x400;
static struct task_struct *master_ipoll;
static unsigned int fsi_ipoll_period_ms = 100;
-static atomic_t master_idx = ATOMIC_INIT(-1);
+static DEFINE_IDA(master_ida);
struct fsi_slave {
struct list_head list_link; /* Master's list of slaves */
@@ -599,7 +600,7 @@ int fsi_master_register(struct fsi_master *master)
if (!master || !master->dev)
return -EINVAL;
- master->idx = atomic_inc_return(&master_idx);
+ master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
master->slave_list = false;
get_device(master->dev);
fsi_master_scan(master);
@@ -610,6 +611,11 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
void fsi_master_unregister(struct fsi_master *master)
{
+ if (master->idx >= 0) {
+ ida_simple_remove(&master_ida, master->idx);
+ master->idx = -1;
+ }
+
device_remove_file(master->dev, &dev_attr_fsi_ipoll_period);
fsi_master_unscan(master);
put_device(master->dev);
diff --git a/drivers/fsi/fsi-master-gpio.c b/drivers/fsi/fsi-master-gpio.c
index 91bdbf2..3ed82ea 100644
--- a/drivers/fsi/fsi-master-gpio.c
+++ b/drivers/fsi/fsi-master-gpio.c
@@ -512,6 +512,7 @@ static int fsi_master_gpio_probe(struct platform_device *pdev)
else
master->gpio_mux = gpio;
+ master->master.idx = -1;
master->master.n_links = 1;
master->master.read = fsi_master_gpio_read;
master->master.write = fsi_master_gpio_write;
diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c
index a439a5e..2874ea0 100644
--- a/drivers/fsi/fsi-scom.c
+++ b/drivers/fsi/fsi-scom.c
@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/list.h>
+#include <linux/idr.h>
#define FSI_ENGID_SCOM 0x5
@@ -41,12 +42,14 @@ struct scom_device {
struct fsi_device *fsi_dev;
struct miscdevice mdev;
char name[32];
+ int idx;
};
#define to_scom_dev(x) container_of((x), struct scom_device, mdev)
static struct list_head scom_devices;
-static atomic_t scom_idx = ATOMIC_INIT(0);
+
+static DEFINE_IDA(scom_ida);
static int put_scom(struct scom_device *scom_dev, uint64_t value,
uint32_t addr)
@@ -187,8 +190,9 @@ static int scom_probe(struct device *dev)
if (!scom)
return -ENOMEM;
+ scom->idx = ida_simple_get(&scom_ida, 1, INT_MAX, GFP_KERNEL);
snprintf(scom->name, sizeof(scom->name),
- "scom%d", atomic_inc_return(&scom_idx));
+ "scom%d", scom->idx);
scom->fsi_dev = fsi_dev;
scom->mdev.minor = MISC_DYNAMIC_MINOR;
scom->mdev.fops = &scom_fops;
@@ -207,6 +211,7 @@ static int scom_remove(struct device *dev)
list_for_each_entry_safe(scom, scom_tmp, &scom_devices, link) {
if (scom->fsi_dev == fsi_dev) {
list_del(&scom->link);
+ ida_simple_remove(&scom_ida, scom->idx);
misc_deregister(&scom->mdev);
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH linux dev-4.7 v3] drivers: fsi: Use kernel ida to manage device indexes
2017-02-17 21:38 [PATCH linux dev-4.7 v3] drivers: fsi: Use kernel ida to manage device indexes Eddie James
@ 2017-02-20 6:56 ` Jeremy Kerr
2017-02-20 23:20 ` Joel Stanley
0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Kerr @ 2017-02-20 6:56 UTC (permalink / raw)
To: Eddie James, openbmc; +Cc: Edward A. James, cbostic
Hi Eddie,
> Fixes bad device indexes and duplicates after fsi rescan
Looks good to me - much cooler than the existing atomic counter.
Acked-by: Jeremy Kerr <jk@ozlabs.org>
Cheers,
Jeremy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH linux dev-4.7 v3] drivers: fsi: Use kernel ida to manage device indexes
2017-02-20 6:56 ` Jeremy Kerr
@ 2017-02-20 23:20 ` Joel Stanley
0 siblings, 0 replies; 3+ messages in thread
From: Joel Stanley @ 2017-02-20 23:20 UTC (permalink / raw)
To: Jeremy Kerr
Cc: Eddie James, OpenBMC Maillist, Edward A. James, Christopher Bostic
On Mon, Feb 20, 2017 at 5:26 PM, Jeremy Kerr <jk@ozlabs.org> wrote:
> Hi Eddie,
>
>> Fixes bad device indexes and duplicates after fsi rescan
>
> Looks good to me - much cooler than the existing atomic counter.
>
> Acked-by: Jeremy Kerr <jk@ozlabs.org>
Thanks for taking a look Jeremy.
Applied to dev-4.7.
Cheers,
Joel
>
> Cheers,
>
>
> Jeremy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-20 23:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 21:38 [PATCH linux dev-4.7 v3] drivers: fsi: Use kernel ida to manage device indexes Eddie James
2017-02-20 6:56 ` Jeremy Kerr
2017-02-20 23:20 ` Joel Stanley
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.