diff mbox

[3/6] g_NCR5380: Check for chip presence before calling NCR5380_init()

Message ID 1477945112-25659-4-git-send-email-linux@rainbow-software.org (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Ondrej Zary Oct. 31, 2016, 8:18 p.m. UTC
Write and read back MODE_REG to check if the chip is really there
before doing more initialization.

This prevents hang when incorrect I/O address was specified by user (in
the most common case where no device is present there so all reads
result in 0xff).

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
---
 drivers/scsi/g_NCR5380.c |    7 +++++++
 1 file changed, 7 insertions(+)

Comments

Finn Thain Nov. 2, 2016, 7:46 a.m. UTC | #1
On Mon, 31 Oct 2016, Ondrej Zary wrote:

> Write and read back MODE_REG to check if the chip is really there
> before doing more initialization.
> 
> This prevents hang when incorrect I/O address was specified by user (in
> the most common case where no device is present there so all reads
> result in 0xff).
> 
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> ---
>  drivers/scsi/g_NCR5380.c |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
> index 0d1f6ad..e713dba 100644
> --- a/drivers/scsi/g_NCR5380.c
> +++ b/drivers/scsi/g_NCR5380.c
> @@ -322,6 +322,13 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
>  		}
>  	}
>  
> +	/* check if the chip is really there */
> +	NCR5380_write(MODE_REG, 0);
> +	if (NCR5380_read(MODE_REG) != 0) {

Wouldn't it be more accurate to write,

	/* Check for some kind of device. A vacant slot reads 0xff. */

?

> +		ret = -ENODEV;
> +		goto out_unregister;
> +	}
> +
>  	ret = NCR5380_init(instance, flags | FLAG_LATE_DMA_SETUP);
>  	if (ret)
>  		goto out_unregister;
>
diff mbox

Patch

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 0d1f6ad..e713dba 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -322,6 +322,13 @@  static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 		}
 	}
 
+	/* check if the chip is really there */
+	NCR5380_write(MODE_REG, 0);
+	if (NCR5380_read(MODE_REG) != 0) {
+		ret = -ENODEV;
+		goto out_unregister;
+	}
+
 	ret = NCR5380_init(instance, flags | FLAG_LATE_DMA_SETUP);
 	if (ret)
 		goto out_unregister;