diff mbox

[2/2] libata: Fix NULL pointer of scsi_host in ata_port

Message ID 20140722201109.GN13851@htj.dyndns.org
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Tejun Heo July 22, 2014, 8:11 p.m. UTC
Hello,

Can you please test the following patch?

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Mike Qiu July 23, 2014, 2:29 a.m. UTC | #1
I have tested with the ipr IOA, passed.

Reviewed-and Tested-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>

On 07/23/2014 04:11 AM, Tejun Heo wrote:
> Hello,
>
> Can you please test the following patch?
>
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index d19c37a7..773f4e6 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -4798,9 +4798,8 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
>   static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
>   {
>   	struct ata_queued_cmd *qc = NULL;
> -	unsigned int i, tag, max_queue;
> -
> -	max_queue = ap->scsi_host->can_queue;
> +	unsigned int max_queue = ap->host->n_tags;
> +	unsigned int i, tag;
>
>   	/* no command while frozen */
>   	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
> @@ -6094,6 +6093,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
>   {
>   	spin_lock_init(&host->lock);
>   	mutex_init(&host->eh_mutex);
> +	host->n_tags = ATA_MAX_QUEUE;
>   	host->dev = dev;
>   	host->ops = ops;
>   }
> @@ -6179,11 +6179,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
>   	 * The max queue supported by hardware must not be greater than
>   	 * ATA_MAX_QUEUE.
>   	 */
> -	if (sht->can_queue > ATA_MAX_QUEUE) {
> -		dev_err(host->dev, "BUG: the hardware max queue is too large\n");
> -		WARN_ON(1);
> -		return -EINVAL;
> -	}
> +	host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE);
>
>   	/* host must have been started */
>   	if (!(host->flags & ATA_HOST_STARTED)) {
> diff --git a/include/linux/libata.h b/include/linux/libata.h
> index 5ab4e3a..92abb49 100644
> --- a/include/linux/libata.h
> +++ b/include/linux/libata.h
> @@ -593,6 +593,7 @@ struct ata_host {
>   	struct device 		*dev;
>   	void __iomem * const	*iomap;
>   	unsigned int		n_ports;
> +	unsigned int		n_tags;			/* nr of NCQ tags */
>   	void			*private_data;
>   	struct ata_port_operations *ops;
>   	unsigned long		flags;
>

--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alexey Kardashevskiy July 23, 2014, 9:03 a.m. UTC | #2
On 07/23/2014 06:11 AM, Tejun Heo wrote:
> Hello,
> 
> Can you please test the following patch?

Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>

on POWER8 + IBM IPR SCSI.




> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index d19c37a7..773f4e6 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -4798,9 +4798,8 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
>  static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
>  {
>  	struct ata_queued_cmd *qc = NULL;
> -	unsigned int i, tag, max_queue;
> -
> -	max_queue = ap->scsi_host->can_queue;
> +	unsigned int max_queue = ap->host->n_tags;
> +	unsigned int i, tag;
>  
>  	/* no command while frozen */
>  	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
> @@ -6094,6 +6093,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
>  {
>  	spin_lock_init(&host->lock);
>  	mutex_init(&host->eh_mutex);
> +	host->n_tags = ATA_MAX_QUEUE;
>  	host->dev = dev;
>  	host->ops = ops;
>  }
> @@ -6179,11 +6179,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
>  	 * The max queue supported by hardware must not be greater than
>  	 * ATA_MAX_QUEUE.
>  	 */
> -	if (sht->can_queue > ATA_MAX_QUEUE) {
> -		dev_err(host->dev, "BUG: the hardware max queue is too large\n");
> -		WARN_ON(1);
> -		return -EINVAL;
> -	}
> +	host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE);
>  
>  	/* host must have been started */
>  	if (!(host->flags & ATA_HOST_STARTED)) {
> diff --git a/include/linux/libata.h b/include/linux/libata.h
> index 5ab4e3a..92abb49 100644
> --- a/include/linux/libata.h
> +++ b/include/linux/libata.h
> @@ -593,6 +593,7 @@ struct ata_host {
>  	struct device 		*dev;
>  	void __iomem * const	*iomap;
>  	unsigned int		n_ports;
> +	unsigned int		n_tags;			/* nr of NCQ tags */
>  	void			*private_data;
>  	struct ata_port_operations *ops;
>  	unsigned long		flags;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
Jesse Brandeburg July 24, 2014, 10:29 p.m. UTC | #3
On Wed, Jul 23, 2014 at 2:03 AM, Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
> On 07/23/2014 06:11 AM, Tejun Heo wrote:
>> Hello,
>>
>> Can you please test the following patch?
>
> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>
> on POWER8 + IBM IPR SCSI.

FWIW, I tested Linus's current git tree and the issue is fixed. Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index d19c37a7..773f4e6 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4798,9 +4798,8 @@  void swap_buf_le16(u16 *buf, unsigned int buf_words)
 static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
 {
 	struct ata_queued_cmd *qc = NULL;
-	unsigned int i, tag, max_queue;
-
-	max_queue = ap->scsi_host->can_queue;
+	unsigned int max_queue = ap->host->n_tags;
+	unsigned int i, tag;
 
 	/* no command while frozen */
 	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN))
@@ -6094,6 +6093,7 @@  void ata_host_init(struct ata_host *host, struct device *dev,
 {
 	spin_lock_init(&host->lock);
 	mutex_init(&host->eh_mutex);
+	host->n_tags = ATA_MAX_QUEUE;
 	host->dev = dev;
 	host->ops = ops;
 }
@@ -6179,11 +6179,7 @@  int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
 	 * The max queue supported by hardware must not be greater than
 	 * ATA_MAX_QUEUE.
 	 */
-	if (sht->can_queue > ATA_MAX_QUEUE) {
-		dev_err(host->dev, "BUG: the hardware max queue is too large\n");
-		WARN_ON(1);
-		return -EINVAL;
-	}
+	host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE);
 
 	/* host must have been started */
 	if (!(host->flags & ATA_HOST_STARTED)) {
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 5ab4e3a..92abb49 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -593,6 +593,7 @@  struct ata_host {
 	struct device 		*dev;
 	void __iomem * const	*iomap;
 	unsigned int		n_ports;
+	unsigned int		n_tags;			/* nr of NCQ tags */
 	void			*private_data;
 	struct ata_port_operations *ops;
 	unsigned long		flags;