Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2627167pxp; Mon, 14 Mar 2022 00:58:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQXIGF0WwD6UeL1LcnbSbxYAc7ycxWggDuZP160nGUPCciRB/kVEYIBMH2r/7GGCGesbMU X-Received: by 2002:a05:6a00:2314:b0:4f7:d9a0:3396 with SMTP id h20-20020a056a00231400b004f7d9a03396mr3130437pfh.11.1647244711077; Mon, 14 Mar 2022 00:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647244711; cv=none; d=google.com; s=arc-20160816; b=veN1d4JwElwPcnuT8fGrEnOaqlgSzN+oexfVkhosr4Myu2GAAHx+v1XqTfjR9iO7NN 1JAb/Ij7kyNITeVpfPDYqIAvNgibHZwCuC7xDH55JAEUQl98dZqYldB5sxxQPDhKW0GU rOdHwG00UHMSpCuT2E+7k7d9I7s2p3hfjXdZ+UK8RLaW+GFBT3f6CqBtQijJjbvH1TeK fpNz6GZpUp6J3tgJaUT5LIqnsf0SCngIFVrhSmehVehYymD116qp/R5QTnMZBNIThT/E J0aWBW5bXxnZ1v+aKnpEy9FwUiUVMvxLR+WHxOGECfZU5IE0whEOtq241gkrftwQcIDt H7GA== 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=diZtGVMzrNJXL9FqxJWnelMm+Fn0MfYX+XKUhuVNNIA=; b=w8WsYxQjbvtnbhkk1hdSwJHxXmRPhebZgdxPVyerCjdCjb8IIfnf0ITGneZtBc54rz sOOonZ9TxByOC+FcQMjoHAn7mQNAMdYbBNnsQzn3cOPJb/baeJaX0tRW/9JkVehTk9Eb Y9uRnYIh+1Ji9YaAEREBX2HYQ4GGRPwLDV81wuHjjoZCkV48PkeELZGZdtn7INeJ5GRh RVSaYNwDSrpTQLTPUlrnXhUpIrfiA/vZaHT5qKbV2KLpJchTBVDcJn9EszLCSoo1xfQ1 wGpaBIN5OFBRR6NogdtQK8rakdKJStGn4fUyNakwdNE6b/hDjvw5vG6QJ+YA91w9Jphj C5Ng== 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 h1-20020a17090adb8100b001bedcbec427si11288550pjv.76.2022.03.14.00.58.20; Mon, 14 Mar 2022 00:58:31 -0700 (PDT) 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 S235807AbiCNCDD (ORCPT + 99 others); Sun, 13 Mar 2022 22:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235795AbiCNCCu (ORCPT ); Sun, 13 Mar 2022 22:02:50 -0400 Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E228FDF06; Sun, 13 Mar 2022 19:01:40 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-03 (Coremail) with SMTP id rQCowAAnLsL2oS5iZce+Ag--.26001S2; Mon, 14 Mar 2022 10:01:26 +0800 (CST) From: Jiasheng Jiang To: stephen@networkplumber.org Cc: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, kpsingh@kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] hv_netvsc: Add check for kvmalloc_array Date: Mon, 14 Mar 2022 10:01:25 +0800 Message-Id: <20220314020125.2365084-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAAnLsL2oS5iZce+Ag--.26001S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFW3Jw4xCrW3Wr15tr1fJFb_yoWDZwb_Cr 48urnxur47CryrKF42gFy7Xr9Yyw1qqF1fAFW2qrZxJFy8ArW7Ww1rZrnrXr4fur45uF9x C3ZrAa1Yv39FgjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbS8FF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7Cj xVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wrylc2xSY4AK67AK6r4UMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF 04k26cxKx2IYs7xG6r4j6FyUMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRLNVgUUUUU= X-Originating-IP: [124.16.138.126] 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,T_SCC_BODY_TEXT_LINE 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 the potential failure of the kvmalloc_array(), it should be better to check and restore the 'data' if fails in order to avoid the dereference of the NULL pointer. Fixes: 6ae746711263 ("hv_netvsc: Add per-cpu ethtool stats for netvsc") Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2 * Change 1. Remove the unrolled zero. --- drivers/net/hyperv/netvsc_drv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 3646469433b1..fde1c492ca02 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1587,6 +1587,9 @@ static void netvsc_get_ethtool_stats(struct net_device *dev, pcpu_sum = kvmalloc_array(num_possible_cpus(), sizeof(struct netvsc_ethtool_pcpu_stats), GFP_KERNEL); + if (!pcpu_sum) + return; + netvsc_get_pcpu_stats(dev, pcpu_sum); for_each_present_cpu(cpu) { struct netvsc_ethtool_pcpu_stats *this_sum = &pcpu_sum[cpu]; -- 2.25.1