Skip to content

Commit

Permalink
Staging: unisys: Replace kmalloc/memset with kzalloc
Browse files Browse the repository at this point in the history
This patch solves the Coccinelle warning: "kzalloc should be used instead of
kmalloc/memset".

Signed-off-by: Andreea-Cristina Bernat <bernat.ada@gmail.com>
Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
  • Loading branch information
Andreea-Cristina Bernat authored and Peter P Waskiewicz Jr committed Mar 17, 2014
1 parent ac0ba3f commit 97a84f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions drivers/staging/unisys/virthba/virthba.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,12 +1060,12 @@ virthba_slave_alloc(struct scsi_device *scsidev)
(vdisk->next->lun == scsidev->lun))
return 0;
}
tmpvdisk = kmalloc(sizeof(struct virtdisk_info), GFP_ATOMIC);
tmpvdisk = kzalloc(sizeof(struct virtdisk_info), GFP_ATOMIC);
if (!tmpvdisk) { /* error allocating */
LOGERR("Could not allocate memory for disk\n");
return 0;
}
memset(tmpvdisk, 0, sizeof(struct virtdisk_info));

tmpvdisk->channel = scsidev->channel;
tmpvdisk->id = scsidev->id;
tmpvdisk->lun = scsidev->lun;
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/unisys/virtpci/virtpci.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,15 +909,13 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
}

/* add a Virtual Device */
virtpcidev = kmalloc(sizeof(struct virtpci_dev), GFP_ATOMIC);
virtpcidev = kzalloc(sizeof(struct virtpci_dev), GFP_ATOMIC);
if (virtpcidev == NULL) {
LOGERR("can't add device - malloc FALLED\n");
POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
return 0;
}

memset(virtpcidev, 0, sizeof(struct virtpci_dev));

/* initialize stuff unique to virtpci_dev struct */
virtpcidev->devtype = devtype;
if (devtype == VIRTHBA_TYPE) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/unisys/visorchipset/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ parser_init_guts(U64 addr, U32 bytes, BOOL isLocal,
*tryAgain = TRUE;
RETPTR(NULL);
}
ctx = kmalloc(allocbytes, GFP_KERNEL|__GFP_NORETRY);
ctx = kzalloc(allocbytes, GFP_KERNEL|__GFP_NORETRY);
if (ctx == NULL) {
ERRDRV("%s (%s:%d) - failed to allocate %d bytes",
__func__, __FILE__, __LINE__, allocbytes);
if (tryAgain)
*tryAgain = TRUE;
RETPTR(NULL);
}
memset(ctx, 0, allocbytes);

ctx->allocbytes = allocbytes;
ctx->param_bytes = bytes;
ctx->curr = NULL;
Expand Down
9 changes: 4 additions & 5 deletions drivers/staging/unisys/visorchipset/visorchipset_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,16 +1081,15 @@ bus_create(CONTROLVM_MESSAGE *inmsg)
POSTCODE_SEVERITY_ERR);
RETINT(-CONTROLVM_RESP_ERROR_ALREADY_DONE);
}
pBusInfo = kmalloc(sizeof(VISORCHIPSET_BUS_INFO), GFP_KERNEL);
pBusInfo = kzalloc(sizeof(VISORCHIPSET_BUS_INFO), GFP_KERNEL);
if (pBusInfo == NULL) {
LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kmalloc failed",
LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kzalloc failed",
busNo);
POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo,
POSTCODE_SEVERITY_ERR);
RETINT(-CONTROLVM_RESP_ERROR_KMALLOC_FAILED);
}

memset(pBusInfo, 0, sizeof(VISORCHIPSET_BUS_INFO));
INIT_LIST_HEAD(&pBusInfo->entry);
pBusInfo->busNo = busNo;
pBusInfo->devNo = cmd->createBus.deviceCount;
Expand Down Expand Up @@ -1231,15 +1230,15 @@ my_device_create(CONTROLVM_MESSAGE *inmsg)
POSTCODE_SEVERITY_ERR);
RETINT(-CONTROLVM_RESP_ERROR_BUS_INVALID);
}
pDevInfo = kmalloc(sizeof(VISORCHIPSET_DEVICE_INFO), GFP_KERNEL);
pDevInfo = kzalloc(sizeof(VISORCHIPSET_DEVICE_INFO), GFP_KERNEL);
if (pDevInfo == NULL) {
LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu kmaloc failed",
busNo, devNo);
POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
POSTCODE_SEVERITY_ERR);
RETINT(-CONTROLVM_RESP_ERROR_KMALLOC_FAILED);
}
memset(pDevInfo, 0, sizeof(VISORCHIPSET_DEVICE_INFO));

INIT_LIST_HEAD(&pDevInfo->entry);
pDevInfo->busNo = busNo;
pDevInfo->devNo = devNo;
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/unisys/visorutil/memregion_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ visor_memregion_create_overlapped(MEMREGION *parent, ulong offset, ulong nbytes)
__func__, offset, nbytes);
return NULL;
}
memregion = kmalloc(sizeof(MEMREGION), GFP_KERNEL|__GFP_NORETRY);
memregion = kzalloc(sizeof(MEMREGION), GFP_KERNEL|__GFP_NORETRY);
if (memregion == NULL) {
ERRDRV("%s allocation failed", __func__);
return NULL;
}
memset(memregion, 0, sizeof(MEMREGION));

memregion->physaddr = parent->physaddr + offset;
memregion->nbytes = nbytes;
memregion->mapped = ((u8 *) (parent->mapped)) + offset;
Expand Down

0 comments on commit 97a84f1

Please sign in to comment.