linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vmbus: use put_device() if device_register fail
@ 2018-03-18  6:48 Arvind Yadav
  2018-03-18 22:37 ` Michael Kelley (EOSG)
  2018-03-19  3:01 ` KY Srinivasan
  0 siblings, 2 replies; 5+ messages in thread
From: Arvind Yadav @ 2018-03-18  6:48 UTC (permalink / raw)
  To: sthemmin, haiyangz; +Cc: devel, linux-kernel

if device_register() returned an error. Always use put_device()
to give up the reference initialized.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
 drivers/hv/vmbus_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index bc65c4d..25da2f3 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device *child_device_obj)
 	ret = device_register(&child_device_obj->device);
 	if (ret) {
 		pr_err("Unable to register child device\n");
+		put_device(&child_device_obj->device);
 		return ret;
 	}
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] vmbus: use put_device() if device_register fail
  2018-03-18  6:48 [PATCH] vmbus: use put_device() if device_register fail Arvind Yadav
@ 2018-03-18 22:37 ` Michael Kelley (EOSG)
  2018-03-19  3:01 ` KY Srinivasan
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Kelley (EOSG) @ 2018-03-18 22:37 UTC (permalink / raw)
  To: Arvind Yadav, Stephen Hemminger, Haiyang Zhang; +Cc: devel, linux-kernel

> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org <linux-kernel-owner@vger.kernel.org> On Behalf
> Of Arvind Yadav
> Sent: Saturday, March 17, 2018 11:48 PM
> To: Stephen Hemminger <sthemmin@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>
> Cc: linux-kernel@vger.kernel.org; devel@linuxdriverproject.org
> Subject: [PATCH] vmbus: use put_device() if device_register fail
> 
> if device_register() returned an error. Always use put_device()
> to give up the reference initialized.
> 
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>

Reviewed-by: Michael Kelley <mikelley@microsoft.com>

> ---
>  drivers/hv/vmbus_drv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index bc65c4d..25da2f3 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device *child_device_obj)
>  	ret = device_register(&child_device_obj->device);
>  	if (ret) {
>  		pr_err("Unable to register child device\n");
> +		put_device(&child_device_obj->device);
>  		return ret;
>  	}
> 
> --
> 2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] vmbus: use put_device() if device_register fail
  2018-03-18  6:48 [PATCH] vmbus: use put_device() if device_register fail Arvind Yadav
  2018-03-18 22:37 ` Michael Kelley (EOSG)
@ 2018-03-19  3:01 ` KY Srinivasan
  2018-03-19  3:40   ` Michael Kelley (EOSG)
  1 sibling, 1 reply; 5+ messages in thread
From: KY Srinivasan @ 2018-03-19  3:01 UTC (permalink / raw)
  To: Arvind Yadav, Stephen Hemminger, Haiyang Zhang; +Cc: devel, linux-kernel



> -----Original Message-----
> From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf
> Of Arvind Yadav
> Sent: Saturday, March 17, 2018 11:48 PM
> To: Stephen Hemminger <sthemmin@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>
> Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] vmbus: use put_device() if device_register fail
> 
> if device_register() returned an error. Always use put_device()
> to give up the reference initialized.
> 
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
>  drivers/hv/vmbus_drv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index bc65c4d..25da2f3 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device
> *child_device_obj)
>  	ret = device_register(&child_device_obj->device);
>  	if (ret) {
>  		pr_err("Unable to register child device\n");
> +		put_device(&child_device_obj->device);

If the registration failed; we would not have acquired the reference on the device and so
we should not be dropping the reference in the failure path.

K. Y
>  		return ret;
>  	}
> 
> --
> 2.7.4
> 
> _______________________________________________
> devel mailing list
> devel@linuxdriverproject.org
> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdriverd
> ev.linuxdriverproject.org%2Fmailman%2Flistinfo%2Fdriverdev-
> devel&data=04%7C01%7Ckys%40microsoft.com%7Caf95bfab917f4e1fa4b008
> d58c9c3b72%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C63656952
> 5011478334%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIj
> oiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-
> 1&sdata=%2FEb%2FMTY2SMh8sY1tar2c8Om2uKPUZAXIUQkrG0q07CA%3D&r
> eserved=0
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] vmbus: use put_device() if device_register fail
  2018-03-19  3:01 ` KY Srinivasan
@ 2018-03-19  3:40   ` Michael Kelley (EOSG)
  2018-03-19  5:52     ` KY Srinivasan
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Kelley (EOSG) @ 2018-03-19  3:40 UTC (permalink / raw)
  To: KY Srinivasan, Arvind Yadav, Stephen Hemminger, Haiyang Zhang
  Cc: devel, linux-kernel

> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org <linux-kernel-owner@vger.kernel.org> On Behalf
> Of KY Srinivasan
> Sent: Sunday, March 18, 2018 8:02 PM
> To: Arvind Yadav <arvind.yadav.cs@gmail.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>
> Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: RE: [PATCH] vmbus: use put_device() if device_register fail
> 
> > -----Original Message-----
> > From: devel <driverdev-devel-bounces@linuxdriverproject.org> On Behalf
> > Of Arvind Yadav
> > Sent: Saturday, March 17, 2018 11:48 PM
> > To: Stephen Hemminger <sthemmin@microsoft.com>; Haiyang Zhang
> > <haiyangz@microsoft.com>
> > Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> > Subject: [PATCH] vmbus: use put_device() if device_register fail
> >
> > if device_register() returned an error. Always use put_device()
> > to give up the reference initialized.
> >
> > Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> > ---
> >  drivers/hv/vmbus_drv.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> > index bc65c4d..25da2f3 100644
> > --- a/drivers/hv/vmbus_drv.c
> > +++ b/drivers/hv/vmbus_drv.c
> > @@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device
> > *child_device_obj)
> >  	ret = device_register(&child_device_obj->device);
> >  	if (ret) {
> >  		pr_err("Unable to register child device\n");
> > +		put_device(&child_device_obj->device);
> 
> If the registration failed; we would not have acquired the reference on the device and so
> we should not be dropping the reference in the failure path.

Looking at the code for device_register() and its constituent parts
device_initialize() and device_add(), Arvind is correct.  device_initialize()
creates the object with a reference count of 1.  device_add() does not
decrement that reference count or free the object, even if it fails.  The
comments for device_register() call this out as well.

Michael  

> 
> K. Y
> >  		return ret;
> >  	}
> >
> > --
> > 2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] vmbus: use put_device() if device_register fail
  2018-03-19  3:40   ` Michael Kelley (EOSG)
@ 2018-03-19  5:52     ` KY Srinivasan
  0 siblings, 0 replies; 5+ messages in thread
From: KY Srinivasan @ 2018-03-19  5:52 UTC (permalink / raw)
  To: Michael Kelley (EOSG), Arvind Yadav, Stephen Hemminger, Haiyang Zhang
  Cc: devel, linux-kernel



> -----Original Message-----
> From: Michael Kelley (EOSG)
> Sent: Sunday, March 18, 2018 8:40 PM
> To: KY Srinivasan <kys@microsoft.com>; Arvind Yadav
> <arvind.yadav.cs@gmail.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>
> Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: RE: [PATCH] vmbus: use put_device() if device_register fail
> 
> > -----Original Message-----
> > From: linux-kernel-owner@vger.kernel.org <linux-kernel-
> owner@vger.kernel.org> On Behalf
> > Of KY Srinivasan
> > Sent: Sunday, March 18, 2018 8:02 PM
> > To: Arvind Yadav <arvind.yadav.cs@gmail.com>; Stephen Hemminger
> > <sthemmin@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>
> > Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> > Subject: RE: [PATCH] vmbus: use put_device() if device_register fail
> >
> > > -----Original Message-----
> > > From: devel <driverdev-devel-bounces@linuxdriverproject.org> On
> Behalf
> > > Of Arvind Yadav
> > > Sent: Saturday, March 17, 2018 11:48 PM
> > > To: Stephen Hemminger <sthemmin@microsoft.com>; Haiyang Zhang
> > > <haiyangz@microsoft.com>
> > > Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> > > Subject: [PATCH] vmbus: use put_device() if device_register fail
> > >
> > > if device_register() returned an error. Always use put_device()
> > > to give up the reference initialized.
> > >
> > > Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> > > ---
> > >  drivers/hv/vmbus_drv.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> > > index bc65c4d..25da2f3 100644
> > > --- a/drivers/hv/vmbus_drv.c
> > > +++ b/drivers/hv/vmbus_drv.c
> > > @@ -1358,6 +1358,7 @@ int vmbus_device_register(struct hv_device
> > > *child_device_obj)
> > >  	ret = device_register(&child_device_obj->device);
> > >  	if (ret) {
> > >  		pr_err("Unable to register child device\n");
> > > +		put_device(&child_device_obj->device);
> >
> > If the registration failed; we would not have acquired the reference on the
> device and so
> > we should not be dropping the reference in the failure path.
> 
> Looking at the code for device_register() and its constituent parts
> device_initialize() and device_add(), Arvind is correct.  device_initialize()
> creates the object with a reference count of 1.  device_add() does not
> decrement that reference count or free the object, even if it fails.  The
> comments for device_register() call this out as well.

Yes; agreed. I will take this patch.

K. Y
> 
> Michael
> 
> >
> > K. Y
> > >  		return ret;
> > >  	}
> > >
> > > --
> > > 2.7.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-19  5:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18  6:48 [PATCH] vmbus: use put_device() if device_register fail Arvind Yadav
2018-03-18 22:37 ` Michael Kelley (EOSG)
2018-03-19  3:01 ` KY Srinivasan
2018-03-19  3:40   ` Michael Kelley (EOSG)
2018-03-19  5:52     ` KY Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).