Skip to content

Commit 9840fcd

Browse files
committed
fsi: Prevent multiple concurrent rescans
The bus scanning process isn't terribly good at parallel attempts at rescanning the same bus. Let's have a per-master mutex protecting the scanning process. Signed-off-by: Benjamin Herrenschmidt <[email protected]>
1 parent d1dcd67 commit 9840fcd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

drivers/fsi/fsi-core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,14 @@ static void fsi_master_unscan(struct fsi_master *master)
12031203

12041204
int fsi_master_rescan(struct fsi_master *master)
12051205
{
1206+
int rc;
1207+
1208+
mutex_lock(&master->scan_lock);
12061209
fsi_master_unscan(master);
1207-
return fsi_master_scan(master);
1210+
rc = fsi_master_scan(master);
1211+
mutex_unlock(&master->scan_lock);
1212+
1213+
return rc;
12081214
}
12091215
EXPORT_SYMBOL_GPL(fsi_master_rescan);
12101216

@@ -1240,6 +1246,7 @@ int fsi_master_register(struct fsi_master *master)
12401246
int rc;
12411247
struct device_node *np;
12421248

1249+
mutex_init(&master->scan_lock);
12431250
master->idx = ida_simple_get(&master_ida, 0, INT_MAX, GFP_KERNEL);
12441251
dev_set_name(&master->dev, "fsi%d", master->idx);
12451252

@@ -1264,8 +1271,11 @@ int fsi_master_register(struct fsi_master *master)
12641271
}
12651272

12661273
np = dev_of_node(&master->dev);
1267-
if (!of_property_read_bool(np, "no-scan-on-init"))
1274+
if (!of_property_read_bool(np, "no-scan-on-init")) {
1275+
mutex_lock(&master->scan_lock);
12681276
fsi_master_scan(master);
1277+
mutex_unlock(&master->scan_lock);
1278+
}
12691279

12701280
return 0;
12711281
}
@@ -1278,7 +1288,9 @@ void fsi_master_unregister(struct fsi_master *master)
12781288
master->idx = -1;
12791289
}
12801290

1291+
mutex_lock(&master->scan_lock);
12811292
fsi_master_unscan(master);
1293+
mutex_unlock(&master->scan_lock);
12821294
device_unregister(&master->dev);
12831295
}
12841296
EXPORT_SYMBOL_GPL(fsi_master_unregister);

drivers/fsi/fsi-master.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define DRIVERS_FSI_MASTER_H
1919

2020
#include <linux/device.h>
21+
#include <linux/mutex.h>
2122

2223
/* Various protocol delays */
2324
#define FSI_ECHO_DELAY_CLOCKS 16 /* Number clocks for echo delay */
@@ -59,6 +60,7 @@ struct fsi_master {
5960
int idx;
6061
int n_links;
6162
int flags;
63+
struct mutex scan_lock;
6264
int (*read)(struct fsi_master *, int link, uint8_t id,
6365
uint32_t addr, void *val, size_t size);
6466
int (*write)(struct fsi_master *, int link, uint8_t id,

0 commit comments

Comments
 (0)