mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
scsi: sr: Add memory allocation failure handling for get_capabilities()
The function get_capabilities() has the possibility of failing to allocate the transfer buffer but it does not currently handle this. This may lead to exceptions when accessing the buffer. Add error handling when memory allocation fails. Link: https://lore.kernel.org/r/20220427025647.298358-1-lienze@kylinos.cn Signed-off-by: Enze Li <lienze@kylinos.cn> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
parent
bb9b9eb0ae
commit
ebc95c7906
@ -113,7 +113,7 @@ static int sr_open(struct cdrom_device_info *, int);
|
||||
static void sr_release(struct cdrom_device_info *);
|
||||
|
||||
static void get_sectorsize(struct scsi_cd *);
|
||||
static void get_capabilities(struct scsi_cd *);
|
||||
static int get_capabilities(struct scsi_cd *);
|
||||
|
||||
static unsigned int sr_check_events(struct cdrom_device_info *cdi,
|
||||
unsigned int clearing, int slot);
|
||||
@ -669,8 +669,9 @@ static int sr_probe(struct device *dev)
|
||||
|
||||
sdev->sector_size = 2048; /* A guess, just in case */
|
||||
|
||||
/* FIXME: need to handle a get_capabilities failure properly ?? */
|
||||
get_capabilities(cd);
|
||||
error = -ENOMEM;
|
||||
if (get_capabilities(cd))
|
||||
goto fail_minor;
|
||||
sr_vendor_init(cd);
|
||||
|
||||
set_capacity(disk, cd->capacity);
|
||||
@ -794,7 +795,7 @@ static void get_sectorsize(struct scsi_cd *cd)
|
||||
return;
|
||||
}
|
||||
|
||||
static void get_capabilities(struct scsi_cd *cd)
|
||||
static int get_capabilities(struct scsi_cd *cd)
|
||||
{
|
||||
unsigned char *buffer;
|
||||
struct scsi_mode_data data;
|
||||
@ -819,7 +820,7 @@ static void get_capabilities(struct scsi_cd *cd)
|
||||
buffer = kmalloc(512, GFP_KERNEL);
|
||||
if (!buffer) {
|
||||
sr_printk(KERN_ERR, cd, "out of memory.\n");
|
||||
return;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* eat unit attentions */
|
||||
@ -839,7 +840,7 @@ static void get_capabilities(struct scsi_cd *cd)
|
||||
CDC_MRW | CDC_MRW_W | CDC_RAM);
|
||||
kfree(buffer);
|
||||
sr_printk(KERN_INFO, cd, "scsi-1 drive");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = data.header_length + data.block_descriptor_length;
|
||||
@ -898,6 +899,7 @@ static void get_capabilities(struct scsi_cd *cd)
|
||||
}
|
||||
|
||||
kfree(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user