7
7
* Copyright (C) 2014, Freescale Semiconductor, Inc.
8
8
*/
9
9
10
- #include <linux/err.h>
11
- #include <linux/errno.h>
10
+ #include <linux/cleanup.h>
12
11
#include <linux/delay.h>
13
12
#include <linux/device.h>
13
+ #include <linux/err.h>
14
+ #include <linux/errno.h>
14
15
#include <linux/math64.h>
15
16
#include <linux/module.h>
16
17
#include <linux/mtd/mtd.h>
17
18
#include <linux/mtd/spi-nor.h>
18
19
#include <linux/mutex.h>
19
- #include <linux/of_platform .h>
20
+ #include <linux/of .h>
20
21
#include <linux/regulator/consumer.h>
21
22
#include <linux/sched/task_stack.h>
22
23
#include <linux/sizes.h>
@@ -639,32 +640,26 @@ static bool spi_nor_use_parallel_locking(struct spi_nor *nor)
639
640
static int spi_nor_rww_start_rdst (struct spi_nor * nor )
640
641
{
641
642
struct spi_nor_rww * rww = & nor -> rww ;
642
- int ret = - EAGAIN ;
643
643
644
- mutex_lock (& nor -> lock );
644
+ guard ( mutex ) (& nor -> lock );
645
645
646
646
if (rww -> ongoing_io || rww -> ongoing_rd )
647
- goto busy ;
647
+ return - EAGAIN ;
648
648
649
649
rww -> ongoing_io = true;
650
650
rww -> ongoing_rd = true;
651
- ret = 0 ;
652
651
653
- busy :
654
- mutex_unlock (& nor -> lock );
655
- return ret ;
652
+ return 0 ;
656
653
}
657
654
658
655
static void spi_nor_rww_end_rdst (struct spi_nor * nor )
659
656
{
660
657
struct spi_nor_rww * rww = & nor -> rww ;
661
658
662
- mutex_lock (& nor -> lock );
659
+ guard ( mutex ) (& nor -> lock );
663
660
664
661
rww -> ongoing_io = false;
665
662
rww -> ongoing_rd = false;
666
-
667
- mutex_unlock (& nor -> lock );
668
663
}
669
664
670
665
static int spi_nor_lock_rdst (struct spi_nor * nor )
@@ -1212,26 +1207,21 @@ static void spi_nor_offset_to_banks(u64 bank_size, loff_t start, size_t len,
1212
1207
static bool spi_nor_rww_start_io (struct spi_nor * nor )
1213
1208
{
1214
1209
struct spi_nor_rww * rww = & nor -> rww ;
1215
- bool start = false;
1216
1210
1217
- mutex_lock (& nor -> lock );
1211
+ guard ( mutex ) (& nor -> lock );
1218
1212
1219
1213
if (rww -> ongoing_io )
1220
- goto busy ;
1214
+ return false ;
1221
1215
1222
1216
rww -> ongoing_io = true;
1223
- start = true;
1224
1217
1225
- busy :
1226
- mutex_unlock (& nor -> lock );
1227
- return start ;
1218
+ return true;
1228
1219
}
1229
1220
1230
1221
static void spi_nor_rww_end_io (struct spi_nor * nor )
1231
1222
{
1232
- mutex_lock (& nor -> lock );
1223
+ guard ( mutex ) (& nor -> lock );
1233
1224
nor -> rww .ongoing_io = false;
1234
- mutex_unlock (& nor -> lock );
1235
1225
}
1236
1226
1237
1227
static int spi_nor_lock_device (struct spi_nor * nor )
@@ -1254,32 +1244,27 @@ static void spi_nor_unlock_device(struct spi_nor *nor)
1254
1244
static bool spi_nor_rww_start_exclusive (struct spi_nor * nor )
1255
1245
{
1256
1246
struct spi_nor_rww * rww = & nor -> rww ;
1257
- bool start = false;
1258
1247
1259
1248
mutex_lock (& nor -> lock );
1260
1249
1261
1250
if (rww -> ongoing_io || rww -> ongoing_rd || rww -> ongoing_pe )
1262
- goto busy ;
1251
+ return false ;
1263
1252
1264
1253
rww -> ongoing_io = true;
1265
1254
rww -> ongoing_rd = true;
1266
1255
rww -> ongoing_pe = true;
1267
- start = true;
1268
1256
1269
- busy :
1270
- mutex_unlock (& nor -> lock );
1271
- return start ;
1257
+ return true;
1272
1258
}
1273
1259
1274
1260
static void spi_nor_rww_end_exclusive (struct spi_nor * nor )
1275
1261
{
1276
1262
struct spi_nor_rww * rww = & nor -> rww ;
1277
1263
1278
- mutex_lock (& nor -> lock );
1264
+ guard ( mutex ) (& nor -> lock );
1279
1265
rww -> ongoing_io = false;
1280
1266
rww -> ongoing_rd = false;
1281
1267
rww -> ongoing_pe = false;
1282
- mutex_unlock (& nor -> lock );
1283
1268
}
1284
1269
1285
1270
int spi_nor_prep_and_lock (struct spi_nor * nor )
@@ -1316,30 +1301,26 @@ static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len)
1316
1301
{
1317
1302
struct spi_nor_rww * rww = & nor -> rww ;
1318
1303
unsigned int used_banks = 0 ;
1319
- bool started = false;
1320
1304
u8 first , last ;
1321
1305
int bank ;
1322
1306
1323
- mutex_lock (& nor -> lock );
1307
+ guard ( mutex ) (& nor -> lock );
1324
1308
1325
1309
if (rww -> ongoing_io || rww -> ongoing_rd || rww -> ongoing_pe )
1326
- goto busy ;
1310
+ return false ;
1327
1311
1328
1312
spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
1329
1313
for (bank = first ; bank <= last ; bank ++ ) {
1330
1314
if (rww -> used_banks & BIT (bank ))
1331
- goto busy ;
1315
+ return false ;
1332
1316
1333
1317
used_banks |= BIT (bank );
1334
1318
}
1335
1319
1336
1320
rww -> used_banks |= used_banks ;
1337
1321
rww -> ongoing_pe = true;
1338
- started = true;
1339
1322
1340
- busy :
1341
- mutex_unlock (& nor -> lock );
1342
- return started ;
1323
+ return true;
1343
1324
}
1344
1325
1345
1326
static void spi_nor_rww_end_pe (struct spi_nor * nor , loff_t start , size_t len )
@@ -1348,15 +1329,13 @@ static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len)
1348
1329
u8 first , last ;
1349
1330
int bank ;
1350
1331
1351
- mutex_lock (& nor -> lock );
1332
+ guard ( mutex ) (& nor -> lock );
1352
1333
1353
1334
spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
1354
1335
for (bank = first ; bank <= last ; bank ++ )
1355
1336
rww -> used_banks &= ~BIT (bank );
1356
1337
1357
1338
rww -> ongoing_pe = false;
1358
-
1359
- mutex_unlock (& nor -> lock );
1360
1339
}
1361
1340
1362
1341
static int spi_nor_prep_and_lock_pe (struct spi_nor * nor , loff_t start , size_t len )
@@ -1393,31 +1372,27 @@ static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len)
1393
1372
{
1394
1373
struct spi_nor_rww * rww = & nor -> rww ;
1395
1374
unsigned int used_banks = 0 ;
1396
- bool started = false;
1397
1375
u8 first , last ;
1398
1376
int bank ;
1399
1377
1400
- mutex_lock (& nor -> lock );
1378
+ guard ( mutex ) (& nor -> lock );
1401
1379
1402
1380
if (rww -> ongoing_io || rww -> ongoing_rd )
1403
- goto busy ;
1381
+ return false ;
1404
1382
1405
1383
spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
1406
1384
for (bank = first ; bank <= last ; bank ++ ) {
1407
1385
if (rww -> used_banks & BIT (bank ))
1408
- goto busy ;
1386
+ return false ;
1409
1387
1410
1388
used_banks |= BIT (bank );
1411
1389
}
1412
1390
1413
1391
rww -> used_banks |= used_banks ;
1414
1392
rww -> ongoing_io = true;
1415
1393
rww -> ongoing_rd = true;
1416
- started = true;
1417
1394
1418
- busy :
1419
- mutex_unlock (& nor -> lock );
1420
- return started ;
1395
+ return true;
1421
1396
}
1422
1397
1423
1398
static void spi_nor_rww_end_rd (struct spi_nor * nor , loff_t start , size_t len )
@@ -1426,16 +1401,14 @@ static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len)
1426
1401
u8 first , last ;
1427
1402
int bank ;
1428
1403
1429
- mutex_lock (& nor -> lock );
1404
+ guard ( mutex ) (& nor -> lock );
1430
1405
1431
1406
spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
1432
1407
for (bank = first ; bank <= last ; bank ++ )
1433
1408
nor -> rww .used_banks &= ~BIT (bank );
1434
1409
1435
1410
rww -> ongoing_io = false;
1436
1411
rww -> ongoing_rd = false;
1437
-
1438
- mutex_unlock (& nor -> lock );
1439
1412
}
1440
1413
1441
1414
static int spi_nor_prep_and_lock_rd (struct spi_nor * nor , loff_t start , size_t len )
0 commit comments