Skip to content

Commit adbf05e

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBI: simplify debugging return codes
UBI debugging functions were a little bit over-engineered and returned more error codes than needed, and the callers had to do useless checks. Simplify the return codes. Impact: only debugging code is affected, which means that for non-developers this is a no-op patch. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent 0bf1c43 commit adbf05e

3 files changed

Lines changed: 37 additions & 41 deletions

File tree

‎drivers/mtd/ubi/io.c‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
143143

144144
err = paranoid_check_not_bad(ubi, pnum);
145145
if (err)
146-
return err > 0 ? -EINVAL : err;
146+
return err;
147147

148148
addr = (loff_t)pnum * ubi->peb_size + offset;
149149
retry:
@@ -236,12 +236,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
236236

237237
err = paranoid_check_not_bad(ubi, pnum);
238238
if (err)
239-
return err > 0 ? -EINVAL : err;
239+
return err;
240240

241241
/* The area we are writing to has to contain all 0xFF bytes */
242242
err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
243243
if (err)
244-
return err > 0 ? -EINVAL : err;
244+
return err;
245245

246246
if (offset >= ubi->leb_start) {
247247
/*
@@ -250,10 +250,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
250250
*/
251251
err = paranoid_check_peb_ec_hdr(ubi, pnum);
252252
if (err)
253-
return err > 0 ? -EINVAL : err;
253+
return err;
254254
err = paranoid_check_peb_vid_hdr(ubi, pnum);
255255
if (err)
256-
return err > 0 ? -EINVAL : err;
256+
return err;
257257
}
258258

259259
if (ubi_dbg_is_write_failure()) {
@@ -348,7 +348,7 @@ static int do_sync_erase(struct ubi_device *ubi, int pnum)
348348

349349
err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
350350
if (err)
351-
return err > 0 ? -EINVAL : err;
351+
return err;
352352

353353
if (ubi_dbg_is_erase_failure() && !err) {
354354
dbg_err("cannot erase PEB %d (emulated)", pnum);
@@ -542,7 +542,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
542542

543543
err = paranoid_check_not_bad(ubi, pnum);
544544
if (err != 0)
545-
return err > 0 ? -EINVAL : err;
545+
return err;
546546

547547
if (ubi->ro_mode) {
548548
ubi_err("read-only mode");
@@ -819,7 +819,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
819819

820820
err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
821821
if (err)
822-
return -EINVAL;
822+
return err;
823823

824824
err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
825825
return err;
@@ -1083,7 +1083,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
10831083

10841084
err = paranoid_check_peb_ec_hdr(ubi, pnum);
10851085
if (err)
1086-
return err > 0 ? -EINVAL : err;
1086+
return err;
10871087

10881088
vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
10891089
vid_hdr->version = UBI_VERSION;
@@ -1092,7 +1092,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
10921092

10931093
err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
10941094
if (err)
1095-
return -EINVAL;
1095+
return err;
10961096

10971097
p = (char *)vid_hdr - ubi->vid_hdr_shift;
10981098
err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
@@ -1107,8 +1107,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
11071107
* @ubi: UBI device description object
11081108
* @pnum: physical eraseblock number to check
11091109
*
1110-
* This function returns zero if the physical eraseblock is good, a positive
1111-
* number if it is bad and a negative error code if an error occurred.
1110+
* This function returns zero if the physical eraseblock is good, %-EINVAL if
1111+
* it is bad and a negative error code if an error occurred.
11121112
*/
11131113
static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
11141114
{
@@ -1120,7 +1120,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
11201120

11211121
ubi_err("paranoid check failed for PEB %d", pnum);
11221122
ubi_dbg_dump_stack();
1123-
return err;
1123+
return err > 0 ? -EINVAL : err;
11241124
}
11251125

11261126
/**
@@ -1130,7 +1130,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
11301130
* @ec_hdr: the erase counter header to check
11311131
*
11321132
* This function returns zero if the erase counter header contains valid
1133-
* values, and %1 if not.
1133+
* values, and %-EINVAL if not.
11341134
*/
11351135
static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
11361136
const struct ubi_ec_hdr *ec_hdr)
@@ -1156,16 +1156,16 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
11561156
fail:
11571157
ubi_dbg_dump_ec_hdr(ec_hdr);
11581158
ubi_dbg_dump_stack();
1159-
return 1;
1159+
return -EINVAL;
11601160
}
11611161

11621162
/**
11631163
* paranoid_check_peb_ec_hdr - check erase counter header.
11641164
* @ubi: UBI device description object
11651165
* @pnum: the physical eraseblock number to check
11661166
*
1167-
* This function returns zero if the erase counter header is all right, %1 if
1168-
* not, and a negative error code if an error occurred.
1167+
* This function returns zero if the erase counter header is all right and and
1168+
* a negative error code if not or if an error occurred.
11691169
*/
11701170
static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
11711171
{
@@ -1188,7 +1188,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
11881188
ubi_err("paranoid check failed for PEB %d", pnum);
11891189
ubi_dbg_dump_ec_hdr(ec_hdr);
11901190
ubi_dbg_dump_stack();
1191-
err = 1;
1191+
err = -EINVAL;
11921192
goto exit;
11931193
}
11941194

@@ -1206,7 +1206,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
12061206
* @vid_hdr: the volume identifier header to check
12071207
*
12081208
* This function returns zero if the volume identifier header is all right, and
1209-
* %1 if not.
1209+
* %-EINVAL if not.
12101210
*/
12111211
static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
12121212
const struct ubi_vid_hdr *vid_hdr)
@@ -1233,7 +1233,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
12331233
ubi_err("paranoid check failed for PEB %d", pnum);
12341234
ubi_dbg_dump_vid_hdr(vid_hdr);
12351235
ubi_dbg_dump_stack();
1236-
return 1;
1236+
return -EINVAL;
12371237

12381238
}
12391239

@@ -1243,7 +1243,7 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
12431243
* @pnum: the physical eraseblock number to check
12441244
*
12451245
* This function returns zero if the volume identifier header is all right,
1246-
* %1 if not, and a negative error code if an error occurred.
1246+
* and a negative error code if not or if an error occurred.
12471247
*/
12481248
static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
12491249
{
@@ -1270,7 +1270,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
12701270
ubi_err("paranoid check failed for PEB %d", pnum);
12711271
ubi_dbg_dump_vid_hdr(vid_hdr);
12721272
ubi_dbg_dump_stack();
1273-
err = 1;
1273+
err = -EINVAL;
12741274
goto exit;
12751275
}
12761276

@@ -1289,8 +1289,8 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
12891289
* @len: the length of the region to check
12901290
*
12911291
* This function returns zero if only 0xFF bytes are present at offset
1292-
* @offset of the physical eraseblock @pnum, %1 if not, and a negative error
1293-
* code if an error occurred.
1292+
* @offset of the physical eraseblock @pnum, and a negative error code if not
1293+
* or if an error occurred.
12941294
*/
12951295
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
12961296
{
@@ -1321,7 +1321,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
13211321
ubi_msg("hex dump of the %d-%d region", offset, offset + len);
13221322
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
13231323
ubi->dbg_peb_buf, len, 1);
1324-
err = 1;
1324+
err = -EINVAL;
13251325
error:
13261326
ubi_dbg_dump_stack();
13271327
mutex_unlock(&ubi->dbg_buf_mutex);

‎drivers/mtd/ubi/scan.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
974974
seb->ec = si->mean_ec;
975975

976976
err = paranoid_check_si(ubi, si);
977-
if (err) {
978-
if (err > 0)
979-
err = -EINVAL;
977+
if (err)
980978
goto out_vidh;
981-
}
982979

983980
ubi_free_vid_hdr(ubi, vidh);
984981
kfree(ech);
@@ -1086,8 +1083,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
10861083
* @ubi: UBI device description object
10871084
* @si: scanning information
10881085
*
1089-
* This function returns zero if the scanning information is all right, %1 if
1090-
* not and a negative error code if an error occurred.
1086+
* This function returns zero if the scanning information is all right, and a
1087+
* negative error code if not or if an error occurred.
10911088
*/
10921089
static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
10931090
{
@@ -1346,7 +1343,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
13461343

13471344
out:
13481345
ubi_dbg_dump_stack();
1349-
return 1;
1346+
return -EINVAL;
13501347
}
13511348

13521349
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */

‎drivers/mtd/ubi/wl.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ int ubi_wl_get_peb(struct ubi_device *ubi, int dtype)
464464
ubi->peb_size - ubi->vid_hdr_aloffset);
465465
if (err) {
466466
ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum);
467-
return err > 0 ? -EINVAL : err;
467+
return err;
468468
}
469469

470470
return e->pnum;
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
513513
dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec);
514514

515515
err = paranoid_check_ec(ubi, e->pnum, e->ec);
516-
if (err > 0)
516+
if (err)
517517
return -EINVAL;
518518

519519
ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi)
15721572
* @ec: the erase counter to check
15731573
*
15741574
* This function returns zero if the erase counter of physical eraseblock @pnum
1575-
* is equivalent to @ec, %1 if not, and a negative error code if an error
1576-
* occurred.
1575+
* is equivalent to @ec, and a negative error code if not or if an error occurred.
15771576
*/
15781577
static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
15791578
{
@@ -1611,8 +1610,8 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
16111610
* @e: the wear-leveling entry to check
16121611
* @root: the root of the tree
16131612
*
1614-
* This function returns zero if @e is in the @root RB-tree and %1 if it is
1615-
* not.
1613+
* This function returns zero if @e is in the @root RB-tree and %-EINVAL if it
1614+
* is not.
16161615
*/
16171616
static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
16181617
struct rb_root *root)
@@ -1623,7 +1622,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
16231622
ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ",
16241623
e->pnum, e->ec, root);
16251624
ubi_dbg_dump_stack();
1626-
return 1;
1625+
return -EINVAL;
16271626
}
16281627

16291628
/**
@@ -1632,7 +1631,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
16321631
* @ubi: UBI device description object
16331632
* @e: the wear-leveling entry to check
16341633
*
1635-
* This function returns zero if @e is in @ubi->pq and %1 if it is not.
1634+
* This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not.
16361635
*/
16371636
static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
16381637
{
@@ -1647,6 +1646,6 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
16471646
ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue",
16481647
e->pnum, e->ec);
16491648
ubi_dbg_dump_stack();
1650-
return 1;
1649+
return -EINVAL;
16511650
}
16521651
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */

0 commit comments

Comments
 (0)