* [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()
@ 2016-12-30 22:40 Alexey Khoroshilov
2017-01-04 12:22 ` Kirti Wankhede
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Khoroshilov @ 2016-12-30 22:40 UTC (permalink / raw)
To: Kirti Wankhede, Neo Jia
Cc: Alexey Khoroshilov, Alex Williamson, kvm, linux-kernel, ldv-project
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()
2016-12-30 22:40 [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init() Alexey Khoroshilov
@ 2017-01-04 12:22 ` Kirti Wankhede
2017-01-04 15:30 ` Alex Williamson
0 siblings, 1 reply; 3+ messages in thread
From: Kirti Wankhede @ 2017-01-04 12:22 UTC (permalink / raw)
To: Alexey Khoroshilov, Neo Jia, Alex Williamson
Cc: kvm, linux-kernel, ldv-project
Dan Carpenter had sent similar change earlier.
https://www.spinics.net/lists/kvm/msg141470.html
Alex,
Did you pull that change in your tree?
Thanks,
Kirti
On 12/31/2016 4:10 AM, Alexey Khoroshilov wrote:
> 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);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init()
2017-01-04 12:22 ` Kirti Wankhede
@ 2017-01-04 15:30 ` Alex Williamson
0 siblings, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2017-01-04 15:30 UTC (permalink / raw)
To: Kirti Wankhede
Cc: Alexey Khoroshilov, Neo Jia, kvm, linux-kernel, ldv-project,
Dan Carpenter
On Wed, 4 Jan 2017 17:52:30 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:
> Dan Carpenter had sent similar change earlier.
> https://www.spinics.net/lists/kvm/msg141470.html
>
> Alex,
> Did you pull that change in your tree?
I had somehow missed Dan's patch. I'll apply Dan's with a Reported-by
credit for Alexey as well. Thanks,
Alex
> On 12/31/2016 4:10 AM, Alexey Khoroshilov wrote:
> > 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);
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-04 15:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-30 22:40 [PATCH] samples/vfio-mdev: don't return zero on failure paths in mtty_dev_init() Alexey Khoroshilov
2017-01-04 12:22 ` Kirti Wankhede
2017-01-04 15:30 ` Alex Williamson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.