Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2354342pxb; Mon, 20 Sep 2021 19:53:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9NqJjfAfJLOVHZS+HuPDSwUTXohy93AkRb0l4wZWffwFbm5zzB+rVlxNUgwK4u/uW/jLW X-Received: by 2002:a17:906:a195:: with SMTP id s21mr31313106ejy.181.1632192821969; Mon, 20 Sep 2021 19:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192821; cv=none; d=google.com; s=arc-20160816; b=mffS5BiAcrX2FknaqIYsb/8u6oQVCLEauBRkhN4dwZ16l6x2Mk7TDVGx0a3CCvqGOD +A03Vhu7TPCA34CvNa64NPtVisMP8vLW0c67nD5HVJHKiriE4wI/N6IlvH58PZRkaC5h m+V1CTn6vIRm/IS6iMCDCfUTn4BAMXhZNGdH9N2zfMK7pzsiHF+rznX+M1EYroDhwFOm CKhnRBAIyIDZ6tY/QFsybhy3ATcmHO/U5ceR4/Jo6E1UOW/qIm+qWok85lDK3LZTZRQA VfuGfV1BlWlqdUfBcftCti0MgXedjGFjv2hbSrQsF+rN4yzC0nrlDhvM0od7+9mbo+23 aM1w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/DuEdEDYMS/XnHIKo5yM2kXJdELFetoGid6wHkvrwfE=; b=pke0mib8jj5ykRG7KRbhr0gBkn+Y1//TgxvGS0q7PyoyEw2MPoVfn/bUl6NFPZh2KT RTMXxXNP6tR38fm6XvrUb3aUsRNUsyxPqg+fAMLvBcxgz8nzCCEvHzix1qJVzu14EKCI 9Y+pkuLVErlCjeBdwkJkSDugWcwO5xZ/j+sBF2H+5BWt08nzRj33+wz5AFDcfl9XZ9T9 AT3EBxp0PWQ6r656uZsPDNSLppXq86H0KWJnNcODhsUJp/VepkOrvV6mCE5Fweh56RzZ athGse7HVMAjA6Vy2xZ3jj7aRWjt9ZEo80AtvhKiMn0fBjZfMG6soYORXnyS4oe48sGP ZKSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pta6mxud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si17868839eda.74.2021.09.20.19.53.18; Mon, 20 Sep 2021 19:53:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pta6mxud; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353927AbhITS6M (ORCPT + 99 others); Mon, 20 Sep 2021 14:58:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:33538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354380AbhITSsd (ORCPT ); Mon, 20 Sep 2021 14:48:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E65961B05; Mon, 20 Sep 2021 17:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159263; bh=dTdlqeLs3fUuozx+cOlkj1JCE6L4yePQWB8V3zEFZFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pta6mxudgQI9WtZ5VhgISKVKCbA4LBCJYd+XKSE4TzFe04roYS5esF18B4530k1Eb jRHsIeaLB5TL3HPro99wTzyz8qaEW/PKMCAvPphJM4axTIkDxbBsRpViIcNDhFUQXD 8KvogOTkKZvxePDAx7bDIO9KvOYCEzP2J0ZLfB6A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ziyang Xuan , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 151/168] net: hso: add failure handler for add_net_device Date: Mon, 20 Sep 2021 18:44:49 +0200 Message-Id: <20210920163926.628964227@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ziyang Xuan [ Upstream commit ecdc28defc46af476566fffd9e5cb4495a2f176e ] If the network devices connected to the system beyond HSO_MAX_NET_DEVICES. add_net_device() in hso_create_net_device() will be failed for the network_table is full. It will lead to business failure which rely on network_table, for example, hso_suspend() and hso_resume(). It will also lead to memory leak because resource release process can not search the hso_device object from network_table in hso_free_interface(). Add failure handler for add_net_device() in hso_create_net_device() to solve the above problems. Fixes: 72dc1c096c70 ("HSO: add option hso driver") Signed-off-by: Ziyang Xuan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/hso.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index dec96e8ab567..18e0ca85f653 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2536,13 +2536,17 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, if (!hso_net->mux_bulk_tx_buf) goto err_free_tx_urb; - add_net_device(hso_dev); + result = add_net_device(hso_dev); + if (result) { + dev_err(&interface->dev, "Failed to add net device\n"); + goto err_free_tx_buf; + } /* registering our net device */ result = register_netdev(net); if (result) { dev_err(&interface->dev, "Failed to register device\n"); - goto err_free_tx_buf; + goto err_rmv_ndev; } hso_log_port(hso_dev); @@ -2551,8 +2555,9 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, return hso_dev; -err_free_tx_buf: +err_rmv_ndev: remove_net_device(hso_dev); +err_free_tx_buf: kfree(hso_net->mux_bulk_tx_buf); err_free_tx_urb: usb_free_urb(hso_net->mux_bulk_tx_urb); -- 2.30.2