Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] pnp: consolidate kmalloc wrappers

ISAPNP, PNPBIOS, and PNPACPI all had their own kmalloc wrappers that
reimplemented kcalloc(). Remove the wrappers and just use kcalloc()
directly.

Note that this also removes the PNPBIOS error message when the kmalloc
fails.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Bjorn Helgaas and committed by
Linus Torvalds
a2822e7f ea2f1590

+43 -75
+11 -22
drivers/pnp/isapnp/core.c
··· 142 142 isapnp_write_byte(idx+1, val); 143 143 } 144 144 145 - static void *isapnp_alloc(long size) 146 - { 147 - void *result; 148 - 149 - result = kmalloc(size, GFP_KERNEL); 150 - if (!result) 151 - return NULL; 152 - memset(result, 0, size); 153 - return result; 154 - } 155 - 156 145 static void isapnp_key(void) 157 146 { 158 147 unsigned char code = 0x6a, msb; ··· 395 406 struct pnp_id * id; 396 407 if (!dev) 397 408 return; 398 - id = isapnp_alloc(sizeof(struct pnp_id)); 409 + id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); 399 410 if (!id) 400 411 return; 401 412 sprintf(id->id, "%c%c%c%x%x%x%x", ··· 419 430 struct pnp_dev *dev; 420 431 421 432 isapnp_peek(tmp, size); 422 - dev = isapnp_alloc(sizeof(struct pnp_dev)); 433 + dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL); 423 434 if (!dev) 424 435 return NULL; 425 436 dev->number = number; ··· 450 461 unsigned long bits; 451 462 452 463 isapnp_peek(tmp, size); 453 - irq = isapnp_alloc(sizeof(struct pnp_irq)); 464 + irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); 454 465 if (!irq) 455 466 return; 456 467 bits = (tmp[1] << 8) | tmp[0]; ··· 474 485 struct pnp_dma *dma; 475 486 476 487 isapnp_peek(tmp, size); 477 - dma = isapnp_alloc(sizeof(struct pnp_dma)); 488 + dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); 478 489 if (!dma) 479 490 return; 480 491 dma->map = tmp[0]; ··· 494 505 struct pnp_port *port; 495 506 496 507 isapnp_peek(tmp, size); 497 - port = isapnp_alloc(sizeof(struct pnp_port)); 508 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 498 509 if (!port) 499 510 return; 500 511 port->min = (tmp[2] << 8) | tmp[1]; ··· 517 528 struct pnp_port *port; 518 529 519 530 isapnp_peek(tmp, size); 520 - port = isapnp_alloc(sizeof(struct pnp_port)); 531 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 521 532 if (!port) 522 533 return; 523 534 port->min = port->max = (tmp[1] << 8) | tmp[0]; ··· 539 550 struct pnp_mem *mem; 540 551 541 552 isapnp_peek(tmp, size); 542 - mem = isapnp_alloc(sizeof(struct pnp_mem)); 553 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 543 554 if (!mem) 544 555 return; 545 556 mem->min = ((tmp[2] << 8) | tmp[1]) << 8; ··· 562 573 struct pnp_mem *mem; 563 574 564 575 isapnp_peek(tmp, size); 565 - mem = isapnp_alloc(sizeof(struct pnp_mem)); 576 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 566 577 if (!mem) 567 578 return; 568 579 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; ··· 584 595 struct pnp_mem *mem; 585 596 586 597 isapnp_peek(tmp, size); 587 - mem = isapnp_alloc(sizeof(struct pnp_mem)); 598 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 588 599 if (!mem) 589 600 return; 590 601 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; ··· 827 838 828 839 static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device) 829 840 { 830 - struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id)); 841 + struct pnp_id * id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); 831 842 if (!id) 832 843 return; 833 844 sprintf(id->id, "%c%c%c%x%x%x%x", ··· 863 874 header[4], header[5], header[6], header[7], header[8]); 864 875 printk(KERN_DEBUG "checksum = 0x%x\n", checksum); 865 876 #endif 866 - if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL) 877 + if ((card = kcalloc(1, sizeof(struct pnp_card), GFP_KERNEL)) == NULL) 867 878 continue; 868 879 869 880 card->number = csn;
+3 -12
drivers/pnp/pnpacpi/core.c
··· 41 41 return (!acpi_match_ids(dev, excluded_id_list)); 42 42 } 43 43 44 - void *pnpacpi_kmalloc(size_t size, int f) 45 - { 46 - void *p = kmalloc(size, f); 47 - if (p) 48 - memset(p, 0, size); 49 - return p; 50 - } 51 - 52 44 /* 53 45 * Compatible Device IDs 54 46 */ ··· 135 143 return 0; 136 144 137 145 pnp_dbg("ACPI device : hid %s", acpi_device_hid(device)); 138 - dev = pnpacpi_kmalloc(sizeof(struct pnp_dev), GFP_KERNEL); 146 + dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL); 139 147 if (!dev) { 140 148 pnp_err("Out of memory"); 141 149 return -ENOMEM; ··· 165 173 dev->number = num; 166 174 167 175 /* set the initial values for the PnP device */ 168 - dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id), GFP_KERNEL); 176 + dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); 169 177 if (!dev_id) 170 178 goto err; 171 179 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id); ··· 197 205 for (i = 0; i < cid_list->count; i++) { 198 206 if (!ispnpidacpi(cid_list->id[i].value)) 199 207 continue; 200 - dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id), 201 - GFP_KERNEL); 208 + dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); 202 209 if (!dev_id) 203 210 continue; 204 211
-1
drivers/pnp/pnpacpi/pnpacpi.h
··· 5 5 #include <linux/acpi.h> 6 6 #include <linux/pnp.h> 7 7 8 - void *pnpacpi_kmalloc(size_t size, int f); 9 8 acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*); 10 9 acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*); 11 10 int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
+9 -9
drivers/pnp/pnpacpi/rsparser.c
··· 244 244 245 245 if (p->number_of_channels == 0) 246 246 return; 247 - dma = pnpacpi_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL); 247 + dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); 248 248 if (!dma) 249 249 return; 250 250 ··· 300 300 301 301 if (p->number_of_interrupts == 0) 302 302 return; 303 - irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 303 + irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); 304 304 if (!irq) 305 305 return; 306 306 ··· 321 321 322 322 if (p->number_of_interrupts == 0) 323 323 return; 324 - irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 324 + irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); 325 325 if (!irq) 326 326 return; 327 327 ··· 342 342 343 343 if (io->range_length == 0) 344 344 return; 345 - port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 345 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 346 346 if (!port) 347 347 return; 348 348 port->min = io->min_base_address; ··· 363 363 364 364 if (io->range_length == 0) 365 365 return; 366 - port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 366 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 367 367 if (!port) 368 368 return; 369 369 port->min = port->max = io->base_address; ··· 382 382 383 383 if (p->range_length == 0) 384 384 return; 385 - mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 385 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 386 386 if (!mem) 387 387 return; 388 388 mem->min = p->min_base_address; ··· 405 405 406 406 if (p->range_length == 0) 407 407 return; 408 - mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 408 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 409 409 if (!mem) 410 410 return; 411 411 mem->min = p->min_base_address; ··· 428 428 429 429 if (p->range_length == 0) 430 430 return; 431 - mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 431 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 432 432 if (!mem) 433 433 return; 434 434 mem->min = mem->max = p->range_base_address; ··· 612 612 if (!res_cnt) 613 613 return -EINVAL; 614 614 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; 615 - buffer->pointer = pnpacpi_kmalloc(buffer->length - 1, GFP_KERNEL); 615 + buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL); 616 616 if (!buffer->pointer) 617 617 return -ENOMEM; 618 618 pnp_dbg("Res cnt %d", res_cnt);
+8 -18
drivers/pnp/pnpbios/core.c
··· 86 86 87 87 struct pnp_dev_node_info node_info; 88 88 89 - void *pnpbios_kmalloc(size_t size, int f) 90 - { 91 - void *p = kmalloc( size, f ); 92 - if ( p == NULL ) 93 - printk(KERN_ERR "PnPBIOS: kmalloc() failed\n"); 94 - else 95 - memset(p, 0, size); 96 - return p; 97 - } 98 - 99 89 /* 100 90 * 101 91 * DOCKING FUNCTIONS ··· 111 121 if (!current->fs->root) { 112 122 return -EAGAIN; 113 123 } 114 - if (!(envp = (char **) pnpbios_kmalloc (20 * sizeof (char *), GFP_KERNEL))) { 124 + if (!(envp = (char **) kcalloc (20, sizeof (char *), GFP_KERNEL))) { 115 125 return -ENOMEM; 116 126 } 117 - if (!(buf = pnpbios_kmalloc (256, GFP_KERNEL))) { 127 + if (!(buf = kcalloc (1, 256, GFP_KERNEL))) { 118 128 kfree (envp); 119 129 return -ENOMEM; 120 130 } ··· 221 231 if(!pnpbios_is_dynamic(dev)) 222 232 return -EPERM; 223 233 224 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 234 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 225 235 if (!node) 226 236 return -1; 227 237 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { ··· 244 254 if (!pnpbios_is_dynamic(dev)) 245 255 return -EPERM; 246 256 247 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 257 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 248 258 if (!node) 249 259 return -1; 250 260 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { ··· 295 305 if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev)) 296 306 return -EPERM; 297 307 298 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 308 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 299 309 if (!node) 300 310 return -ENOMEM; 301 311 ··· 337 347 } 338 348 339 349 /* set the initial values for the PnP device */ 340 - dev_id = pnpbios_kmalloc(sizeof(struct pnp_id), GFP_KERNEL); 350 + dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL); 341 351 if (!dev_id) 342 352 return -1; 343 353 pnpid32_to_pnpid(node->eisa_id,id); ··· 375 385 struct pnp_bios_node *node; 376 386 struct pnp_dev *dev; 377 387 378 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 388 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 379 389 if (!node) 380 390 return; 381 391 ··· 392 402 break; 393 403 } 394 404 nodes_got++; 395 - dev = pnpbios_kmalloc(sizeof (struct pnp_dev), GFP_KERNEL); 405 + dev = kcalloc(1, sizeof (struct pnp_dev), GFP_KERNEL); 396 406 if (!dev) 397 407 break; 398 408 if(insert_device(dev,node)<0)
-1
drivers/pnp/pnpbios/pnpbios.h
··· 26 26 27 27 extern int pnp_bios_present(void); 28 28 extern int pnpbios_dont_use_current_config; 29 - extern void *pnpbios_kmalloc(size_t size, int f); 30 29 31 30 extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node); 32 31 extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
+4 -4
drivers/pnp/pnpbios/proc.c
··· 87 87 return -EFBIG; 88 88 } 89 89 90 - tmpbuf = pnpbios_kmalloc(escd.escd_size, GFP_KERNEL); 90 + tmpbuf = kcalloc(1, escd.escd_size, GFP_KERNEL); 91 91 if (!tmpbuf) return -ENOMEM; 92 92 93 93 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) { ··· 133 133 if (pos >= 0xff) 134 134 return 0; 135 135 136 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 136 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 137 137 if (!node) return -ENOMEM; 138 138 139 139 for (nodenum=pos; nodenum<0xff; ) { ··· 168 168 u8 nodenum = (long)data; 169 169 int len; 170 170 171 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 171 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 172 172 if (!node) return -ENOMEM; 173 173 if (pnp_bios_get_dev_node(&nodenum, boot, node)) { 174 174 kfree(node); ··· 188 188 u8 nodenum = (long)data; 189 189 int ret = count; 190 190 191 - node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 191 + node = kcalloc(1, node_info.max_node_size, GFP_KERNEL); 192 192 if (!node) 193 193 return -ENOMEM; 194 194 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
+8 -8
drivers/pnp/pnpbios/rsparser.c
··· 247 247 pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option) 248 248 { 249 249 struct pnp_mem * mem; 250 - mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 250 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 251 251 if (!mem) 252 252 return; 253 253 mem->min = ((p[5] << 8) | p[4]) << 8; ··· 263 263 pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option) 264 264 { 265 265 struct pnp_mem * mem; 266 - mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 266 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 267 267 if (!mem) 268 268 return; 269 269 mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; ··· 279 279 pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option) 280 280 { 281 281 struct pnp_mem * mem; 282 - mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 282 + mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL); 283 283 if (!mem) 284 284 return; 285 285 mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; ··· 296 296 struct pnp_irq * irq; 297 297 unsigned long bits; 298 298 299 - irq = pnpbios_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 299 + irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL); 300 300 if (!irq) 301 301 return; 302 302 bits = (p[2] << 8) | p[1]; ··· 313 313 pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option) 314 314 { 315 315 struct pnp_dma * dma; 316 - dma = pnpbios_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL); 316 + dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL); 317 317 if (!dma) 318 318 return; 319 319 dma->map = p[1]; ··· 326 326 pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option) 327 327 { 328 328 struct pnp_port * port; 329 - port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 329 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 330 330 if (!port) 331 331 return; 332 332 port->min = (p[3] << 8) | p[2]; ··· 342 342 pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option) 343 343 { 344 344 struct pnp_port * port; 345 - port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 345 + port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL); 346 346 if (!port) 347 347 return; 348 348 port->min = port->max = (p[2] << 8) | p[1]; ··· 530 530 case SMALL_TAG_COMPATDEVID: /* compatible ID */ 531 531 if (len != 4) 532 532 goto len_err; 533 - dev_id = pnpbios_kmalloc(sizeof (struct pnp_id), GFP_KERNEL); 533 + dev_id = kcalloc(1, sizeof (struct pnp_id), GFP_KERNEL); 534 534 if (!dev_id) 535 535 return NULL; 536 536 memset(dev_id, 0, sizeof(struct pnp_id));