diff mbox series

[v2] USB: serial: mos7720: fix mos_parport refcount imbalance on error path

Message ID 20190320110456.GA5738@163.com (mailing list archive)
State Mainlined
Commit 2908b076f5198d231de62713cb2b633a3a4b95ac
Headers show
Series [v2] USB: serial: mos7720: fix mos_parport refcount imbalance on error path | expand

Commit Message

Nil Yi March 20, 2019, 11:04 a.m. UTC
Johan said that move the kref_get() and mos_parport assignment to the
end of urbtrack initialisation is a better way, so move it. and
mos_parport do not used until urbtrack initialisation.

Signed-off-by: Lin Yi <teroincn@163.com>
---
 drivers/usb/serial/mos7720.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Johan Hovold March 20, 2019, 1:18 p.m. UTC | #1
On Wed, Mar 20, 2019 at 07:04:56PM +0800, Lin Yi wrote:
> Johan said that move the kref_get() and mos_parport assignment to the
> end of urbtrack initialisation is a better way, so move it. and
> mos_parport do not used until urbtrack initialisation.
> 
> Signed-off-by: Lin Yi <teroincn@163.com>
> ---

Thanks for the v2. Now applied with a Fixes and Cc-stable tag and a
slightly updated commit message in order to make it more self-contained:

	https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git/commit/?h=usb-linus&id=2908b076f5198d231de62713cb2b633a3a4b95ac

Johan
diff mbox series

Patch

diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index fc52ac7..18110225 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -366,8 +366,6 @@  static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
 	if (!urbtrack)
 		return -ENOMEM;
 
-	kref_get(&mos_parport->ref_count);
-	urbtrack->mos_parport = mos_parport;
 	urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
 	if (!urbtrack->urb) {
 		kfree(urbtrack);
@@ -388,6 +386,8 @@  static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
 			     usb_sndctrlpipe(usbdev, 0),
 			     (unsigned char *)urbtrack->setup,
 			     NULL, 0, async_complete, urbtrack);
+	kref_get(&mos_parport->ref_count);
+	urbtrack->mos_parport = mos_parport;
 	kref_init(&urbtrack->ref_count);
 	INIT_LIST_HEAD(&urbtrack->urblist_entry);