77 * Copyright (C) 2014, Freescale Semiconductor, Inc.
88 */
99
10- #include <linux/err.h>
11- #include <linux/errno.h>
10+ #include <linux/cleanup.h>
1211#include <linux/delay.h>
1312#include <linux/device.h>
13+ #include <linux/err.h>
14+ #include <linux/errno.h>
1415#include <linux/math64.h>
1516#include <linux/module.h>
1617#include <linux/mtd/mtd.h>
1718#include <linux/mtd/spi-nor.h>
1819#include <linux/mutex.h>
19- #include <linux/of_platform .h>
20+ #include <linux/of .h>
2021#include <linux/regulator/consumer.h>
2122#include <linux/sched/task_stack.h>
2223#include <linux/sizes.h>
@@ -639,32 +640,26 @@ static bool spi_nor_use_parallel_locking(struct spi_nor *nor)
639640static int spi_nor_rww_start_rdst (struct spi_nor * nor )
640641{
641642 struct spi_nor_rww * rww = & nor -> rww ;
642- int ret = - EAGAIN ;
643643
644- mutex_lock (& nor -> lock );
644+ guard ( mutex ) (& nor -> lock );
645645
646646 if (rww -> ongoing_io || rww -> ongoing_rd )
647- goto busy ;
647+ return - EAGAIN ;
648648
649649 rww -> ongoing_io = true;
650650 rww -> ongoing_rd = true;
651- ret = 0 ;
652651
653- busy :
654- mutex_unlock (& nor -> lock );
655- return ret ;
652+ return 0 ;
656653}
657654
658655static void spi_nor_rww_end_rdst (struct spi_nor * nor )
659656{
660657 struct spi_nor_rww * rww = & nor -> rww ;
661658
662- mutex_lock (& nor -> lock );
659+ guard ( mutex ) (& nor -> lock );
663660
664661 rww -> ongoing_io = false;
665662 rww -> ongoing_rd = false;
666-
667- mutex_unlock (& nor -> lock );
668663}
669664
670665static 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,
12121207static bool spi_nor_rww_start_io (struct spi_nor * nor )
12131208{
12141209 struct spi_nor_rww * rww = & nor -> rww ;
1215- bool start = false;
12161210
1217- mutex_lock (& nor -> lock );
1211+ guard ( mutex ) (& nor -> lock );
12181212
12191213 if (rww -> ongoing_io )
1220- goto busy ;
1214+ return false ;
12211215
12221216 rww -> ongoing_io = true;
1223- start = true;
12241217
1225- busy :
1226- mutex_unlock (& nor -> lock );
1227- return start ;
1218+ return true;
12281219}
12291220
12301221static void spi_nor_rww_end_io (struct spi_nor * nor )
12311222{
1232- mutex_lock (& nor -> lock );
1223+ guard ( mutex ) (& nor -> lock );
12331224 nor -> rww .ongoing_io = false;
1234- mutex_unlock (& nor -> lock );
12351225}
12361226
12371227static int spi_nor_lock_device (struct spi_nor * nor )
@@ -1254,32 +1244,27 @@ static void spi_nor_unlock_device(struct spi_nor *nor)
12541244static bool spi_nor_rww_start_exclusive (struct spi_nor * nor )
12551245{
12561246 struct spi_nor_rww * rww = & nor -> rww ;
1257- bool start = false;
12581247
12591248 mutex_lock (& nor -> lock );
12601249
12611250 if (rww -> ongoing_io || rww -> ongoing_rd || rww -> ongoing_pe )
1262- goto busy ;
1251+ return false ;
12631252
12641253 rww -> ongoing_io = true;
12651254 rww -> ongoing_rd = true;
12661255 rww -> ongoing_pe = true;
1267- start = true;
12681256
1269- busy :
1270- mutex_unlock (& nor -> lock );
1271- return start ;
1257+ return true;
12721258}
12731259
12741260static void spi_nor_rww_end_exclusive (struct spi_nor * nor )
12751261{
12761262 struct spi_nor_rww * rww = & nor -> rww ;
12771263
1278- mutex_lock (& nor -> lock );
1264+ guard ( mutex ) (& nor -> lock );
12791265 rww -> ongoing_io = false;
12801266 rww -> ongoing_rd = false;
12811267 rww -> ongoing_pe = false;
1282- mutex_unlock (& nor -> lock );
12831268}
12841269
12851270int 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)
13161301{
13171302 struct spi_nor_rww * rww = & nor -> rww ;
13181303 unsigned int used_banks = 0 ;
1319- bool started = false;
13201304 u8 first , last ;
13211305 int bank ;
13221306
1323- mutex_lock (& nor -> lock );
1307+ guard ( mutex ) (& nor -> lock );
13241308
13251309 if (rww -> ongoing_io || rww -> ongoing_rd || rww -> ongoing_pe )
1326- goto busy ;
1310+ return false ;
13271311
13281312 spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
13291313 for (bank = first ; bank <= last ; bank ++ ) {
13301314 if (rww -> used_banks & BIT (bank ))
1331- goto busy ;
1315+ return false ;
13321316
13331317 used_banks |= BIT (bank );
13341318 }
13351319
13361320 rww -> used_banks |= used_banks ;
13371321 rww -> ongoing_pe = true;
1338- started = true;
13391322
1340- busy :
1341- mutex_unlock (& nor -> lock );
1342- return started ;
1323+ return true;
13431324}
13441325
13451326static 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)
13481329 u8 first , last ;
13491330 int bank ;
13501331
1351- mutex_lock (& nor -> lock );
1332+ guard ( mutex ) (& nor -> lock );
13521333
13531334 spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
13541335 for (bank = first ; bank <= last ; bank ++ )
13551336 rww -> used_banks &= ~BIT (bank );
13561337
13571338 rww -> ongoing_pe = false;
1358-
1359- mutex_unlock (& nor -> lock );
13601339}
13611340
13621341static 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)
13931372{
13941373 struct spi_nor_rww * rww = & nor -> rww ;
13951374 unsigned int used_banks = 0 ;
1396- bool started = false;
13971375 u8 first , last ;
13981376 int bank ;
13991377
1400- mutex_lock (& nor -> lock );
1378+ guard ( mutex ) (& nor -> lock );
14011379
14021380 if (rww -> ongoing_io || rww -> ongoing_rd )
1403- goto busy ;
1381+ return false ;
14041382
14051383 spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
14061384 for (bank = first ; bank <= last ; bank ++ ) {
14071385 if (rww -> used_banks & BIT (bank ))
1408- goto busy ;
1386+ return false ;
14091387
14101388 used_banks |= BIT (bank );
14111389 }
14121390
14131391 rww -> used_banks |= used_banks ;
14141392 rww -> ongoing_io = true;
14151393 rww -> ongoing_rd = true;
1416- started = true;
14171394
1418- busy :
1419- mutex_unlock (& nor -> lock );
1420- return started ;
1395+ return true;
14211396}
14221397
14231398static 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)
14261401 u8 first , last ;
14271402 int bank ;
14281403
1429- mutex_lock (& nor -> lock );
1404+ guard ( mutex ) (& nor -> lock );
14301405
14311406 spi_nor_offset_to_banks (nor -> params -> bank_size , start , len , & first , & last );
14321407 for (bank = first ; bank <= last ; bank ++ )
14331408 nor -> rww .used_banks &= ~BIT (bank );
14341409
14351410 rww -> ongoing_io = false;
14361411 rww -> ongoing_rd = false;
1437-
1438- mutex_unlock (& nor -> lock );
14391412}
14401413
14411414static int spi_nor_prep_and_lock_rd (struct spi_nor * nor , loff_t start , size_t len )
0 commit comments