Commit 1228713c authored by Niklas Cassel's avatar Niklas Cassel

ata: libata-core: Reuse available ata_port print_ids

Currently, the ata_port print_ids are increased indefinitely, even when
there are lower ids available.

E.g. on first boot you will have ata1-ata6 assigned.
After a rmmod + modprobe, you will instead have ata7-ata12 assigned.

Move to use the ida_alloc() API, such that print_ids will get reused.
This means that even after a rmmod + modprobe, the ports will be assigned
print_ids ata1-ata6.
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20240703184418.723066-18-cassel@kernel.orgSigned-off-by: default avatarNiklas Cassel <cassel@kernel.org>
parent 1c1fbb86
...@@ -86,7 +86,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev); ...@@ -86,7 +86,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
static void ata_dev_xfermask(struct ata_device *dev); static void ata_dev_xfermask(struct ata_device *dev);
static unsigned long ata_dev_blacklisted(const struct ata_device *dev); static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
atomic_t ata_print_id = ATOMIC_INIT(0); static DEFINE_IDA(ata_ida);
#ifdef CONFIG_ATA_FORCE #ifdef CONFIG_ATA_FORCE
struct ata_force_param { struct ata_force_param {
...@@ -5463,6 +5463,7 @@ int sata_link_init_spd(struct ata_link *link) ...@@ -5463,6 +5463,7 @@ int sata_link_init_spd(struct ata_link *link)
struct ata_port *ata_port_alloc(struct ata_host *host) struct ata_port *ata_port_alloc(struct ata_host *host)
{ {
struct ata_port *ap; struct ata_port *ap;
int id;
ap = kzalloc(sizeof(*ap), GFP_KERNEL); ap = kzalloc(sizeof(*ap), GFP_KERNEL);
if (!ap) if (!ap)
...@@ -5470,7 +5471,12 @@ struct ata_port *ata_port_alloc(struct ata_host *host) ...@@ -5470,7 +5471,12 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN;
ap->lock = &host->lock; ap->lock = &host->lock;
ap->print_id = atomic_inc_return(&ata_print_id); id = ida_alloc_min(&ata_ida, 1, GFP_KERNEL);
if (id < 0) {
kfree(ap);
return NULL;
}
ap->print_id = id;
ap->host = host; ap->host = host;
ap->dev = host->dev; ap->dev = host->dev;
...@@ -5504,6 +5510,7 @@ void ata_port_free(struct ata_port *ap) ...@@ -5504,6 +5510,7 @@ void ata_port_free(struct ata_port *ap)
kfree(ap->pmp_link); kfree(ap->pmp_link);
kfree(ap->slave_link); kfree(ap->slave_link);
kfree(ap->ncq_sense_buf); kfree(ap->ncq_sense_buf);
ida_free(&ata_ida, ap->print_id);
kfree(ap); kfree(ap);
} }
EXPORT_SYMBOL_GPL(ata_port_free); EXPORT_SYMBOL_GPL(ata_port_free);
......
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