From 97660957fb5318d76a680a1b6cfb7b998bfa3723 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 11:10:07 +0200 Subject: vme: tsi148: Delete nine error messages for a failed memory allocation Omit extra messages for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'drivers/vme/bridges/vme_tsi148.c') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index fc1b634b969a..fb91fddc6312 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -751,8 +751,6 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, if (image->bus_resource.name == NULL) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); if (image->bus_resource.name == NULL) { - dev_err(tsi148_bridge->parent, "Unable to allocate " - "memory for resource name\n"); retval = -ENOMEM; goto err_name; } @@ -1643,8 +1641,6 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(struct tsi148_dma_entry), GFP_KERNEL); if (entry == NULL) { - dev_err(tsi148_bridge->parent, "Failed to allocate memory for " - "dma resource structure\n"); retval = -ENOMEM; goto err_mem; } @@ -2296,8 +2292,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) */ tsi148_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); if (tsi148_bridge == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_struct; } @@ -2305,8 +2299,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device = kzalloc(sizeof(struct tsi148_driver), GFP_KERNEL); if (tsi148_device == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for device " - "structure\n"); retval = -ENOMEM; goto err_driver; } @@ -2373,8 +2365,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image = kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); if (tsi148_device->flush_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "flush resource structure\n"); retval = -ENOMEM; goto err_master; } @@ -2392,8 +2382,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) master_image = kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); if (master_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "master resource structure\n"); retval = -ENOMEM; goto err_master; } @@ -2421,8 +2409,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) slave_image = kmalloc(sizeof(struct vme_slave_resource), GFP_KERNEL); if (slave_image == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "slave resource structure\n"); retval = -ENOMEM; goto err_slave; } @@ -2445,8 +2431,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), GFP_KERNEL); if (dma_ctrlr == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "dma resource structure\n"); retval = -ENOMEM; goto err_dma; } @@ -2467,8 +2451,6 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); if (lm == NULL) { - dev_err(&pdev->dev, "Failed to allocate memory for " - "location monitor resource structure\n"); retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3 From 6d011dd876cb825b2e1213daaabda07e1151fc6a Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 11:55:03 +0200 Subject: vme: tsi148: Improve 17 size determinations Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring [martyn@welchs.me.uk: Correct long line] Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'drivers/vme/bridges/vme_tsi148.c') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index fb91fddc6312..946f62597360 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -741,7 +741,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, image->kern_base = NULL; kfree(image->bus_resource.name); release_resource(&image->bus_resource); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } /* Exit here if size is zero */ @@ -788,7 +788,7 @@ err_remap: release_resource(&image->bus_resource); err_resource: kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); err_name: return retval; } @@ -802,7 +802,7 @@ static void tsi148_free_resource(struct vme_master_resource *image) image->kern_base = NULL; release_resource(&image->bus_resource); kfree(image->bus_resource.name); - memset(&image->bus_resource, 0, sizeof(struct resource)); + memset(&image->bus_resource, 0, sizeof(image->bus_resource)); } /* @@ -1639,7 +1639,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, tsi148_bridge = list->parent->parent; /* Descriptor must be aligned on 64-bit boundaries */ - entry = kmalloc(sizeof(struct tsi148_dma_entry), GFP_KERNEL); + entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (entry == NULL) { retval = -ENOMEM; goto err_mem; @@ -1657,7 +1657,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Given we are going to fill out the structure, we probably don't * need to zero it, but better safe than sorry for now. */ - memset(&entry->descriptor, 0, sizeof(struct tsi148_dma_descriptor)); + memset(&entry->descriptor, 0, sizeof(entry->descriptor)); /* Fill out source part */ switch (src->type) { @@ -1752,8 +1752,9 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, list_add_tail(&entry->list, &list->entries); entry->dma_handle = dma_map_single(tsi148_bridge->parent, - &entry->descriptor, - sizeof(struct tsi148_dma_descriptor), DMA_TO_DEVICE); + &entry->descriptor, + sizeof(entry->descriptor), + DMA_TO_DEVICE); if (dma_mapping_error(tsi148_bridge->parent, entry->dma_handle)) { dev_err(tsi148_bridge->parent, "DMA mapping error\n"); retval = -EINVAL; @@ -2290,14 +2291,14 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* If we want to support more than one of each bridge, we need to * dynamically generate this so we get one per device */ - tsi148_bridge = kzalloc(sizeof(struct vme_bridge), GFP_KERNEL); + tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL); if (tsi148_bridge == NULL) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(tsi148_bridge); - tsi148_device = kzalloc(sizeof(struct tsi148_driver), GFP_KERNEL); + tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL); if (tsi148_device == NULL) { retval = -ENOMEM; goto err_driver; @@ -2363,7 +2364,8 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) master_num--; tsi148_device->flush_image = - kmalloc(sizeof(struct vme_master_resource), GFP_KERNEL); + kmalloc(sizeof(*tsi148_device->flush_image), + GFP_KERNEL); if (tsi148_device->flush_image == NULL) { retval = -ENOMEM; goto err_master; @@ -2373,14 +2375,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image->locked = 1; tsi148_device->flush_image->number = master_num; memset(&tsi148_device->flush_image->bus_resource, 0, - sizeof(struct resource)); + sizeof(tsi148_device->flush_image->bus_resource)); tsi148_device->flush_image->kern_base = NULL; } /* Add master windows to list */ for (i = 0; i < master_num; i++) { - master_image = kmalloc(sizeof(struct vme_master_resource), - GFP_KERNEL); + master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); if (master_image == NULL) { retval = -ENOMEM; goto err_master; @@ -2398,7 +2399,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) VME_PROG | VME_DATA; master_image->width_attr = VME_D16 | VME_D32; memset(&master_image->bus_resource, 0, - sizeof(struct resource)); + sizeof(master_image->bus_resource)); master_image->kern_base = NULL; list_add_tail(&master_image->list, &tsi148_bridge->master_resources); @@ -2406,8 +2407,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < TSI148_MAX_SLAVE; i++) { - slave_image = kmalloc(sizeof(struct vme_slave_resource), - GFP_KERNEL); + slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); if (slave_image == NULL) { retval = -ENOMEM; goto err_slave; @@ -2428,8 +2428,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < TSI148_MAX_DMA; i++) { - dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), - GFP_KERNEL); + dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); if (dma_ctrlr == NULL) { retval = -ENOMEM; goto err_dma; @@ -2449,7 +2448,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) } /* Add location monitor to list */ - lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); + lm = kmalloc(sizeof(*lm), GFP_KERNEL); if (lm == NULL) { retval = -ENOMEM; goto err_lm; -- cgit v1.2.3 From a75dc630086a6b83d780a7b27d03c4c0abdf0807 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 25 Aug 2017 12:00:17 +0200 Subject: vme: tsi148: Adjust 14 checks for null pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The script “checkpatch.pl” pointed information out like the following. Comparison to NULL could be written … Thus fix the affected source code places. Signed-off-by: Markus Elfring Signed-off-by: Martyn Welch --- drivers/vme/bridges/vme_tsi148.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'drivers/vme/bridges/vme_tsi148.c') diff --git a/drivers/vme/bridges/vme_tsi148.c b/drivers/vme/bridges/vme_tsi148.c index 946f62597360..647d231d4422 100644 --- a/drivers/vme/bridges/vme_tsi148.c +++ b/drivers/vme/bridges/vme_tsi148.c @@ -748,9 +748,9 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, if (size == 0) return 0; - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { image->bus_resource.name = kmalloc(VMENAMSIZ+3, GFP_ATOMIC); - if (image->bus_resource.name == NULL) { + if (!image->bus_resource.name) { retval = -ENOMEM; goto err_name; } @@ -776,7 +776,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image, image->kern_base = ioremap_nocache( image->bus_resource.start, size); - if (image->kern_base == NULL) { + if (!image->kern_base) { dev_err(tsi148_bridge->parent, "Failed to remap resource\n"); retval = -ENOMEM; goto err_remap; @@ -1640,7 +1640,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list, /* Descriptor must be aligned on 64-bit boundaries */ entry = kmalloc(sizeof(*entry), GFP_KERNEL); - if (entry == NULL) { + if (!entry) { retval = -ENOMEM; goto err_mem; } @@ -1943,7 +1943,7 @@ static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, /* If we already have a callback attached, we can't move it! */ for (i = 0; i < lm->monitors; i++) { - if (bridge->lm_callback[i] != NULL) { + if (bridge->lm_callback[i]) { mutex_unlock(&lm->mtx); dev_err(tsi148_bridge->parent, "Location monitor " "callback attached, can't reset\n"); @@ -2068,7 +2068,7 @@ static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor, } /* Check that a callback isn't already attached */ - if (bridge->lm_callback[monitor] != NULL) { + if (bridge->lm_callback[monitor]) { mutex_unlock(&lm->mtx); dev_err(tsi148_bridge->parent, "Existing callback attached\n"); return -EBUSY; @@ -2205,7 +2205,7 @@ static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge, /* Allocate mem for CR/CSR image */ bridge->crcsr_kernel = pci_zalloc_consistent(pdev, VME_CRCSR_BUF_SIZE, &bridge->crcsr_bus); - if (bridge->crcsr_kernel == NULL) { + if (!bridge->crcsr_kernel) { dev_err(tsi148_bridge->parent, "Failed to allocate memory for " "CR/CSR image\n"); return -ENOMEM; @@ -2292,14 +2292,14 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) * dynamically generate this so we get one per device */ tsi148_bridge = kzalloc(sizeof(*tsi148_bridge), GFP_KERNEL); - if (tsi148_bridge == NULL) { + if (!tsi148_bridge) { retval = -ENOMEM; goto err_struct; } vme_init_bridge(tsi148_bridge); tsi148_device = kzalloc(sizeof(*tsi148_device), GFP_KERNEL); - if (tsi148_device == NULL) { + if (!tsi148_device) { retval = -ENOMEM; goto err_driver; } @@ -2366,7 +2366,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) tsi148_device->flush_image = kmalloc(sizeof(*tsi148_device->flush_image), GFP_KERNEL); - if (tsi148_device->flush_image == NULL) { + if (!tsi148_device->flush_image) { retval = -ENOMEM; goto err_master; } @@ -2382,7 +2382,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add master windows to list */ for (i = 0; i < master_num; i++) { master_image = kmalloc(sizeof(*master_image), GFP_KERNEL); - if (master_image == NULL) { + if (!master_image) { retval = -ENOMEM; goto err_master; } @@ -2408,7 +2408,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add slave windows to list */ for (i = 0; i < TSI148_MAX_SLAVE; i++) { slave_image = kmalloc(sizeof(*slave_image), GFP_KERNEL); - if (slave_image == NULL) { + if (!slave_image) { retval = -ENOMEM; goto err_slave; } @@ -2429,7 +2429,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add dma engines to list */ for (i = 0; i < TSI148_MAX_DMA; i++) { dma_ctrlr = kmalloc(sizeof(*dma_ctrlr), GFP_KERNEL); - if (dma_ctrlr == NULL) { + if (!dma_ctrlr) { retval = -ENOMEM; goto err_dma; } @@ -2449,7 +2449,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id) /* Add location monitor to list */ lm = kmalloc(sizeof(*lm), GFP_KERNEL); - if (lm == NULL) { + if (!lm) { retval = -ENOMEM; goto err_lm; } -- cgit v1.2.3