From: Chandra Seetharaman <[email-masked]>

Do not automatically "select" SCSI_DH for dm-multipath. If SCSI_DH
doesn't exist, just do not allow  hardware handlers to be used.

Handle SCSI_DH being a module also. Make sure it doesn't allow DM_MULTIPATH
to be compiled in when SCSI_DH is a module.

Signed-off-by: Chandra Seetharaman <[email-masked]>
Reported-by: Randy Dunlap <[email-masked]>
Reported-by: Andrew Morton <[email-masked]>
Cc: James Bottomley <[email-masked]>
Cc: Mike Christie <[email-masked]>
Signed-off-by: Alasdair G Kergon <[email-masked]>
Cc: Mike Anderson <[email-masked]>
Cc: Hannes Reinecke <[email-masked]>
Signed-off-by: Andrew Morton <[email-masked]>
---

 drivers/md/Kconfig     |    2 +-
 drivers/md/dm-mpath.c  |    2 ++
 include/scsi/scsi_dh.h |   12 +++++++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff -puN drivers/md/Kconfig~git-scsi-misc-fix-scsi_dh-build-errors drivers/md/Kconfig
--- a/drivers/md/Kconfig~git-scsi-misc-fix-scsi_dh-build-errors
+++ a/drivers/md/Kconfig
@@ -252,7 +252,7 @@ config DM_ZERO
 config DM_MULTIPATH
 	tristate "Multipath target"
 	depends on BLK_DEV_DM
-	select SCSI_DH
+	depends on SCSI_DH || !SCSI_DH
 	---help---
 	  Allow volume managers to support multipath hardware.
 
diff -puN drivers/md/dm-mpath.c~git-scsi-misc-fix-scsi_dh-build-errors drivers/md/dm-mpath.c
--- a/drivers/md/dm-mpath.c~git-scsi-misc-fix-scsi_dh-build-errors
+++ a/drivers/md/dm-mpath.c
@@ -664,6 +664,8 @@ static int parse_hw_handler(struct arg_s
 	request_module("scsi_dh_%s", m->hw_handler_name);
 	if (scsi_dh_handler_exist(m->hw_handler_name) == 0) {
 		ti->error = "unknown hardware handler type";
+		kfree(m->hw_handler_name);
+		m->hw_handler_name = NULL;
 		return -EINVAL;
 	}
 	consume(as, hw_argc - 1);
diff -puN include/scsi/scsi_dh.h~git-scsi-misc-fix-scsi_dh-build-errors include/scsi/scsi_dh.h
--- a/include/scsi/scsi_dh.h~git-scsi-misc-fix-scsi_dh-build-errors
+++ a/include/scsi/scsi_dh.h
@@ -54,6 +54,16 @@ enum {
 	SCSI_DH_NOSYS,
 	SCSI_DH_DRIVER_MAX,
 };
-
+#if defined(CONFIG_SCSI_DH) || defined(CONFIG_SCSI_DH_MODULE)
 extern int scsi_dh_activate(struct request_queue *);
 extern int scsi_dh_handler_exist(const char *);
+#else
+static inline int scsi_dh_activate(struct request_queue *req)
+{
+	return 0;
+}
+static inline int scsi_dh_handler_exist(const char *name)
+{
+	return 0;
+}
+#endif
_