2013-09-19 22:01:30

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 0/2] Cocci spatch "kzalloc-simple" - v3.11-7547-g44598f9

Use kzalloc rather than kmalloc followed by memset with 0.
Found by coccinelle spatch "api/alloc/kzalloc-simple.cocci"

Run against version v3.11-7547-g44598f9

Let me know when you as a maintainer are not interested in these kind of patches.
I can exclude you by path; all cocci findings in e.g. "drivers/scsi" will never
be reported again by this semi-automatic cocci program runs.


2013-09-19 22:01:33

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 2/2] [SCSI] aic7xxx: Cocci spatch "kzalloc-simple"

Use kzalloc rather than kmalloc followed by memset with 0.
Found by coccinelle spatch "api/alloc/kzalloc-simple.cocci"

Signed-off-by: Thomas Meyer <[email protected]>
---

diff -u -p a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1324,11 +1324,10 @@ ahd_linux_initialize_scsi_bus(struct ahd
int
ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
{
- ahd->platform_data =
- kmalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
+ ahd->platform_data = kzalloc(sizeof(struct ahd_platform_data),
+ GFP_ATOMIC);
if (ahd->platform_data == NULL)
return (ENOMEM);
- memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
ahd->platform_data->irq = AHD_LINUX_NOIRQ;
ahd_lockinit(ahd);
ahd->seltime = (aic79xx_seltime & 0x3) << 4;
diff -u -p a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1222,11 +1222,10 @@ int
ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
{

- ahc->platform_data =
- kmalloc(sizeof(struct ahc_platform_data), GFP_ATOMIC);
+ ahc->platform_data = kzalloc(sizeof(struct ahc_platform_data),
+ GFP_ATOMIC);
if (ahc->platform_data == NULL)
return (ENOMEM);
- memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
ahc->platform_data->irq = AHC_LINUX_NOIRQ;
ahc_lockinit(ahc);
ahc->seltime = (aic7xxx_seltime & 0x3) << 4;

2013-09-19 22:01:23

by Thomas Meyer

[permalink] [raw]
Subject: [PATCH 1/2] NVMe: Cocci spatch "kzalloc-simple"

Use kzalloc rather than kmalloc followed by memset with 0.
Found by coccinelle spatch "api/alloc/kzalloc-simple.cocci"

Signed-off-by: Thomas Meyer <[email protected]>
---

diff -u -p a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c
--- a/drivers/block/nvme-scsi.c
+++ b/drivers/block/nvme-scsi.c
@@ -933,13 +933,12 @@ static int nvme_trans_bdev_char_page(str
int res = SNTI_TRANSLATION_SUCCESS;
int xfer_len;

- inq_response = kmalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH, GFP_KERNEL);
+ inq_response = kzalloc(EXTENDED_INQUIRY_DATA_PAGE_LENGTH, GFP_KERNEL);
if (inq_response == NULL) {
res = -ENOMEM;
goto out_mem;
}

- memset(inq_response, 0, EXTENDED_INQUIRY_DATA_PAGE_LENGTH);
inq_response[1] = INQ_BDEV_CHARACTERISTICS_PAGE; /* Page Code */
inq_response[2] = 0x00; /* Page Length MSB */
inq_response[3] = 0x3C; /* Page Length LSB */
@@ -964,12 +963,12 @@ static int nvme_trans_log_supp_pages(str
int xfer_len;
u8 *log_response;

- log_response = kmalloc(LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH, GFP_KERNEL);
+ log_response = kzalloc(LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH,
+ GFP_KERNEL);
if (log_response == NULL) {
res = -ENOMEM;
goto out_mem;
}
- memset(log_response, 0, LOG_PAGE_SUPPORTED_LOG_PAGES_LENGTH);

log_response[0] = LOG_PAGE_SUPPORTED_LOG_PAGES_PAGE;
/* Subpage=0x00, Page Length MSB=0 */
@@ -1000,12 +999,11 @@ static int nvme_trans_log_info_exception
u8 temp_c;
u16 temp_k;

- log_response = kmalloc(LOG_INFO_EXCP_PAGE_LENGTH, GFP_KERNEL);
+ log_response = kzalloc(LOG_INFO_EXCP_PAGE_LENGTH, GFP_KERNEL);
if (log_response == NULL) {
res = -ENOMEM;
goto out_mem;
}
- memset(log_response, 0, LOG_INFO_EXCP_PAGE_LENGTH);

mem = dma_alloc_coherent(&dev->pci_dev->dev,
sizeof(struct nvme_smart_log),
@@ -1069,12 +1067,11 @@ static int nvme_trans_log_temperature(st
u8 temp_c_cur, temp_c_thresh;
u16 temp_k;

- log_response = kmalloc(LOG_TEMP_PAGE_LENGTH, GFP_KERNEL);
+ log_response = kzalloc(LOG_TEMP_PAGE_LENGTH, GFP_KERNEL);
if (log_response == NULL) {
res = -ENOMEM;
goto out_mem;
}
- memset(log_response, 0, LOG_TEMP_PAGE_LENGTH);

mem = dma_alloc_coherent(&dev->pci_dev->dev,
sizeof(struct nvme_smart_log),
@@ -1380,12 +1377,11 @@ static int nvme_trans_mode_page_create(s
blk_desc_offset = mph_size;
mode_pages_offset_1 = blk_desc_offset + blk_desc_len;

- response = kmalloc(resp_size, GFP_KERNEL);
+ response = kzalloc(resp_size, GFP_KERNEL);
if (response == NULL) {
res = -ENOMEM;
goto out_mem;
}
- memset(response, 0, resp_size);

res = nvme_trans_fill_mode_parm_hdr(&response[0], mph_size, cdb10,
llbaa, mode_data_length, blk_desc_len);
@@ -2480,12 +2476,11 @@ static int nvme_trans_read_capacity(stru
}
id_ns = mem;

- response = kmalloc(resp_size, GFP_KERNEL);
+ response = kzalloc(resp_size, GFP_KERNEL);
if (response == NULL) {
res = -ENOMEM;
goto out_dma;
}
- memset(response, 0, resp_size);
nvme_trans_fill_read_cap(response, id_ns, cdb16);

xfer_len = min(alloc_len, resp_size);
@@ -2554,12 +2549,11 @@ static int nvme_trans_report_luns(struct
goto out_dma;
}

- response = kmalloc(resp_size, GFP_KERNEL);
+ response = kzalloc(resp_size, GFP_KERNEL);
if (response == NULL) {
res = -ENOMEM;
goto out_dma;
}
- memset(response, 0, resp_size);

/* The first LUN ID will always be 0 per the SAM spec */
for (lun_id = 0; lun_id < le32_to_cpu(id_ctrl->nn); lun_id++) {
@@ -2600,12 +2594,11 @@ static int nvme_trans_request_sense(stru

resp_size = ((desc_format) ? (DESC_FMT_SENSE_DATA_SIZE) :
(FIXED_FMT_SENSE_DATA_SIZE));
- response = kmalloc(resp_size, GFP_KERNEL);
+ response = kzalloc(resp_size, GFP_KERNEL);
if (response == NULL) {
res = -ENOMEM;
goto out;
}
- memset(response, 0, resp_size);

if (desc_format == DESCRIPTOR_FORMAT_SENSE_DATA_TYPE) {
/* Descriptor Format Sense Data */

2013-09-19 22:25:29

by Verma, Vishal L

[permalink] [raw]
Subject: Re: [PATCH 1/2] NVMe: Cocci spatch "kzalloc-simple"

On 9/19/13 3:45 PM, "Thomas Meyer" <[email protected]> wrote:

>Use kzalloc rather than kmalloc followed by memset with 0.
>Found by coccinelle spatch "api/alloc/kzalloc-simple.cocci"
>
>Signed-off-by: Thomas Meyer <[email protected]>
>---

Thomas,

This has already been applied to Matthew's tree:
http://git.infradead.org/users/willy/linux-nvme.git/commitdiff/03ea83e9a37e
41d436f8348e6eee3d8281bfff3a


-Vishal

2013-09-19 22:29:35

by Verma, Vishal L

[permalink] [raw]
Subject: Re: [PATCH 1/2] NVMe: Cocci spatch "kzalloc-simple"

On 9/19/13 4:25 PM, "Verma, Vishal L" <[email protected]> wrote:

>On 9/19/13 3:45 PM, "Thomas Meyer" <[email protected]> wrote:
>
>>Use kzalloc rather than kmalloc followed by memset with 0.
>>Found by coccinelle spatch "api/alloc/kzalloc-simple.cocci"
>>
>>Signed-off-by: Thomas Meyer <[email protected]>
>>---
>
>Thomas,
>
>This has already been applied to Matthew's tree:
>http://git.infradead.org/users/willy/linux-nvme.git/commitdiff/03ea83e9a37
>e
>41d436f8348e6eee3d8281bfff3a
>
>
>-Vishal
>
>
>_______________________________________________
>Linux-nvme mailing list
>[email protected]
>http://merlin.infradead.org/mailman/listinfo/linux-nvme
>

And in Linus' tree - applied in 3.11
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=
03ea83e9a37e41d436f8348e6eee3d8281bfff3a