Skip to content

Commit

Permalink
UBI: fix IS_ERR test
Browse files Browse the repository at this point in the history
In case of error, the function add_volume returns an ERR pointer. The
result of IS_ERR, which is supposed to be used in a test as it is, is
here checked to be less than zero, which seems odd. We suggest to
replace this test by a simple IS_ERR test.

A simplified version of the semantic match that finds this problem is
as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@def0@
expression x;
position p0;
@@
x@p0 = add_volume(...)

@protected@
expression def0.x,E;
position def0.p0;
position p;
statement S;
@@
x@p0
... when != x = E
if (!IS_ERR(x) && ...) {<... x@p ...>} else S

@unprotected@
expression def0.x,E;
identifier fld;
position def0.p0;
position p != protected.p;
@@
x@p0
... when != x = E
* x@p->fld
// </smpl>

Signed-off-by:  Julien Brunel <brunel@diku.dk>
Signed-off-by:  Julia Lawall <julia@diku.dk>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
  • Loading branch information
Julien Brunel authored and Artem Bityutskiy committed Sep 26, 2008
1 parent 7d200e8 commit 0e4a008
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/mtd/ubi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
pnum, vol_id, lnum, ec, sqnum, bitflips);

sv = add_volume(si, vol_id, pnum, vid_hdr);
if (IS_ERR(sv) < 0)
if (IS_ERR(sv))
return PTR_ERR(sv);

if (si->max_sqnum < sqnum)
Expand Down

0 comments on commit 0e4a008

Please sign in to comment.