Pull ata fixes from Damien Le Moal: - Two fixes from Ondrej for the pata_parport driver to address an issue with error handling during drive connection and to fix memory leaks in case of errors during initialization and when disconnecting a device. * tag 'ata-6.3-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata: ata: pata_parport: fix memory leaks ata: pata_parport: fix parport release without claim
Unified · Split
| @@ -381,6 +381,7 @@ static void pata_parport_dev_release(struct device *dev) · 380 unmodified lines | ||
| 381 | 381 | { |
| 382 | 382 | struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev); |
| 383 | 383 | |
| 384 | + ida_free(&pata_parport_bus_dev_ids, dev->id); | |
| 384 | 385 | kfree(pi); |
| 385 | 386 | } |
| 386 | 387 | |
| @@ -433,23 +434,27 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 46 unmodified lines | ||
| 433 | 434 | if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev)) |
| 434 | 435 | return NULL; |
| 435 | 436 | |
| 437 | + id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL); | |
| 438 | + if (id < 0) | |
| 439 | + return NULL; | |
| 440 | + | |
| 436 | 441 | pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL); |
| 437 | − if (!pi) | |
| 442 | + if (!pi) { | |
| 443 | + ida_free(&pata_parport_bus_dev_ids, id); | |
| 438 | 444 | return NULL; |
| 445 | + } | |
| 439 | 446 | |
| 440 | 447 | /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */ |
| 441 | 448 | pi->dev.parent = &pata_parport_bus; |
| 442 | 449 | pi->dev.bus = &pata_parport_bus_type; |
| 443 | 450 | pi->dev.driver = &pr->driver; |
| 444 | 451 | pi->dev.release = pata_parport_dev_release; |
| 445 | − id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL); | |
| 446 | − if (id < 0) | |
| 447 | − return NULL; /* pata_parport_dev_release will do kfree(pi) */ | |
| 448 | 452 | pi->dev.id = id; |
| 449 | 453 | dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id); |
| 450 | 454 | if (device_register(&pi->dev)) { |
| 451 | 455 | put_device(&pi->dev); |
| 452 | − goto out_ida_free; | |
| 456 | + /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */ | |
| 457 | + return NULL; | |
| 453 | 458 | } |
| 454 | 459 | |
| 455 | 460 | pi->proto = pr; |
| @@ -464,8 +469,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 8 unmodified lines | ||
| 464 | 469 | pi->port = parport->base; |
| 465 | 470 | |
| 466 | 471 | par_cb.private = pi; |
| 467 | − pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb, | |
| 468 | − pi->dev.id); | |
| 472 | + pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb, id); | |
| 469 | 473 | if (!pi->pardev) |
| 470 | 474 | goto out_module_put; |
| 471 | 475 | |
| @@ -487,12 +491,13 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 15 unmodified lines | ||
| 487 | 491 | |
| 488 | 492 | pi_connect(pi); |
| 489 | 493 | if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht)) |
| 490 | − goto out_unreg_parport; | |
| 494 | + goto out_disconnect; | |
| 491 | 495 | |
| 492 | 496 | return pi; |
| 493 | 497 | |
| 494 | −out_unreg_parport: | |
| 498 | +out_disconnect: | |
| 495 | 499 | pi_disconnect(pi); |
| 500 | +out_unreg_parport: | |
| 496 | 501 | parport_unregister_device(pi->pardev); |
| 497 | 502 | if (pi->proto->release_proto) |
| 498 | 503 | pi->proto->release_proto(pi); |
| @@ -500,8 +505,7 @@ out_module_put: · 1 unmodified line | ||
| 500 | 505 | module_put(pi->proto->owner); |
| 501 | 506 | out_unreg_dev: |
| 502 | 507 | device_unregister(&pi->dev); |
| 503 | −out_ida_free: | |
| 504 | − ida_free(&pata_parport_bus_dev_ids, pi->dev.id); | |
| 508 | + /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */ | |
| 505 | 509 | return NULL; |
| 506 | 510 | } |
| 507 | 511 | |
| @@ -626,8 +630,7 @@ static void pi_remove_one(struct device *dev) · 118 unmodified lines | ||
| 626 | 630 | pi_disconnect(pi); |
| 627 | 631 | pi_release(pi); |
| 628 | 632 | device_unregister(dev); |
| 629 | − ida_free(&pata_parport_bus_dev_ids, dev->id); | |
| 630 | − /* pata_parport_dev_release will do kfree(pi) */ | |
| 633 | + /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */ | |
| 631 | 634 | } |
| 632 | 635 | |
| 633 | 636 | static ssize_t delete_device_store(struct bus_type *bus, const char *buf, |
| @@ -643,6 +646,7 @@ static ssize_t delete_device_store(struct bus_type *bus, const char *buf, · 9 unmodified lines | ||
| 643 | 646 | } |
| 644 | 647 | |
| 645 | 648 | pi_remove_one(dev); |
| 649 | + put_device(dev); | |
| 646 | 650 | mutex_unlock(&pi_mutex); |
| 647 | 651 | |
| 648 | 652 | return count; |