Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1548744 > unrolled thread

[PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()

Started byAlexey Khoroshilov <khoroshilov@ispras.ru>
First post2016-12-30 23:50 +0100
Last post2016-12-30 23:50 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init() Alexey Khoroshilov <khoroshilov@ispras.ru> - 2016-12-30 23:50 +0100

#1548744 — [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()

FromAlexey Khoroshilov <khoroshilov@ispras.ru>
Date2016-12-30 23:50 +0100
Subject[PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()
Message-ID<sUe9Q-1Z2-3@gated-at.bofh.it>
If class_create() or mdev_register_device() fail, mtty_dev_init()
breaks off initialization, deallocates all resources, but returns zero.

The patch adds proper error code return values.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 samples/vfio-mdev/mtty.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 6b633a4ea333..e9c52e1f97a6 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1446,6 +1446,7 @@ static int __init mtty_dev_init(void)
 	mtty_dev.vd_class = class_create(THIS_MODULE, MTTY_CLASS_NAME);
 
 	if (IS_ERR(mtty_dev.vd_class)) {
+		ret = PTR_ERR(mtty_dev.vd_class);
 		pr_err("Error: failed to register mtty_dev class\n");
 		goto failed1;
 	}
@@ -1458,7 +1459,8 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	if (mdev_register_device(&mtty_dev.dev, &mdev_fops) != 0)
+	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	if (ret)
 		goto failed3;
 
 	mutex_init(&mdev_list_lock);
@@ -1467,11 +1469,9 @@ static int __init mtty_dev_init(void)
 	goto all_done;
 
 failed3:
-
 	device_unregister(&mtty_dev.dev);
 failed2:
 	class_destroy(mtty_dev.vd_class);
-
 failed1:
 	cdev_del(&mtty_dev.vd_cdev);
 	unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK);
-- 
2.7.4

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web