Skip to content

Commit f5afe80

Browse files
SesterhennEricgregkh
authored andcommitted
[PATCH] PCI: kzalloc() conversion in drivers/pci
this patch converts drivers/pci to kzalloc usage. Compile tested with allyes config. Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 7c8f25d commit f5afe80

14 files changed

Lines changed: 75 additions & 169 deletions

‎drivers/pci/hotplug/acpiphp_glue.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
143143
device = (adr >> 16) & 0xffff;
144144
function = adr & 0xffff;
145145

146-
newfunc = kmalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
146+
newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
147147
if (!newfunc)
148148
return AE_NO_MEMORY;
149-
memset(newfunc, 0, sizeof(struct acpiphp_func));
150149

151150
INIT_LIST_HEAD(&newfunc->sibling);
152151
newfunc->handle = handle;
@@ -189,13 +188,12 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
189188
}
190189

191190
if (!slot) {
192-
slot = kmalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
191+
slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
193192
if (!slot) {
194193
kfree(newfunc);
195194
return AE_NO_MEMORY;
196195
}
197196

198-
memset(slot, 0, sizeof(struct acpiphp_slot));
199197
slot->bridge = bridge;
200198
slot->device = device;
201199
slot->sun = sun;
@@ -376,12 +374,10 @@ static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
376374
{
377375
struct acpiphp_bridge *bridge;
378376

379-
bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
377+
bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
380378
if (bridge == NULL)
381379
return;
382380

383-
memset(bridge, 0, sizeof(struct acpiphp_bridge));
384-
385381
bridge->type = BRIDGE_TYPE_HOST;
386382
bridge->handle = handle;
387383

@@ -398,14 +394,12 @@ static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
398394
{
399395
struct acpiphp_bridge *bridge;
400396

401-
bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
397+
bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
402398
if (bridge == NULL) {
403399
err("out of memory\n");
404400
return;
405401
}
406402

407-
memset(bridge, 0, sizeof(struct acpiphp_bridge));
408-
409403
bridge->type = BRIDGE_TYPE_P2P;
410404
bridge->handle = handle;
411405

‎drivers/pci/hotplug/cpci_hotplug_core.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,19 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
248248
* with the pci_hotplug subsystem.
249249
*/
250250
for (i = first; i <= last; ++i) {
251-
slot = kmalloc(sizeof (struct slot), GFP_KERNEL);
251+
slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
252252
if (!slot)
253253
goto error;
254-
memset(slot, 0, sizeof (struct slot));
255254

256255
hotplug_slot =
257-
kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
256+
kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
258257
if (!hotplug_slot)
259258
goto error_slot;
260-
memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
261259
slot->hotplug_slot = hotplug_slot;
262260

263-
info = kmalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
261+
info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
264262
if (!info)
265263
goto error_hpslot;
266-
memset(info, 0, sizeof (struct hotplug_slot_info));
267264
hotplug_slot->info = info;
268265

269266
name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);

‎drivers/pci/hotplug/cpqphp_core.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,26 +347,22 @@ static int ctrl_slot_setup(struct controller *ctrl,
347347
slot_number = ctrl->first_slot;
348348

349349
while (number_of_slots) {
350-
slot = kmalloc(sizeof(*slot), GFP_KERNEL);
350+
slot = kzalloc(sizeof(*slot), GFP_KERNEL);
351351
if (!slot)
352352
goto error;
353353

354-
memset(slot, 0, sizeof(struct slot));
355-
slot->hotplug_slot = kmalloc(sizeof(*(slot->hotplug_slot)),
354+
slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
356355
GFP_KERNEL);
357356
if (!slot->hotplug_slot)
358357
goto error_slot;
359358
hotplug_slot = slot->hotplug_slot;
360-
memset(hotplug_slot, 0, sizeof(struct hotplug_slot));
361359

362360
hotplug_slot->info =
363-
kmalloc(sizeof(*(hotplug_slot->info)),
361+
kzalloc(sizeof(*(hotplug_slot->info)),
364362
GFP_KERNEL);
365363
if (!hotplug_slot->info)
366364
goto error_hpslot;
367365
hotplug_slot_info = hotplug_slot->info;
368-
memset(hotplug_slot_info, 0,
369-
sizeof(struct hotplug_slot_info));
370366
hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
371367

372368
if (!hotplug_slot->name)
@@ -854,13 +850,12 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
854850
goto err_disable_device;
855851
}
856852

857-
ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
853+
ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
858854
if (!ctrl) {
859855
err("%s : out of memory\n", __FUNCTION__);
860856
rc = -ENOMEM;
861857
goto err_disable_device;
862858
}
863-
memset(ctrl, 0, sizeof(struct controller));
864859

865860
rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
866861
if (rc) {

‎drivers/pci/hotplug/fakephp.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ static int add_slot(struct pci_dev *dev)
9595
struct hotplug_slot *slot;
9696
int retval = -ENOMEM;
9797

98-
slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
98+
slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
9999
if (!slot)
100100
goto error;
101-
memset(slot, 0, sizeof(*slot));
102101

103-
slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
102+
slot->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
104103
if (!slot->info)
105104
goto error_slot;
106-
memset(slot->info, 0, sizeof(struct hotplug_slot_info));
107105

108106
slot->info->power_status = 1;
109107
slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
@@ -227,11 +225,10 @@ static void pci_rescan_bus(const struct pci_bus *bus)
227225
{
228226
unsigned int devfn;
229227
struct pci_dev *dev;
230-
dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
228+
dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
231229
if (!dev)
232230
return;
233231

234-
memset(dev, 0, sizeof(dev));
235232
dev->bus = (struct pci_bus*)bus;
236233
dev->sysdata = bus->sysdata;
237234
for (devfn = 0; devfn < 0x100; devfn += 8) {

‎drivers/pci/hotplug/ibmphp_core.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,15 +1141,14 @@ static int enable_slot(struct hotplug_slot *hs)
11411141
goto error_power;
11421142
}
11431143

1144-
slot_cur->func = kmalloc(sizeof(struct pci_func), GFP_KERNEL);
1144+
slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
11451145
if (!slot_cur->func) {
11461146
/* We cannot do update_slot_info here, since no memory for
11471147
* kmalloc n.e.ways, and update_slot_info allocates some */
11481148
err("out of system memory\n");
11491149
rc = -ENOMEM;
11501150
goto error_power;
11511151
}
1152-
memset(slot_cur->func, 0, sizeof(struct pci_func));
11531152
slot_cur->func->busno = slot_cur->bus;
11541153
slot_cur->func->device = slot_cur->device;
11551154
for (i = 0; i < 4; i++)
@@ -1252,13 +1251,12 @@ int ibmphp_do_disable_slot(struct slot *slot_cur)
12521251

12531252
if (slot_cur->func == NULL) {
12541253
/* We need this for fncs's that were there on bootup */
1255-
slot_cur->func = kmalloc(sizeof(struct pci_func), GFP_KERNEL);
1254+
slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
12561255
if (!slot_cur->func) {
12571256
err("out of system memory\n");
12581257
rc = -ENOMEM;
12591258
goto error;
12601259
}
1261-
memset(slot_cur->func, 0, sizeof(struct pci_func));
12621260
slot_cur->func->busno = slot_cur->bus;
12631261
slot_cur->func->device = slot_cur->device;
12641262
}

‎drivers/pci/hotplug/ibmphp_ebda.c‎

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ static int ebda_rio_table (void);
7272

7373
static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void)
7474
{
75-
struct ebda_hpc_list *list;
76-
77-
list = kmalloc (sizeof (struct ebda_hpc_list), GFP_KERNEL);
78-
if (!list)
79-
return NULL;
80-
memset (list, 0, sizeof (*list));
81-
return list;
75+
return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL);
8276
}
8377

8478
static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
@@ -87,21 +81,18 @@ static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
8781
struct ebda_hpc_slot *slots;
8882
struct ebda_hpc_bus *buses;
8983

90-
controller = kmalloc (sizeof (struct controller), GFP_KERNEL);
84+
controller = kzalloc(sizeof(struct controller), GFP_KERNEL);
9185
if (!controller)
9286
goto error;
93-
memset (controller, 0, sizeof (*controller));
9487

95-
slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL);
88+
slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL);
9689
if (!slots)
9790
goto error_contr;
98-
memset (slots, 0, sizeof (*slots) * slot_count);
9991
controller->slots = slots;
10092

101-
buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL);
93+
buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL);
10294
if (!buses)
10395
goto error_slots;
104-
memset (buses, 0, sizeof (*buses) * bus_count);
10596
controller->buses = buses;
10697

10798
return controller;
@@ -122,24 +113,12 @@ static void free_ebda_hpc (struct controller *controller)
122113

123114
static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void)
124115
{
125-
struct ebda_rsrc_list *list;
126-
127-
list = kmalloc (sizeof (struct ebda_rsrc_list), GFP_KERNEL);
128-
if (!list)
129-
return NULL;
130-
memset (list, 0, sizeof (*list));
131-
return list;
116+
return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL);
132117
}
133118

134119
static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void)
135120
{
136-
struct ebda_pci_rsrc *resource;
137-
138-
resource = kmalloc (sizeof (struct ebda_pci_rsrc), GFP_KERNEL);
139-
if (!resource)
140-
return NULL;
141-
memset (resource, 0, sizeof (*resource));
142-
return resource;
121+
return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL);
143122
}
144123

145124
static void __init print_bus_info (void)
@@ -390,10 +369,9 @@ int __init ibmphp_access_ebda (void)
390369
debug ("now enter io table ---\n");
391370
debug ("rio blk id: %x\n", blk_id);
392371

393-
rio_table_ptr = kmalloc (sizeof (struct rio_table_hdr), GFP_KERNEL);
372+
rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL);
394373
if (!rio_table_ptr)
395374
return -ENOMEM;
396-
memset (rio_table_ptr, 0, sizeof (struct rio_table_hdr) );
397375
rio_table_ptr->ver_num = readb (io_mem + offset);
398376
rio_table_ptr->scal_count = readb (io_mem + offset + 1);
399377
rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
@@ -445,10 +423,9 @@ static int __init ebda_rio_table (void)
445423

446424
// we do concern about rio details
447425
for (i = 0; i < rio_table_ptr->riodev_count; i++) {
448-
rio_detail_ptr = kmalloc (sizeof (struct rio_detail), GFP_KERNEL);
426+
rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL);
449427
if (!rio_detail_ptr)
450428
return -ENOMEM;
451-
memset (rio_detail_ptr, 0, sizeof (struct rio_detail));
452429
rio_detail_ptr->rio_node_id = readb (io_mem + offset);
453430
rio_detail_ptr->bbar = readl (io_mem + offset + 1);
454431
rio_detail_ptr->rio_type = readb (io_mem + offset + 5);
@@ -503,10 +480,9 @@ static int __init combine_wpg_for_chassis (void)
503480
rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
504481
opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num);
505482
if (!opt_rio_ptr) {
506-
opt_rio_ptr = (struct opt_rio *) kmalloc (sizeof (struct opt_rio), GFP_KERNEL);
483+
opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL);
507484
if (!opt_rio_ptr)
508485
return -ENOMEM;
509-
memset (opt_rio_ptr, 0, sizeof (struct opt_rio));
510486
opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
511487
opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
512488
opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
@@ -546,10 +522,9 @@ static int combine_wpg_for_expansion (void)
546522
rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
547523
opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num);
548524
if (!opt_rio_lo_ptr) {
549-
opt_rio_lo_ptr = (struct opt_rio_lo *) kmalloc (sizeof (struct opt_rio_lo), GFP_KERNEL);
525+
opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL);
550526
if (!opt_rio_lo_ptr)
551527
return -ENOMEM;
552-
memset (opt_rio_lo_ptr, 0, sizeof (struct opt_rio_lo));
553528
opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
554529
opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
555530
opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
@@ -842,12 +817,11 @@ static int __init ebda_rsrc_controller (void)
842817

843818
bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num);
844819
if (!bus_info_ptr2) {
845-
bus_info_ptr1 = (struct bus_info *) kmalloc (sizeof (struct bus_info), GFP_KERNEL);
820+
bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL);
846821
if (!bus_info_ptr1) {
847822
rc = -ENOMEM;
848823
goto error_no_hp_slot;
849824
}
850-
memset (bus_info_ptr1, 0, sizeof (struct bus_info));
851825
bus_info_ptr1->slot_min = slot_ptr->slot_num;
852826
bus_info_ptr1->slot_max = slot_ptr->slot_num;
853827
bus_info_ptr1->slot_count += 1;
@@ -946,32 +920,29 @@ static int __init ebda_rsrc_controller (void)
946920
// register slots with hpc core as well as create linked list of ibm slot
947921
for (index = 0; index < hpc_ptr->slot_count; index++) {
948922

949-
hp_slot_ptr = kmalloc(sizeof(*hp_slot_ptr), GFP_KERNEL);
923+
hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL);
950924
if (!hp_slot_ptr) {
951925
rc = -ENOMEM;
952926
goto error_no_hp_slot;
953927
}
954-
memset(hp_slot_ptr, 0, sizeof(*hp_slot_ptr));
955928

956-
hp_slot_ptr->info = kmalloc (sizeof(struct hotplug_slot_info), GFP_KERNEL);
929+
hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
957930
if (!hp_slot_ptr->info) {
958931
rc = -ENOMEM;
959932
goto error_no_hp_info;
960933
}
961-
memset(hp_slot_ptr->info, 0, sizeof(struct hotplug_slot_info));
962934

963935
hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
964936
if (!hp_slot_ptr->name) {
965937
rc = -ENOMEM;
966938
goto error_no_hp_name;
967939
}
968940

969-
tmp_slot = kmalloc(sizeof(*tmp_slot), GFP_KERNEL);
941+
tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
970942
if (!tmp_slot) {
971943
rc = -ENOMEM;
972944
goto error_no_slot;
973945
}
974-
memset(tmp_slot, 0, sizeof(*tmp_slot));
975946

976947
tmp_slot->flag = TRUE;
977948

0 commit comments

Comments
 (0)