Commit f900bffe authored by Linus Torvalds's avatar Linus Torvalds

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
parents efbcbb12 5bc9e2d4
...@@ -381,6 +381,7 @@ static void pata_parport_dev_release(struct device *dev) ...@@ -381,6 +381,7 @@ static void pata_parport_dev_release(struct device *dev)
{ {
struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev); struct pi_adapter *pi = container_of(dev, struct pi_adapter, dev);
ida_free(&pata_parport_bus_dev_ids, dev->id);
kfree(pi); kfree(pi);
} }
...@@ -433,23 +434,27 @@ static struct pi_adapter *pi_init_one(struct parport *parport, ...@@ -433,23 +434,27 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev)) if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev))
return NULL; return NULL;
id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
if (id < 0)
return NULL;
pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL); pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL);
if (!pi) if (!pi) {
ida_free(&pata_parport_bus_dev_ids, id);
return NULL; return NULL;
}
/* set up pi->dev before pi_probe_unit() so it can use dev_printk() */ /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */
pi->dev.parent = &pata_parport_bus; pi->dev.parent = &pata_parport_bus;
pi->dev.bus = &pata_parport_bus_type; pi->dev.bus = &pata_parport_bus_type;
pi->dev.driver = &pr->driver; pi->dev.driver = &pr->driver;
pi->dev.release = pata_parport_dev_release; pi->dev.release = pata_parport_dev_release;
id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL);
if (id < 0)
return NULL; /* pata_parport_dev_release will do kfree(pi) */
pi->dev.id = id; pi->dev.id = id;
dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id); dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id);
if (device_register(&pi->dev)) { if (device_register(&pi->dev)) {
put_device(&pi->dev); put_device(&pi->dev);
goto out_ida_free; /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */
return NULL;
} }
pi->proto = pr; pi->proto = pr;
...@@ -464,8 +469,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport, ...@@ -464,8 +469,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
pi->port = parport->base; pi->port = parport->base;
par_cb.private = pi; par_cb.private = pi;
pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb, pi->pardev = parport_register_dev_model(parport, DRV_NAME, &par_cb, id);
pi->dev.id);
if (!pi->pardev) if (!pi->pardev)
goto out_module_put; goto out_module_put;
...@@ -487,12 +491,13 @@ static struct pi_adapter *pi_init_one(struct parport *parport, ...@@ -487,12 +491,13 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
pi_connect(pi); pi_connect(pi);
if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht)) if (ata_host_activate(host, 0, NULL, 0, &pata_parport_sht))
goto out_unreg_parport; goto out_disconnect;
return pi; return pi;
out_unreg_parport: out_disconnect:
pi_disconnect(pi); pi_disconnect(pi);
out_unreg_parport:
parport_unregister_device(pi->pardev); parport_unregister_device(pi->pardev);
if (pi->proto->release_proto) if (pi->proto->release_proto)
pi->proto->release_proto(pi); pi->proto->release_proto(pi);
...@@ -500,8 +505,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport, ...@@ -500,8 +505,7 @@ static struct pi_adapter *pi_init_one(struct parport *parport,
module_put(pi->proto->owner); module_put(pi->proto->owner);
out_unreg_dev: out_unreg_dev:
device_unregister(&pi->dev); device_unregister(&pi->dev);
out_ida_free: /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */
ida_free(&pata_parport_bus_dev_ids, pi->dev.id);
return NULL; return NULL;
} }
...@@ -626,8 +630,7 @@ static void pi_remove_one(struct device *dev) ...@@ -626,8 +630,7 @@ static void pi_remove_one(struct device *dev)
pi_disconnect(pi); pi_disconnect(pi);
pi_release(pi); pi_release(pi);
device_unregister(dev); device_unregister(dev);
ida_free(&pata_parport_bus_dev_ids, dev->id); /* pata_parport_dev_release will do ida_free(dev->id) and kfree(pi) */
/* pata_parport_dev_release will do kfree(pi) */
} }
static ssize_t delete_device_store(struct bus_type *bus, const char *buf, 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, ...@@ -643,6 +646,7 @@ static ssize_t delete_device_store(struct bus_type *bus, const char *buf,
} }
pi_remove_one(dev); pi_remove_one(dev);
put_device(dev);
mutex_unlock(&pi_mutex); mutex_unlock(&pi_mutex);
return count; return count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment