Skip to content

Commit

Permalink
[MTD] slram: Handle negative devlength correctly
Browse files Browse the repository at this point in the history
A negative devlength won't get noticed and clean up:

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Roel Kluin authored and David Woodhouse committed Jan 19, 2009
1 parent 5f87760 commit 3afd522
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/mtd/devices/slram.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,28 @@ static int parse_cmdline(char *devname, char *szstart, char *szlength)
if (*(szlength) != '+') {
devlength = simple_strtoul(szlength, &buffer, 0);
devlength = handle_unit(devlength, buffer) - devstart;
if (devlength < devstart)
goto err_out;

devlength -= devstart;
} else {
devlength = simple_strtoul(szlength + 1, &buffer, 0);
devlength = handle_unit(devlength, buffer);
}
T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
devname, devstart, devlength);
if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
E("slram: Illegal start / length parameter.\n");
return(-EINVAL);
}
if (devlength % SLRAM_BLK_SZ != 0)
goto err_out;

if ((devstart = register_device(devname, devstart, devlength))){
unregister_devices();
return((int)devstart);
}
return(0);

err_out:
E("slram: Illegal length parameter.\n");
return(-EINVAL);
}

#ifndef MODULE
Expand Down

0 comments on commit 3afd522

Please sign in to comment.