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
381381 {
382382 struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
383383
384+ ida_free(&pata_parport_bus_dev_ids, dev->id);
384385 kfree(pi);
385386 }
386387
@@ -433,23 +434,27 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 46 unmodified lines
433434 if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev))
434435 return NULL;
435436
437+ id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
438+ if (id < 0)
439+ return NULL;
440+
436441 pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);
437− if (!pi)
442+ if (!pi) {
443+ ida_free(&pata_parport_bus_dev_ids, id);
438444 return NULL;
445+ }
439446
440447 /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
441448 pi->dev.parent = &pata_parport_bus;
442449 pi->dev.bus = &pata_parport_bus_type;
443450 pi->dev.driver = &pr->driver;
444451 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) */
448452 pi->dev.id = id;
449453 dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
450454 if (device_register(&pi->dev)) {
451455 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;
453458 }
454459
455460 pi->proto = pr;
@@ -464,8 +469,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 8 unmodified lines
464469 pi->port = parport->base;
465470
466471 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);
469473 if (!pi->pardev)
470474 goto out_module_put;
471475
@@ -487,12 +491,13 @@ static struct pi_adapter *pi_init_one(struct parport *parport, · 15 unmodified lines
487491
488492 pi_connect(pi);
489493 if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht))
490− goto out_unreg_parport;
494+ goto out_disconnect;
491495
492496 return pi;
493497
494−out_unreg_parport:
498+out_disconnect:
495499 pi_disconnect(pi);
500+out_unreg_parport:
496501 parport_unregister_device(pi->pardev);
497502 if (pi->proto->release_proto)
498503 pi->proto->release_proto(pi);
@@ -500,8 +505,7 @@ out_module_put: · 1 unmodified line
500505 module_put(pi->proto->owner);
501506 out_unreg_dev:
502507 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) */
505509 return NULL;
506510 }
507511
@@ -626,8 +630,7 @@ static void pi_remove_one(struct device *dev) · 118 unmodified lines
626630 pi_disconnect(pi);
627631 pi_release(pi);
628632 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) */
631634 }
632635
633636 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
643646 }
644647
645648 pi_remove_one(dev);
649+ put_device(dev);
646650 mutex_unlock(&pi_mutex);
647651
648652 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