Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2875558rwb; Sun, 20 Nov 2022 03:23:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf5MKikuLnXMHx5CGkVgFpSIAgK4Qpx8C0MtZrZl9A7KsSKnY4WCUMEJtucQc/+0HeyIKI39 X-Received: by 2002:a05:6402:1243:b0:469:147e:3f0 with SMTP id l3-20020a056402124300b00469147e03f0mr4020946edw.404.1668943438887; Sun, 20 Nov 2022 03:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668943438; cv=none; d=google.com; s=arc-20160816; b=WnR1F4BYmTIsJiL2rtUfCiNxEKs6YKKlIvG/B6REboT1EGDnazVnR/5csvKOxFkgPv aREM3WWQhoU8SSWhlYOi4P3PfvA5dACumygE/paetWBX7we+mMMPOeOlLvd2ljie3Sxc J6fZ1WFwmrKgpoPPw4otMWj7PV9uKR0QdU9n3kFjYfLlK+pBarIQYcaPBYF71uWhZc5R h5bpCaj85kCXdZVzDlfyOTFFhzJ9Aiw8ToDuJWgMI87y1rJGZPWR0IINSni1rysjQ9D5 HgE6OeyZ7O6BxtNhIC+y85xHwMP/hT6F1xqe3rqKTLcV8ZooeiyRSnvB/cpFQkNWJNz2 W3Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AlZgyGzJSksbiSVnwu7EnHZCXOjLRMJSW611pKd6AVw=; b=Y4A+iwqrbqfcVWikMWEm9EatUC1rObQhuBR7bL8l/uuV4mdIVTGhcCH/89GPUq4Iws FtVA0X4Yoe2oPD8oUr8e1hDvH7P7176hScysIVs7mt/J427QopOnYvSz4PD4ORHJ+4bq 15kU2Q1qMpXK1SjIp+7axpCGWatj1X4iBgYzQhWQfZ1ma7cDf+Pn604rEb/2M8oqcs35 lLi+ZpAuHFzaeFk8chk3GwmuWuyfsW7mG5aQaEyIo1AsscZWDN8+vB5dQEjx6cGJgFRG fp4TiPvXjo306k5ZTgm27XOnYx7cd2VxcSz7C+YMnpgcd0AX4xiPnHJlxONNODbJpBwx xKgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Kwm7NayB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp17-20020a170906c15100b007ae8b1704d0si7421561ejc.68.2022.11.20.03.23.34; Sun, 20 Nov 2022 03:23:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Kwm7NayB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229652AbiKTKPP (ORCPT + 91 others); Sun, 20 Nov 2022 05:15:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiKTKPN (ORCPT ); Sun, 20 Nov 2022 05:15:13 -0500 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5DCD41D336; Sun, 20 Nov 2022 02:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=AlZgy GzJSksbiSVnwu7EnHZCXOjLRMJSW611pKd6AVw=; b=Kwm7NayBh3mQjmPLXeDOy miId3jIeCSmEC078Ebg7vopeSk7l6D5eOHQX4eVjz11QAkECDbZNVsJjHg2XugCV 9bHRjNr2TvUzfuZPGH5Gv2aFI3r2glHy7HPK8nptadliwquPnbcA2S1t5CxpCopg Zcn0ItMaYuslY5nLPeZk0U= Received: from localhost.localdomain (unknown [36.112.3.106]) by smtp2 (Coremail) with SMTP id GtxpCgCnIgz4_XljPtHttg--.23124S4; Sun, 20 Nov 2022 18:14:24 +0800 (CST) From: Jianglei Nie To: yashi@spacecubics.com, wg@grandegger.com, mkl@pengutronix.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mailhol.vincent@wanadoo.fr, stefan.maetje@esd.eu, socketcan@hartkopp.net, hbh25y@gmail.com Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] can: mcba_usb: fix potential resource leak in mcba_usb_xmit_cmd() Date: Sun, 20 Nov 2022 18:14:14 +0800 Message-Id: <20221120101414.6071-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgCnIgz4_XljPtHttg--.23124S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7XFy7ZF13Jr1DWFy3ur1fXrb_yoWDCFX_K3 y7Gry8WayUJrn09w18K3yxJ34FywsrZr4kuFs3t343JFW2ya18JFnFgr9rGr1ruw4aqa9x CwnrZF1DJw4SvjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRisXo5UUUUU== X-Originating-IP: [36.112.3.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiWwC-jGI0XGfXSAAAsa X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org mcba_usb_xmit_cmd() gets free ctx by mcba_usb_get_free_ctx(). When mcba_usb_xmit() fails, the ctx should be freed with mcba_usb_free_ctx() like mcba_usb_start_xmit() does in label "xmit_failed" to avoid potential resource leak. Fix it by calling mcba_usb_free_ctx() when mcba_usb_xmit() fails. Signed-off-by: Jianglei Nie --- drivers/net/can/usb/mcba_usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 218b098b261d..471f6be6e030 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -380,9 +380,11 @@ static void mcba_usb_xmit_cmd(struct mcba_priv *priv, } err = mcba_usb_xmit(priv, usb_msg, ctx); - if (err) + if (err) { + mcba_usb_free_ctx(ctx); netdev_err(priv->netdev, "Failed to send cmd (%d)", usb_msg->cmd_id); + } } static void mcba_usb_xmit_change_bitrate(struct mcba_priv *priv, u16 bitrate) -- 2.25.1