From patchwork Wed Mar 20 11:04:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Yi X-Patchwork-Id: 10861399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 996AB17E0 for ; Wed, 20 Mar 2019 11:05:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DAE829B3C for ; Wed, 20 Mar 2019 11:05:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69FA729B34; Wed, 20 Mar 2019 11:05:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC37129970 for ; Wed, 20 Mar 2019 11:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727174AbfCTLFI (ORCPT ); Wed, 20 Mar 2019 07:05:08 -0400 Received: from m12-17.163.com ([220.181.12.17]:42370 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbfCTLFH (ORCPT ); Wed, 20 Mar 2019 07:05:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=ND/v3 OFKwI0VyHbPIh9TvXC00QrHbOLMYrOH95CHUlA=; b=WH+CuBvBEyJOlAYd7t03w uWJ2EAcNiRWSI0WLLsI9BWJF5il/zzZ4+P7zVCRHBrDbk0xT7Qc3xULXbhRT2vKU R9EBUifWH3av0fFY3VFqtIF2TwlOEgO70gvRdfX9ccvzhQfjhnj05SznXnmIKFMK Wfb5P7NjL/t3jPGN4FSeOI= Received: from tero-machine (unknown [124.16.85.186]) by smtp13 (Coremail) with SMTP id EcCowADHmZNYHpJcw0apLw--.27556S3; Wed, 20 Mar 2019 19:04:57 +0800 (CST) Date: Wed, 20 Mar 2019 19:04:56 +0800 From: Lin Yi To: linux-usb@vger.kernel.org Cc: johan@kernel.org, gregkh@linuxfoundation.org, csong@cs.ucr.edu, zhiyunq@cs.ucr.edu, ljian236@gmail.com, yiqiuping@gmail.com Subject: [PATCH v2] USB: serial: mos7720: fix mos_parport refcount imbalance on error path Message-ID: <20190320110456.GA5738@163.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-CM-TRANSID: EcCowADHmZNYHpJcw0apLw--.27556S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Xw4kZr13Cry5Jr45Zr1xAFb_yoW8Jry5pa 1Yg3yUX3y8JFZ7ur1DX398GF45t3y8tF93uFZFga1Sqw1agFZ8Jw1xGF1DKFs8tr9ruFya qr1jvr4UuFy7Ar7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bx9a9UUUUU= X-Originating-IP: [124.16.85.186] X-CM-SenderInfo: 5whu0xxqfqqiywtou0bp/1tbiShl9ElPADm7G0wAAsa Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/usb/serial/mos7720.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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);