Skip to content

Commit 1228713

Browse files
committed
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: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]>
1 parent 1c1fbb8 commit 1228713

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/ata/libata-core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
8686
static void ata_dev_xfermask(struct ata_device *dev);
8787
static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
8888

89-
atomic_t ata_print_id = ATOMIC_INIT(0);
89+
static DEFINE_IDA(ata_ida);
9090

9191
#ifdef CONFIG_ATA_FORCE
9292
struct ata_force_param {
@@ -5463,14 +5463,20 @@ int sata_link_init_spd(struct ata_link *link)
54635463
struct ata_port *ata_port_alloc(struct ata_host *host)
54645464
{
54655465
struct ata_port *ap;
5466+
int id;
54665467

54675468
ap = kzalloc(sizeof(*ap), GFP_KERNEL);
54685469
if (!ap)
54695470
return NULL;
54705471

54715472
ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN;
54725473
ap->lock = &host->lock;
5473-
ap->print_id = atomic_inc_return(&ata_print_id);
5474+
id = ida_alloc_min(&ata_ida, 1, GFP_KERNEL);
5475+
if (id < 0) {
5476+
kfree(ap);
5477+
return NULL;
5478+
}
5479+
ap->print_id = id;
54745480
ap->host = host;
54755481
ap->dev = host->dev;
54765482

@@ -5504,6 +5510,7 @@ void ata_port_free(struct ata_port *ap)
55045510
kfree(ap->pmp_link);
55055511
kfree(ap->slave_link);
55065512
kfree(ap->ncq_sense_buf);
5513+
ida_free(&ata_ida, ap->print_id);
55075514
kfree(ap);
55085515
}
55095516
EXPORT_SYMBOL_GPL(ata_port_free);

0 commit comments

Comments
 (0)