Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp188465pxb; Thu, 2 Sep 2021 01:44:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmt48o0dmmlw5ctYHVAJndZVS3ka5n2C0xtH4NMM778n6MyBuJKAniANR4aKzs0npaA1Pe X-Received: by 2002:a17:906:4346:: with SMTP id z6mr2499936ejm.403.1630572252834; Thu, 02 Sep 2021 01:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630572252; cv=none; d=google.com; s=arc-20160816; b=fKf3AsN8m+TaYNS3Ri4pX91/xfcabr018zzURMH7JCENKeEl7wwN4VOR9zonuOa+Qy 0NAsV1BkuaovcAhlUol9aEdjv9GqEDcck7P5AGzJMkeGwgOaTOutKmRhKTqgKPm/xEYf c5R+dj1gBJ4T0Ib1HPR0VQVzYI6xHf0x15Zmjveo60u6XROc0PFmdX0gbXtvKRk5Vbl8 BGYuV20JIzuS/6De0X0nB1IE0Ek2Ti9BCoBQS8SmTkNc699wqO6+NykgiMyt0Nz2PEDU +2xc86KoPlFsgsQcpir94f7USDiMjFf5qHhYtZuz2o01s29sTXcDWlGXyILYK4a/a48T JfSQ== 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; bh=GLWR0epnJfNmNeF7kRQp8P84FKuotOEfsxdLfV6PoBA=; b=se+JwfkvdE9kTe2jkuCrZBYYAmrvqkEaGS0YsGgjJbYyOuoWDt4LoR5/N8wQMr/j9S 43s3lH4f6c0MqSqi4UUkhO9IJ2CyLOxHu5FDRtxsLTIO8tPBbt1FiDQZ/gmBWt9SBsjb qeg1YTll0aX7sVOLDp0Fd2XID4Aw0TSuj5cLpLw/gFjFMQgAGIQoABEET6/GBPvg4lRp 5ANcl2drllYJ3A9aRKMJB/b2tahpWmK6l7TSZJl+0TZWfct8ZmnYpVirEXbak7cBCoF+ WWGxRwecD6jQLuZUQ/P28Wh9I2vJFZSS6ivHWJIcGaSFPz7LP+AqS0o8meBPOYQSeR+O Qz6A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm12si1170928ejc.744.2021.09.02.01.43.37; Thu, 02 Sep 2021 01:44:12 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244583AbhIBIh6 (ORCPT + 99 others); Thu, 2 Sep 2021 04:37:58 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:15283 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244392AbhIBIh5 (ORCPT ); Thu, 2 Sep 2021 04:37:57 -0400 Received: from dggeml757-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H0Z5s6C98z8Cj6; Thu, 2 Sep 2021 16:36:33 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by dggeml757-chm.china.huawei.com (10.1.199.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 2 Sep 2021 16:36:56 +0800 From: Ziyang Xuan To: CC: , , , , , Subject: [PATCH net] net: hso: add failure handler for add_net_device Date: Thu, 2 Sep 2021 16:36:09 +0800 Message-ID: <20210902083609.1679146-1-william.xuanziyang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeml757-chm.china.huawei.com (10.1.199.137) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 24bc1e678b7b..422a07fd8814 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2535,13 +2535,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); @@ -2550,8 +2554,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.25.1