Skip to content

Commit

Permalink
ide: fix memleak on failure in probe_for_drive()
Browse files Browse the repository at this point in the history
Always free drive->id in probe_for_drive() if device is not present.

While at it:
- remove dead IDE_DFLAG_DEAD flag
- remove superfluous IDE_DFLAG_PRESENT check

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  • Loading branch information
Bartlomiej Zolnierkiewicz committed Mar 27, 2009
1 parent 304ffd6 commit 69197ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 9 additions & 13 deletions drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,9 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
m[ATA_ID_PROD_LEN - 1] = '\0';

if (strstr(m, "E X A B Y T E N E S T"))
goto err_misc;

drive->dev_flags |= IDE_DFLAG_PRESENT;
drive->dev_flags &= ~IDE_DFLAG_DEAD;

return;
err_misc:
kfree(id);
drive->dev_flags &= ~IDE_DFLAG_PRESENT;
drive->dev_flags &= ~IDE_DFLAG_PRESENT;
else
drive->dev_flags |= IDE_DFLAG_PRESENT;
}

/**
Expand Down Expand Up @@ -505,8 +499,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
}

if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
/* drive not found */
return 0;
goto out_free;

/* identification failed? */
if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
Expand All @@ -530,7 +523,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
}

if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
return 0;
goto out_free;

/* The drive wasn't being helpful. Add generic info only */
if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
Expand All @@ -543,7 +536,10 @@ static u8 probe_for_drive(ide_drive_t *drive)
ide_disk_init_mult_count(drive);
}

return !!(drive->dev_flags & IDE_DFLAG_PRESENT);
return 1;
out_free:
kfree(drive->id);
return 0;
}

static void hwif_release_dev(struct device *dev)
Expand Down
2 changes: 0 additions & 2 deletions include/linux/ide.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ enum {
IDE_DFLAG_NICE1 = (1 << 5),
/* device is physically present */
IDE_DFLAG_PRESENT = (1 << 6),
/* device ejected hint */
IDE_DFLAG_DEAD = (1 << 7),
/* id read from device (synthetic if not set) */
IDE_DFLAG_ID_READ = (1 << 8),
IDE_DFLAG_NOPROBE = (1 << 9),
Expand Down

0 comments on commit 69197ad

Please sign in to comment.