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

amd8111_edac: Fix leaks in probe error paths

Both probe error paths are incomplete and leak memory and device
references. Add the missing cleanups.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Link: http://lkml.kernel.org/r/20140224154534.5a3b797a@endymion.delvare
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>

authored by

Jean Delvare and committed by
Borislav Petkov
5576fb86 0e089c18

+30 -14
+30 -14
drivers/edac/amd8111_edac.c
··· 350 350 const struct pci_device_id *id) 351 351 { 352 352 struct amd8111_dev_info *dev_info = &amd8111_devices[id->driver_data]; 353 + int ret = -ENODEV; 353 354 354 355 dev_info->dev = pci_get_device(PCI_VENDOR_ID_AMD, 355 356 dev_info->err_dev, NULL); ··· 360 359 "vendor %x, device %x, name %s\n", 361 360 PCI_VENDOR_ID_AMD, dev_info->err_dev, 362 361 dev_info->ctl_name); 363 - return -ENODEV; 362 + goto err; 364 363 } 365 364 366 365 if (pci_enable_device(dev_info->dev)) { 367 - pci_dev_put(dev_info->dev); 368 366 printk(KERN_ERR "failed to enable:" 369 367 "vendor %x, device %x, name %s\n", 370 368 PCI_VENDOR_ID_AMD, dev_info->err_dev, 371 369 dev_info->ctl_name); 372 - return -ENODEV; 370 + goto err_dev_put; 373 371 } 374 372 375 373 /* ··· 381 381 edac_device_alloc_ctl_info(0, dev_info->ctl_name, 1, 382 382 NULL, 0, 0, 383 383 NULL, 0, dev_info->edac_idx); 384 - if (!dev_info->edac_dev) 385 - return -ENOMEM; 384 + if (!dev_info->edac_dev) { 385 + ret = -ENOMEM; 386 + goto err_dev_put; 387 + } 386 388 387 389 dev_info->edac_dev->pvt_info = dev_info; 388 390 dev_info->edac_dev->dev = &dev_info->dev->dev; ··· 401 399 if (edac_device_add_device(dev_info->edac_dev) > 0) { 402 400 printk(KERN_ERR "failed to add edac_dev for %s\n", 403 401 dev_info->ctl_name); 404 - edac_device_free_ctl_info(dev_info->edac_dev); 405 - return -ENODEV; 402 + goto err_edac_free_ctl; 406 403 } 407 404 408 405 printk(KERN_INFO "added one edac_dev on AMD8111 " ··· 410 409 dev_info->ctl_name); 411 410 412 411 return 0; 412 + 413 + err_edac_free_ctl: 414 + edac_device_free_ctl_info(dev_info->edac_dev); 415 + err_dev_put: 416 + pci_dev_put(dev_info->dev); 417 + err: 418 + return ret; 413 419 } 414 420 415 421 static void amd8111_dev_remove(struct pci_dev *dev) ··· 445 437 const struct pci_device_id *id) 446 438 { 447 439 struct amd8111_pci_info *pci_info = &amd8111_pcis[id->driver_data]; 440 + int ret = -ENODEV; 448 441 449 442 pci_info->dev = pci_get_device(PCI_VENDOR_ID_AMD, 450 443 pci_info->err_dev, NULL); ··· 455 446 "vendor %x, device %x, name %s\n", 456 447 PCI_VENDOR_ID_AMD, pci_info->err_dev, 457 448 pci_info->ctl_name); 458 - return -ENODEV; 449 + goto err; 459 450 } 460 451 461 452 if (pci_enable_device(pci_info->dev)) { 462 - pci_dev_put(pci_info->dev); 463 453 printk(KERN_ERR "failed to enable:" 464 454 "vendor %x, device %x, name %s\n", 465 455 PCI_VENDOR_ID_AMD, pci_info->err_dev, 466 456 pci_info->ctl_name); 467 - return -ENODEV; 457 + goto err_dev_put; 468 458 } 469 459 470 460 /* ··· 473 465 */ 474 466 pci_info->edac_idx = edac_pci_alloc_index(); 475 467 pci_info->edac_dev = edac_pci_alloc_ctl_info(0, pci_info->ctl_name); 476 - if (!pci_info->edac_dev) 477 - return -ENOMEM; 468 + if (!pci_info->edac_dev) { 469 + ret = -ENOMEM; 470 + goto err_dev_put; 471 + } 478 472 479 473 pci_info->edac_dev->pvt_info = pci_info; 480 474 pci_info->edac_dev->dev = &pci_info->dev->dev; ··· 493 483 if (edac_pci_add_device(pci_info->edac_dev, pci_info->edac_idx) > 0) { 494 484 printk(KERN_ERR "failed to add edac_pci for %s\n", 495 485 pci_info->ctl_name); 496 - edac_pci_free_ctl_info(pci_info->edac_dev); 497 - return -ENODEV; 486 + goto err_edac_free_ctl; 498 487 } 499 488 500 489 printk(KERN_INFO "added one edac_pci on AMD8111 " ··· 502 493 pci_info->ctl_name); 503 494 504 495 return 0; 496 + 497 + err_edac_free_ctl: 498 + edac_pci_free_ctl_info(pci_info->edac_dev); 499 + err_dev_put: 500 + pci_dev_put(pci_info->dev); 501 + err: 502 + return ret; 505 503 } 506 504 507 505 static void amd8111_pci_remove(struct pci_dev *dev)