mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-11-19 08:05:27 +08:00
[SCSI] SCSI core kmalloc2kzalloc
Change the core SCSI code to use kzalloc rather than kmalloc+memset where possible. Signed-off-by: Jes Sorensen <jes@sgi.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
This commit is contained in:
parent
b9a33cebac
commit
24669f75a3
@ -306,10 +306,9 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
|
||||
dump_stack();
|
||||
}
|
||||
|
||||
shost = kmalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask);
|
||||
shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask);
|
||||
if (!shost)
|
||||
return NULL;
|
||||
memset(shost, 0, sizeof(struct Scsi_Host) + privsize);
|
||||
|
||||
spin_lock_init(&shost->default_lock);
|
||||
scsi_assign_lock(shost, &shost->default_lock);
|
||||
|
@ -136,9 +136,8 @@ struct scsi_request *scsi_allocate_request(struct scsi_device *sdev,
|
||||
const int size = offset + sizeof(struct request);
|
||||
struct scsi_request *sreq;
|
||||
|
||||
sreq = kmalloc(size, gfp_mask);
|
||||
sreq = kzalloc(size, gfp_mask);
|
||||
if (likely(sreq != NULL)) {
|
||||
memset(sreq, 0, size);
|
||||
sreq->sr_request = (struct request *)(((char *)sreq) + offset);
|
||||
sreq->sr_device = sdev;
|
||||
sreq->sr_host = sdev->host;
|
||||
|
@ -1061,13 +1061,12 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
|
||||
}
|
||||
}
|
||||
if (NULL == open_devip) { /* try and make a new one */
|
||||
open_devip = kmalloc(sizeof(*open_devip),GFP_KERNEL);
|
||||
open_devip = kzalloc(sizeof(*open_devip),GFP_KERNEL);
|
||||
if (NULL == open_devip) {
|
||||
printk(KERN_ERR "%s: out of memory at line %d\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
memset(open_devip, 0, sizeof(*open_devip));
|
||||
open_devip->sdbg_host = sdbg_host;
|
||||
list_add_tail(&open_devip->dev_list,
|
||||
&sdbg_host->dev_info_list);
|
||||
@ -1814,7 +1813,7 @@ static int sdebug_add_adapter(void)
|
||||
struct sdebug_dev_info *sdbg_devinfo;
|
||||
struct list_head *lh, *lh_sf;
|
||||
|
||||
sdbg_host = kmalloc(sizeof(*sdbg_host),GFP_KERNEL);
|
||||
sdbg_host = kzalloc(sizeof(*sdbg_host), GFP_KERNEL);
|
||||
|
||||
if (NULL == sdbg_host) {
|
||||
printk(KERN_ERR "%s: out of memory at line %d\n",
|
||||
@ -1822,19 +1821,17 @@ static int sdebug_add_adapter(void)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(sdbg_host, 0, sizeof(*sdbg_host));
|
||||
INIT_LIST_HEAD(&sdbg_host->dev_info_list);
|
||||
|
||||
devs_per_host = scsi_debug_num_tgts * scsi_debug_max_luns;
|
||||
for (k = 0; k < devs_per_host; k++) {
|
||||
sdbg_devinfo = kmalloc(sizeof(*sdbg_devinfo),GFP_KERNEL);
|
||||
sdbg_devinfo = kzalloc(sizeof(*sdbg_devinfo), GFP_KERNEL);
|
||||
if (NULL == sdbg_devinfo) {
|
||||
printk(KERN_ERR "%s: out of memory at line %d\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
error = -ENOMEM;
|
||||
goto clean;
|
||||
}
|
||||
memset(sdbg_devinfo, 0, sizeof(*sdbg_devinfo));
|
||||
sdbg_devinfo->sdbg_host = sdbg_host;
|
||||
list_add_tail(&sdbg_devinfo->dev_list,
|
||||
&sdbg_host->dev_info_list);
|
||||
|
@ -241,10 +241,9 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
|
||||
buf_needed = (buf_needed + 511) & ~511;
|
||||
if (buf_needed > MAX_BUF)
|
||||
buf_needed = MAX_BUF;
|
||||
buf = kmalloc(buf_needed, gfp_mask);
|
||||
buf = kzalloc(buf_needed, gfp_mask);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
memset(buf, 0, buf_needed);
|
||||
if (inlen == 0) {
|
||||
data_direction = DMA_FROM_DEVICE;
|
||||
} else if (outlen == 0 ) {
|
||||
|
@ -286,13 +286,12 @@ int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
|
||||
int result;
|
||||
|
||||
if (sshdr) {
|
||||
sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
|
||||
sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
|
||||
if (!sense)
|
||||
return DRIVER_ERROR << 24;
|
||||
memset(sense, 0, SCSI_SENSE_BUFFERSIZE);
|
||||
}
|
||||
result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
|
||||
sense, timeout, retries, 0);
|
||||
sense, timeout, retries, 0);
|
||||
if (sshdr)
|
||||
scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr);
|
||||
|
||||
|
@ -205,12 +205,11 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
|
||||
int display_failure_msg = 1, ret;
|
||||
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
|
||||
|
||||
sdev = kmalloc(sizeof(*sdev) + shost->transportt->device_size,
|
||||
sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size,
|
||||
GFP_ATOMIC);
|
||||
if (!sdev)
|
||||
goto out;
|
||||
|
||||
memset(sdev, 0, sizeof(*sdev));
|
||||
sdev->vendor = scsi_null_device_strs;
|
||||
sdev->model = scsi_null_device_strs;
|
||||
sdev->rev = scsi_null_device_strs;
|
||||
@ -334,12 +333,11 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
|
||||
struct scsi_target *starget;
|
||||
struct scsi_target *found_target;
|
||||
|
||||
starget = kmalloc(size, GFP_KERNEL);
|
||||
starget = kzalloc(size, GFP_KERNEL);
|
||||
if (!starget) {
|
||||
printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
memset(starget, 0, size);
|
||||
dev = &starget->dev;
|
||||
device_initialize(dev);
|
||||
starget->reap_ref = 1;
|
||||
|
@ -1115,15 +1115,13 @@ static int fc_user_scan(struct Scsi_Host *shost, uint channel,
|
||||
struct scsi_transport_template *
|
||||
fc_attach_transport(struct fc_function_template *ft)
|
||||
{
|
||||
struct fc_internal *i = kmalloc(sizeof(struct fc_internal),
|
||||
GFP_KERNEL);
|
||||
int count;
|
||||
struct fc_internal *i = kzalloc(sizeof(struct fc_internal),
|
||||
GFP_KERNEL);
|
||||
|
||||
if (unlikely(!i))
|
||||
return NULL;
|
||||
|
||||
memset(i, 0, sizeof(struct fc_internal));
|
||||
|
||||
i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
|
||||
i->t.target_attrs.ac.class = &fc_transport_class.class;
|
||||
i->t.target_attrs.ac.match = fc_target_match;
|
||||
@ -1305,12 +1303,11 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
|
||||
size_t size;
|
||||
|
||||
size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
|
||||
rport = kmalloc(size, GFP_KERNEL);
|
||||
rport = kzalloc(size, GFP_KERNEL);
|
||||
if (unlikely(!rport)) {
|
||||
printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
memset(rport, 0, size);
|
||||
|
||||
rport->maxframe_size = -1;
|
||||
rport->supported_classes = FC_COS_UNSPECIFIED;
|
||||
|
@ -1117,10 +1117,9 @@ iscsi_register_transport(struct iscsi_transport *tt)
|
||||
if (priv)
|
||||
return NULL;
|
||||
|
||||
priv = kmalloc(sizeof(*priv), GFP_KERNEL);
|
||||
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return NULL;
|
||||
memset(priv, 0, sizeof(*priv));
|
||||
INIT_LIST_HEAD(&priv->list);
|
||||
priv->iscsi_transport = tt;
|
||||
|
||||
|
@ -391,10 +391,9 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
|
||||
struct Scsi_Host *shost = dev_to_shost(parent);
|
||||
struct sas_phy *phy;
|
||||
|
||||
phy = kmalloc(sizeof(*phy), GFP_KERNEL);
|
||||
phy = kzalloc(sizeof(*phy), GFP_KERNEL);
|
||||
if (!phy)
|
||||
return NULL;
|
||||
memset(phy, 0, sizeof(*phy));
|
||||
|
||||
get_device(parent);
|
||||
|
||||
@ -585,12 +584,11 @@ struct sas_rphy *sas_rphy_alloc(struct sas_phy *parent)
|
||||
struct Scsi_Host *shost = dev_to_shost(&parent->dev);
|
||||
struct sas_rphy *rphy;
|
||||
|
||||
rphy = kmalloc(sizeof(*rphy), GFP_KERNEL);
|
||||
rphy = kzalloc(sizeof(*rphy), GFP_KERNEL);
|
||||
if (!rphy) {
|
||||
put_device(&parent->dev);
|
||||
return NULL;
|
||||
}
|
||||
memset(rphy, 0, sizeof(*rphy));
|
||||
|
||||
device_initialize(&rphy->dev);
|
||||
rphy->dev.parent = get_device(&parent->dev);
|
||||
@ -793,10 +791,9 @@ sas_attach_transport(struct sas_function_template *ft)
|
||||
struct sas_internal *i;
|
||||
int count;
|
||||
|
||||
i = kmalloc(sizeof(struct sas_internal), GFP_KERNEL);
|
||||
i = kzalloc(sizeof(struct sas_internal), GFP_KERNEL);
|
||||
if (!i)
|
||||
return NULL;
|
||||
memset(i, 0, sizeof(struct sas_internal));
|
||||
|
||||
i->t.user_scan = sas_user_scan;
|
||||
|
||||
|
@ -900,13 +900,11 @@ spi_dv_device(struct scsi_device *sdev)
|
||||
if (unlikely(scsi_device_get(sdev)))
|
||||
return;
|
||||
|
||||
buffer = kmalloc(len, GFP_KERNEL);
|
||||
buffer = kzalloc(len, GFP_KERNEL);
|
||||
|
||||
if (unlikely(!buffer))
|
||||
goto out_put;
|
||||
|
||||
memset(buffer, 0, len);
|
||||
|
||||
/* We need to verify that the actual device will quiesce; the
|
||||
* later target quiesce is just a nice to have */
|
||||
if (unlikely(scsi_device_quiesce(sdev)))
|
||||
@ -1265,15 +1263,13 @@ static DECLARE_ANON_TRANSPORT_CLASS(spi_device_class,
|
||||
struct scsi_transport_template *
|
||||
spi_attach_transport(struct spi_function_template *ft)
|
||||
{
|
||||
struct spi_internal *i = kmalloc(sizeof(struct spi_internal),
|
||||
GFP_KERNEL);
|
||||
int count = 0;
|
||||
struct spi_internal *i = kzalloc(sizeof(struct spi_internal),
|
||||
GFP_KERNEL);
|
||||
|
||||
if (unlikely(!i))
|
||||
return NULL;
|
||||
|
||||
memset(i, 0, sizeof(struct spi_internal));
|
||||
|
||||
|
||||
i->t.target_attrs.ac.class = &spi_transport_class.class;
|
||||
i->t.target_attrs.ac.attrs = &i->attrs[0];
|
||||
i->t.target_attrs.ac.match = spi_target_match;
|
||||
|
@ -1517,11 +1517,10 @@ static int sd_probe(struct device *dev)
|
||||
"sd_attach\n"));
|
||||
|
||||
error = -ENOMEM;
|
||||
sdkp = kmalloc(sizeof(*sdkp), GFP_KERNEL);
|
||||
sdkp = kzalloc(sizeof(*sdkp), GFP_KERNEL);
|
||||
if (!sdkp)
|
||||
goto out;
|
||||
|
||||
memset (sdkp, 0, sizeof(*sdkp));
|
||||
kref_init(&sdkp->kref);
|
||||
|
||||
gd = alloc_disk(16);
|
||||
|
@ -1361,7 +1361,7 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
|
||||
void *old_sg_dev_arr = NULL;
|
||||
int k, error;
|
||||
|
||||
sdp = kmalloc(sizeof(Sg_device), GFP_KERNEL);
|
||||
sdp = kzalloc(sizeof(Sg_device), GFP_KERNEL);
|
||||
if (!sdp) {
|
||||
printk(KERN_WARNING "kmalloc Sg_device failure\n");
|
||||
return -ENOMEM;
|
||||
@ -1373,12 +1373,11 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
|
||||
int tmp_dev_max = sg_nr_dev + SG_DEV_ARR_LUMP;
|
||||
write_unlock_irqrestore(&sg_dev_arr_lock, iflags);
|
||||
|
||||
tmp_da = kmalloc(tmp_dev_max * sizeof(Sg_device *), GFP_KERNEL);
|
||||
tmp_da = kzalloc(tmp_dev_max * sizeof(Sg_device *), GFP_KERNEL);
|
||||
if (unlikely(!tmp_da))
|
||||
goto expand_failed;
|
||||
|
||||
write_lock_irqsave(&sg_dev_arr_lock, iflags);
|
||||
memset(tmp_da, 0, tmp_dev_max * sizeof(Sg_device *));
|
||||
memcpy(tmp_da, sg_dev_arr, sg_dev_max * sizeof(Sg_device *));
|
||||
old_sg_dev_arr = sg_dev_arr;
|
||||
sg_dev_arr = tmp_da;
|
||||
@ -1391,7 +1390,6 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
|
||||
if (unlikely(k >= SG_MAX_DEVS))
|
||||
goto overflow;
|
||||
|
||||
memset(sdp, 0, sizeof(*sdp));
|
||||
SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k));
|
||||
sprintf(disk->disk_name, "sg%d", k);
|
||||
disk->first_minor = k;
|
||||
|
@ -525,10 +525,9 @@ static int sr_probe(struct device *dev)
|
||||
goto fail;
|
||||
|
||||
error = -ENOMEM;
|
||||
cd = kmalloc(sizeof(*cd), GFP_KERNEL);
|
||||
cd = kzalloc(sizeof(*cd), GFP_KERNEL);
|
||||
if (!cd)
|
||||
goto fail;
|
||||
memset(cd, 0, sizeof(*cd));
|
||||
|
||||
kref_init(&cd->kref);
|
||||
|
||||
|
@ -44,11 +44,10 @@ static int sr_read_tochdr(struct cdrom_device_info *cdi,
|
||||
int result;
|
||||
unsigned char *buffer;
|
||||
|
||||
buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
||||
buffer = kzalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(&cgc, 0, sizeof(struct packet_command));
|
||||
cgc.timeout = IOCTL_TIMEOUT;
|
||||
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
||||
cgc.cmd[8] = 12; /* LSB of length */
|
||||
@ -74,11 +73,10 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi,
|
||||
int result;
|
||||
unsigned char *buffer;
|
||||
|
||||
buffer = kmalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
||||
buffer = kzalloc(32, GFP_KERNEL | SR_GFP_DMA(cd));
|
||||
if (!buffer)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(&cgc, 0, sizeof(struct packet_command));
|
||||
cgc.timeout = IOCTL_TIMEOUT;
|
||||
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
||||
cgc.cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
|
||||
|
@ -3590,12 +3590,11 @@ static struct st_buffer *
|
||||
|
||||
i = sizeof(struct st_buffer) + (max_sg - 1) * sizeof(struct scatterlist) +
|
||||
max_sg * sizeof(struct st_buf_fragment);
|
||||
tb = kmalloc(i, priority);
|
||||
tb = kzalloc(i, priority);
|
||||
if (!tb) {
|
||||
printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(tb, 0, i);
|
||||
tb->frp_segs = tb->orig_frp_segs = 0;
|
||||
tb->use_sg = max_sg;
|
||||
tb->frp = (struct st_buf_fragment *)(&(tb->sg[0]) + max_sg);
|
||||
@ -3924,14 +3923,13 @@ static int st_probe(struct device *dev)
|
||||
goto out_put_disk;
|
||||
}
|
||||
|
||||
tmp_da = kmalloc(tmp_dev_max * sizeof(struct scsi_tape *), GFP_ATOMIC);
|
||||
tmp_da = kzalloc(tmp_dev_max * sizeof(struct scsi_tape *), GFP_ATOMIC);
|
||||
if (tmp_da == NULL) {
|
||||
write_unlock(&st_dev_arr_lock);
|
||||
printk(KERN_ERR "st: Can't extend device array.\n");
|
||||
goto out_put_disk;
|
||||
}
|
||||
|
||||
memset(tmp_da, 0, tmp_dev_max * sizeof(struct scsi_tape *));
|
||||
if (scsi_tapes != NULL) {
|
||||
memcpy(tmp_da, scsi_tapes,
|
||||
st_dev_max * sizeof(struct scsi_tape *));
|
||||
@ -3948,13 +3946,12 @@ static int st_probe(struct device *dev)
|
||||
if (i >= st_dev_max)
|
||||
panic("scsi_devices corrupt (st)");
|
||||
|
||||
tpnt = kmalloc(sizeof(struct scsi_tape), GFP_ATOMIC);
|
||||
tpnt = kzalloc(sizeof(struct scsi_tape), GFP_ATOMIC);
|
||||
if (tpnt == NULL) {
|
||||
write_unlock(&st_dev_arr_lock);
|
||||
printk(KERN_ERR "st: Can't allocate device descriptor.\n");
|
||||
goto out_put_disk;
|
||||
}
|
||||
memset(tpnt, 0, sizeof(struct scsi_tape));
|
||||
kref_init(&tpnt->kref);
|
||||
tpnt->disk = disk;
|
||||
sprintf(disk->disk_name, "st%d", i);
|
||||
|
Loading…
Reference in New Issue
Block a user