public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Niklas Cassel <cassel@kernel.org>,
	John Garry <john.g.garry@oracle.com>,
	Jason Yan <yanaijie@huawei.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH v2 05/13] ata,scsi: libata-core: Add ata_port_free()
Date: Thu, 27 Jun 2024 10:15:37 +0900	[thread overview]
Message-ID: <ec3be157-4096-4817-885b-1cb90ca032b2@kernel.org> (raw)
In-Reply-To: <20240626180031.4050226-20-cassel@kernel.org>

On 6/27/24 03:00, Niklas Cassel wrote:
> Add a function, ata_port_free(), that is used to free a ata_port.
> It makes sense to keep the code related to freeing a ata_port in its own
> function, which will also free all the struct members of struct ata_port.
> 
> libsas is currently not freeing all the struct ata_port struct members,
> e.g. ncq_sense_buf for a driver supporting Command Duration Limits (CDL).

This part should be a separate fix patch and sent out this cycle.

> 
> Signed-off-by: Niklas Cassel <cassel@kernel.org>

> @@ -5518,12 +5530,7 @@ static void ata_host_release(struct kref *kref)
>  	for (i = 0; i < host->n_ports; i++) {
>  		struct ata_port *ap = host->ports[i];
>  
> -		if (ap) {
> -			kfree(ap->pmp_link);
> -			kfree(ap->slave_link);
> -			kfree(ap->ncq_sense_buf);
> -			kfree(ap);
> -		}
> +		ata_port_free(ap);

The variable "ap" can be removed too.

>  		host->ports[i] = NULL;
>  	}
>  	kfree(host);

> diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
> index 6e01ddec10c9..951bdc554a10 100644
> --- a/drivers/scsi/libsas/sas_discover.c
> +++ b/drivers/scsi/libsas/sas_discover.c
> @@ -301,7 +301,7 @@ void sas_free_device(struct kref *kref)
>  
>  	if (dev_is_sata(dev) && dev->sata_dev.ap) {
>  		ata_tport_delete(dev->sata_dev.ap);
> -		kfree(dev->sata_dev.ap);
> +		ata_port_free(dev->sata_dev.ap);

Why not have this inside ata_tport_delete() ?

>  		ata_host_put(dev->sata_dev.ata_host);
>  		dev->sata_dev.ata_host = NULL;
>  		dev->sata_dev.ap = NULL;
> diff --git a/include/linux/libata.h b/include/linux/libata.h
> index 581e166615fa..586f0116d1d7 100644
> --- a/include/linux/libata.h
> +++ b/include/linux/libata.h
> @@ -1249,6 +1249,7 @@ extern int ata_slave_link_init(struct ata_port *ap);
>  extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
>  					   struct ata_port_info *, struct Scsi_Host *);
>  extern void ata_port_probe(struct ata_port *ap);
> +extern void ata_port_free(struct ata_port *ap);
>  extern int ata_tport_add(struct device *parent, struct ata_port *ap);
>  extern void ata_tport_delete(struct ata_port *ap);
>  int ata_sas_device_configure(struct scsi_device *sdev, struct queue_limits *lim,

-- 
Damien Le Moal
Western Digital Research


  reply	other threads:[~2024-06-27  1:15 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26 18:00 [PATCH v2 00/13] ata,libsas: Assign the unique id used for printing earlier Niklas Cassel
2024-06-26 18:00 ` [PATCH v2 01/13] ata: libata-core: Fix null pointer dereference on error Niklas Cassel
2024-06-27  1:00   ` Damien Le Moal
2024-06-27  6:24   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 02/13] ata: libata-core: Fix double free " Niklas Cassel
2024-06-27  1:02   ` Damien Le Moal
2024-06-27  6:25   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 03/13] ata: ahci: Clean up sysfs file " Niklas Cassel
2024-06-26 18:34   ` Niklas Cassel
2024-06-27  1:04   ` Damien Le Moal
2024-06-27  6:28   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 04/13] ata,scsi: Remove useless wrappers ata_sas_tport_{add,delete}() Niklas Cassel
2024-06-27  1:07   ` Damien Le Moal
2024-06-27  6:29   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 05/13] ata,scsi: libata-core: Add ata_port_free() Niklas Cassel
2024-06-27  1:15   ` Damien Le Moal [this message]
2024-06-29 12:09     ` Niklas Cassel
2024-06-27  6:30   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 06/13] ata: libata: Remove unused function declaration for ata_scsi_detect() Niklas Cassel
2024-06-27  1:16   ` Damien Le Moal
2024-06-27  6:31   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 07/13] ata: libata-core: Remove support for decreasing the number of ports Niklas Cassel
2024-06-26 19:30   ` Niklas Cassel
2024-06-27  1:30   ` Damien Le Moal
2024-06-27  6:35   ` Hannes Reinecke
2024-06-29 12:24     ` Niklas Cassel
2024-06-26 18:00 ` [PATCH v2 08/13] ata: libata-sata: Remove superfluous assignment in ata_sas_port_alloc() Niklas Cassel
2024-06-27  1:31   ` Damien Le Moal
2024-06-27  6:37   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 09/13] ata: libata-core: Remove local_port_no struct member Niklas Cassel
2024-06-27  1:33   ` Damien Le Moal
2024-06-27  6:37   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 10/13] ata: libata: Assign print_id at port allocation time Niklas Cassel
2024-06-27  6:38   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 11/13] ata: libata-core: Reuse available ata_port print_ids Niklas Cassel
2024-06-27  1:37   ` Damien Le Moal
2024-07-02 15:43     ` Niklas Cassel
2024-06-27  6:39   ` Hannes Reinecke
2024-06-28 16:31   ` kernel test robot
2024-06-28 18:15     ` Niklas Cassel
2024-06-26 18:00 ` [PATCH v2 12/13] ata,scsi: Remove useless ata_sas_port_alloc() wrapper Niklas Cassel
2024-06-27  1:46   ` Damien Le Moal
2024-06-27  9:48     ` Niklas Cassel
2024-06-28  3:46       ` Damien Le Moal
2024-06-27  6:40   ` Hannes Reinecke
2024-06-26 18:00 ` [PATCH v2 13/13] ata: ahci: Add debug print for external port Niklas Cassel
2024-06-27  6:40   ` Hannes Reinecke
2024-06-27 12:26 ` [PATCH v2 00/13] ata,libsas: Assign the unique id used for printing earlier John Garry
2024-06-27 12:32   ` Niklas Cassel
2024-06-27 12:54     ` John Garry
2024-06-27 15:07       ` Niklas Cassel
2024-07-02 15:43         ` Niklas Cassel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec3be157-4096-4817-885b-1cb90ca032b2@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cassel@kernel.org \
    --cc=john.g.garry@oracle.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=yanaijie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox