From: Israel Rukshin <israelr@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/nvme/target/fcloop.c

Change-Id: I0df1f66601895853dd098cdcf774ba69f2812c87
---
 drivers/nvme/target/fcloop.c | 39 ++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

--- a/drivers/nvme/target/fcloop.c
+++ b/drivers/nvme/target/fcloop.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) 2016 Avago Technologies.  All rights reserved.
  */
+
 #ifdef pr_fmt
 #undef pr_fmt
 #endif
@@ -1559,9 +1560,13 @@ static const struct attribute_group *fcl
 	NULL,
 };
 
+#ifdef HAVE_CLASS_REGISTER_GET_CONST
 static const struct class fcloop_class = {
 	.name = "fcloop",
 };
+#else
+static struct class *fcloop_class;
+#endif
 static struct device *fcloop_device;
 
 
@@ -1569,15 +1574,33 @@ static int __init fcloop_init(void)
 {
 	int ret;
 
+#ifdef HAVE_CLASS_REGISTER_GET_CONST
 	ret = class_register(&fcloop_class);
 	if (ret) {
 		pr_err("couldn't register class fcloop\n");
 		return ret;
 	}
+#else
+#ifdef HAVE_CLASS_CREATE_GET_1_PARAM
+	fcloop_class = class_create("fcloop");
+#else
+	fcloop_class = class_create(THIS_MODULE, "fcloop");
+#endif
+	if (IS_ERR(fcloop_class)) {
+		pr_err("couldn't register class fcloop\n");
+		ret = PTR_ERR(fcloop_class);
+		return ret;
+	}
+#endif
 
 	fcloop_device = device_create_with_groups(
-				&fcloop_class, NULL, MKDEV(0, 0), NULL,
-				fcloop_dev_attr_groups, "ctl");
+#ifdef HAVE_CLASS_REGISTER_GET_CONST
+		&fcloop_class,
+#else
+		fcloop_class,
+#endif
+		NULL, MKDEV(0, 0), NULL,
+		fcloop_dev_attr_groups, "ctl");
 	if (IS_ERR(fcloop_device)) {
 		pr_err("couldn't create ctl device!\n");
 		ret = PTR_ERR(fcloop_device);
@@ -1589,7 +1612,11 @@ static int __init fcloop_init(void)
 	return 0;
 
 out_destroy_class:
+#ifdef HAVE_CLASS_REGISTER_GET_CONST
 	class_unregister(&fcloop_class);
+#else
+	class_unregister(fcloop_class);
+#endif
 	return ret;
 }
 
@@ -1647,8 +1674,13 @@ static void __exit fcloop_exit(void)
 
 	put_device(fcloop_device);
 
+#ifdef HAVE_CLASS_REGISTER_GET_CONST
 	device_destroy(&fcloop_class, MKDEV(0, 0));
 	class_unregister(&fcloop_class);
+#else
+	device_destroy(fcloop_class, MKDEV(0, 0));
+	class_unregister(fcloop_class);
+#endif
 }
 
 module_init(fcloop_init);
@@ -1656,3 +1688,6 @@ module_exit(fcloop_exit);
 
 MODULE_DESCRIPTION("NVMe target FC loop transport driver");
 MODULE_LICENSE("GPL v2");
+#ifdef RETPOLINE_MLNX
+MODULE_INFO(retpoline, "Y");
+#endif
