Skip to content

Commit 23262cc

Browse files
committed
ata: libata-core: Remove support for decreasing the number of ports
Commit f318719 ("libata: separate out ata_host_alloc() and ata_host_register()") added ata_host_alloc(), where the API allowed a LLD to overallocate the number of ports supplied to ata_host_alloc(), as long as the LLD decreased host->n_ports before calling ata_host_register(). However, this functionally has never ever been used by a single LLD. Because of the current API design, the assignment of ap->print_id is deferred until registration time, which is bad, because that means that the ata_port_*() print functions cannot be used by a LLD until after registration time, which means that a LLD is forced to use a print function that is non-port specific, even for a port specific error. Remove the support for decreasing the number of ports, such that it will be possible to assign ap->print_id earlier. Reviewed-by: Damien Le Moal <[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 2199d6f commit 23262cc

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

drivers/ata/libata-core.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5555,32 +5555,27 @@ EXPORT_SYMBOL_GPL(ata_host_put);
55555555
/**
55565556
* ata_host_alloc - allocate and init basic ATA host resources
55575557
* @dev: generic device this host is associated with
5558-
* @max_ports: maximum number of ATA ports associated with this host
5558+
* @n_ports: the number of ATA ports associated with this host
55595559
*
55605560
* Allocate and initialize basic ATA host resources. LLD calls
55615561
* this function to allocate a host, initializes it fully and
55625562
* attaches it using ata_host_register().
55635563
*
5564-
* @max_ports ports are allocated and host->n_ports is
5565-
* initialized to @max_ports. The caller is allowed to decrease
5566-
* host->n_ports before calling ata_host_register(). The unused
5567-
* ports will be automatically freed on registration.
5568-
*
55695564
* RETURNS:
55705565
* Allocate ATA host on success, NULL on failure.
55715566
*
55725567
* LOCKING:
55735568
* Inherited from calling layer (may sleep).
55745569
*/
5575-
struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5570+
struct ata_host *ata_host_alloc(struct device *dev, int n_ports)
55765571
{
55775572
struct ata_host *host;
55785573
size_t sz;
55795574
int i;
55805575
void *dr;
55815576

55825577
/* alloc a container for our list of ATA ports (buses) */
5583-
sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *);
5578+
sz = sizeof(struct ata_host) + n_ports * sizeof(void *);
55845579
host = kzalloc(sz, GFP_KERNEL);
55855580
if (!host)
55865581
return NULL;
@@ -5600,11 +5595,11 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
56005595
spin_lock_init(&host->lock);
56015596
mutex_init(&host->eh_mutex);
56025597
host->dev = dev;
5603-
host->n_ports = max_ports;
5598+
host->n_ports = n_ports;
56045599
kref_init(&host->kref);
56055600

56065601
/* allocate ports bound to this host */
5607-
for (i = 0; i < max_ports; i++) {
5602+
for (i = 0; i < n_ports; i++) {
56085603
struct ata_port *ap;
56095604

56105605
ap = ata_port_alloc(host);
@@ -5913,13 +5908,6 @@ int ata_host_register(struct ata_host *host, const struct scsi_host_template *sh
59135908
return -EINVAL;
59145909
}
59155910

5916-
/* Blow away unused ports. This happens when LLD can't
5917-
* determine the exact number of ports to allocate at
5918-
* allocation time.
5919-
*/
5920-
for (i = host->n_ports; host->ports[i]; i++)
5921-
ata_port_free(host->ports[i]);
5922-
59235911
/* give ports names and add SCSI hosts */
59245912
for (i = 0; i < host->n_ports; i++) {
59255913
host->ports[i]->print_id = atomic_inc_return(&ata_print_id);

include/linux/libata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
10691069
unsigned long deadline);
10701070
extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
10711071

1072-
extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
1072+
extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports);
10731073
extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
10741074
const struct ata_port_info * const * ppi, int n_ports);
10751075
extern void ata_host_get(struct ata_host *host);

0 commit comments

Comments
 (0)