History

Merge tag 'ata-6.3-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata

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

Linus Torvalds committed 3 years ago

Commit f900bff2 parents efbcbb1 5bc9e2d1 file · +17 −13Browse files

Unified · Split

drivers/ata/pata_parport/pata_parport.c+17−13
@@ -381,6 +381,7 @@ static void pata_parport_dev_release(struct device *dev) · 380 unmodified lines
381{381{
382 struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);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 kfree(pi);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 if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev))434 if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev))
434 return NULL;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 pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);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 return NULL;444 return NULL;
445 }
439 446
440 /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */447 /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
441 pi->dev.parent = &pata_parport_bus;448 pi->dev.parent = &pata_parport_bus;
442 pi->dev.bus = &pata_parport_bus_type;449 pi->dev.bus = &pata_parport_bus_type;
443 pi->dev.driver = &pr->driver;450 pi->dev.driver = &pr->driver;
444 pi->dev.release = pata_parport_dev_release;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 pi->dev.id = id;452 pi->dev.id = id;
449 dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);453 dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
450 if (device_register(&pi->dev)) {454 if (device_register(&pi->dev)) {
451 put_device(&pi->dev);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 pi->proto = pr;460 pi->proto = pr;
@@ -464,8 +469,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 8 unmodified lines
464 pi->port = parport->base;469 pi->port = parport->base;
465 470
466 par_cb.private = pi;471 par_cb.private = pi;
467 pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb,472 pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb, id);
468 pi->dev.id);
469 if (!pi->pardev)473 if (!pi->pardev)
470 goto out_module_put;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 pi_connect(pi);492 pi_connect(pi);
489 if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht))493 if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht))
490 goto out_unreg_parport;494 goto out_disconnect;
491 495
492 return pi;496 return pi;
493 497
494out_unreg_parport:498out_disconnect:
495 pi_disconnect(pi);499 pi_disconnect(pi);
500out_unreg_parport:
496 parport_unregister_device(pi->pardev);501 parport_unregister_device(pi->pardev);
497 if (pi->proto->release_proto)502 if (pi->proto->release_proto)
498 pi->proto->release_proto(pi);503 pi->proto->release_proto(pi);
@@ -500,8 +505,7 @@ out_module_put: · 1 unmodified line
500 module_put(pi->proto->owner);505 module_put(pi->proto->owner);
501out_unreg_dev:506out_unreg_dev:
502 device_unregister(&pi->dev);507 device_unregister(&pi->dev);
503out_ida_free:508 /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */
504 ida_free(&pata_parport_bus_dev_ids, pi->dev.id);
505 return NULL;509 return NULL;
506}510}
507 511
@@ -626,8 +630,7 @@ static void pi_remove_one(struct device *dev) · 118 unmodified lines
626 pi_disconnect(pi);630 pi_disconnect(pi);
627 pi_release(pi);631 pi_release(pi);
628 device_unregister(dev);632 device_unregister(dev);
629 ida_free(&pata_parport_bus_dev_ids, dev->id);633 /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */
630 /* pata_parport_dev_release will do kfree(pi) */
631}634}
632 635
633static ssize_t delete_device_store(struct bus_type *bus, const char *buf,636static 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 pi_remove_one(dev);648 pi_remove_one(dev);
649 put_device(dev);
646 mutex_unlock(&pi_mutex);650 mutex_unlock(&pi_mutex);
647 651
648 return count;652 return count;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t