Skip to content

Commit

Permalink
blk: fix wrong idr_pre_get() error check in loop.c
Browse files Browse the repository at this point in the history
The idr_pre_get() function never returns a value < 0.  It returns 0 (no
memory) or 1 (OK).

Reported-by: Silva Paulo <psdasilva@yahoo.com>
[ Rewrote Silva's patch, but attributing it to Silva anyway  - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Silva Paulo authored and torvalds committed Jul 14, 2012
1 parent 1daaa5e commit 68d740d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/block/loop.c
Expand Up @@ -1597,14 +1597,12 @@ static int loop_add(struct loop_device **l, int i)
struct gendisk *disk;
int err;

err = -ENOMEM;
lo = kzalloc(sizeof(*lo), GFP_KERNEL);
if (!lo) {
err = -ENOMEM;
if (!lo)
goto out;
}

err = idr_pre_get(&loop_index_idr, GFP_KERNEL);
if (err < 0)
if (!idr_pre_get(&loop_index_idr, GFP_KERNEL))
goto out_free_dev;

if (i >= 0) {
Expand Down

0 comments on commit 68d740d

Please sign in to comment.