Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6870798rwb; Mon, 5 Dec 2022 20:04:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf5gwzmL6GNrJf/QTQcm7MD3N6l8TA9Bo3oKy5HMxWI7NC1VYsF3fYhomAYT4xYXweILXoCi X-Received: by 2002:a17:90b:3c91:b0:219:da8f:c6f0 with SMTP id pv17-20020a17090b3c9100b00219da8fc6f0mr7291744pjb.1.1670299445001; Mon, 05 Dec 2022 20:04:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670299444; cv=none; d=google.com; s=arc-20160816; b=I9e4WNchtX9WBeIrFzw0+o5ge3s9Z2ct83ZYLZhFP1RdSQqiK1bHz1Fh2IMfz3Iir3 ETQ9fctdO3vmkfdEkRF33hXeWE+f7/z9ovBdzcvPUGMIpMeeFu4tL8Csze1/NhCoXTif bjWN1yfNxmW2FHw7u5A/GGi3EQniIS/40neLCQ99rlqKYswENrgi3J5n1imDvShZfvip mQgf8fJGibAc09/Bqi3DhtfOlH3hEqC2Hd4gfjGqUzvOzHVR60y8FLBnpf68Dqt5A5fM +VXAsIHQkb3u/gnt438NgiNPc0RkiFw01ZWwAnnxtF/fvmKPpK1tKlGREX2ow2Zexw/m iu5w== 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=qK5HujBqOFXbRT0eGmwtqV9kj1UtkZ7ztR+NTIIK76U=; b=vylhtgKxkp2gmAuhqtdI6grHEF8bZLYh6yIl+16q8vaCCSK1OwyNcxG4O5MWG/2Kbe hUqvA1IX/mpbtTdRz6NWNjjCgxSZ3TFbtCfYQ+cPxxxjwkefBnRUssHFs+Y5oWTHrevf oAKSATY0FKjArx51DaoaXl8W7x0aqV5tJ3hT7qDWKnBoWGYxSqCROdYFRYTjdWG7D09S dRKwuIyOG8q4Sq78TkxgWz/kohYzPbK46HvMsFuACIjNI7iXWaSF5sXooZYgZwjlA/xG GuGJj/zEMYH4ZF4mi3lZyR+zqDElx2dCeSBlWkbxDjYbR1Jd6SOSmxYsU/J6bvYokjPS Dk0w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y65-20020a638a44000000b00476990d057asi5261772pgd.472.2022.12.05.20.03.51; Mon, 05 Dec 2022 20:04:04 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233748AbiLFDI1 (ORCPT + 79 others); Mon, 5 Dec 2022 22:08:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbiLFDIZ (ORCPT ); Mon, 5 Dec 2022 22:08:25 -0500 Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7D8BD640C; Mon, 5 Dec 2022 19:08:21 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-03 (Coremail) with SMTP id rQCowABXX5cWso5jFUbkBA--.26373S2; Tue, 06 Dec 2022 11:08:06 +0800 (CST) From: Jiasheng Jiang To: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH net] ice: Add check for kzalloc Date: Tue, 6 Dec 2022 11:08:05 +0800 Message-Id: <20221206030805.15934-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowABXX5cWso5jFUbkBA--.26373S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFWrur4rKw1fKF4DGw4fuFg_yoW8Xr4rpa n8JFyjvrW8Jr4UWr9xXF4qyFZ8Wa4xJ34Sga9rX398ZF1Dtr15t3WDKryYyr1rGrW3ZFsI yF45AF13uF92vw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxa n2IY04v7MxkIecxEwVAFwVW8GwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnU UI43ZEXa7VUjQBMtUUUUU== X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,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 As kzalloc may fail and return NULL pointer, it should be better to check the return value in order to avoid the NULL pointer dereference. Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY") Signed-off-by: Jiasheng Jiang --- drivers/net/ethernet/intel/ice/ice_gnss.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c index b5a7f246d230..6d3d5e75726b 100644 --- a/drivers/net/ethernet/intel/ice/ice_gnss.c +++ b/drivers/net/ethernet/intel/ice/ice_gnss.c @@ -421,7 +421,7 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf) const int ICE_TTYDRV_NAME_MAX = 14; struct tty_driver *tty_driver; char *ttydrv_name; - unsigned int i; + unsigned int i, j; int err; tty_driver = tty_alloc_driver(ICE_GNSS_TTY_MINOR_DEVICES, @@ -462,6 +462,17 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf) GFP_KERNEL); pf->gnss_serial[i] = NULL; + if (!pf->gnss_tty_port[i]) { + for (j = 0; j < i; j++) { + tty_port_destroy(pf->gnss_tty_port[j]); + kfree(pf->gnss_tty_port[j]); + } + kfree(ttydrv_name); + tty_driver_kref_put(pf->ice_gnss_tty_driver); + + return NULL; + } + tty_port_init(pf->gnss_tty_port[i]); tty_port_link_device(pf->gnss_tty_port[i], tty_driver, i); } -- 2.25.1