diff options
author | James Bottomley <James.Bottomley@suse.de> | 2009-11-03 13:33:07 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2010-01-18 11:48:05 -0500 |
commit | e3deec090558d5cb5ffdc574e5560f3ed9723394 (patch) | |
tree | c76a5e26a3e08598ada0a2de34adcdf714aa7168 /drivers/scsi/sd.c | |
parent | 534ef056db8a8fb6b9d50188d88ed5d1fbc66673 (diff) |
[SCSI] eliminate potential kmalloc failure in scsi_get_vpd_page()
The best way to fix this is to eliminate the intenal kmalloc() and
make the caller allocate the required amount of storage.
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 255da53e5a01..c5e9a99d4066 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1946,13 +1946,13 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) | |||
1946 | { | 1946 | { |
1947 | struct request_queue *q = sdkp->disk->queue; | 1947 | struct request_queue *q = sdkp->disk->queue; |
1948 | unsigned int sector_sz = sdkp->device->sector_size; | 1948 | unsigned int sector_sz = sdkp->device->sector_size; |
1949 | char *buffer; | 1949 | const int vpd_len = 32; |
1950 | unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL); | ||
1950 | 1951 | ||
1951 | /* Block Limits VPD */ | 1952 | if (!buffer || |
1952 | buffer = scsi_get_vpd_page(sdkp->device, 0xb0); | 1953 | /* Block Limits VPD */ |
1953 | 1954 | scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len)) | |
1954 | if (buffer == NULL) | 1955 | goto out; |
1955 | return; | ||
1956 | 1956 | ||
1957 | blk_queue_io_min(sdkp->disk->queue, | 1957 | blk_queue_io_min(sdkp->disk->queue, |
1958 | get_unaligned_be16(&buffer[6]) * sector_sz); | 1958 | get_unaligned_be16(&buffer[6]) * sector_sz); |
@@ -1984,6 +1984,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) | |||
1984 | get_unaligned_be32(&buffer[32]) & ~(1 << 31); | 1984 | get_unaligned_be32(&buffer[32]) & ~(1 << 31); |
1985 | } | 1985 | } |
1986 | 1986 | ||
1987 | out: | ||
1987 | kfree(buffer); | 1988 | kfree(buffer); |
1988 | } | 1989 | } |
1989 | 1990 | ||
@@ -1993,20 +1994,23 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) | |||
1993 | */ | 1994 | */ |
1994 | static void sd_read_block_characteristics(struct scsi_disk *sdkp) | 1995 | static void sd_read_block_characteristics(struct scsi_disk *sdkp) |
1995 | { | 1996 | { |
1996 | char *buffer; | 1997 | unsigned char *buffer; |
1997 | u16 rot; | 1998 | u16 rot; |
1999 | const int vpd_len = 32; | ||
1998 | 2000 | ||
1999 | /* Block Device Characteristics VPD */ | 2001 | buffer = kmalloc(vpd_len, GFP_KERNEL); |
2000 | buffer = scsi_get_vpd_page(sdkp->device, 0xb1); | ||
2001 | 2002 | ||
2002 | if (buffer == NULL) | 2003 | if (!buffer || |
2003 | return; | 2004 | /* Block Device Characteristics VPD */ |
2005 | scsi_get_vpd_page(sdkp->device, 0xb1, buffer, vpd_len)) | ||
2006 | goto out; | ||
2004 | 2007 | ||
2005 | rot = get_unaligned_be16(&buffer[4]); | 2008 | rot = get_unaligned_be16(&buffer[4]); |
2006 | 2009 | ||
2007 | if (rot == 1) | 2010 | if (rot == 1) |
2008 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, sdkp->disk->queue); | 2011 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, sdkp->disk->queue); |
2009 | 2012 | ||
2013 | out: | ||
2010 | kfree(buffer); | 2014 | kfree(buffer); |
2011 | } | 2015 | } |
2012 | 2016 | ||