Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2678881pxp; Mon, 14 Mar 2022 02:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn8xNzKpHLKVNCoRjBz6x1PiyvXpFCSiyODaTmK+VOxzxbF/mBipPMFi5/fmnvq/xO8cAA X-Received: by 2002:a05:6402:4301:b0:418:585b:cfe1 with SMTP id m1-20020a056402430100b00418585bcfe1mr9915019edc.250.1647250192723; Mon, 14 Mar 2022 02:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647250192; cv=none; d=google.com; s=arc-20160816; b=XXvxUkJTmriuJCWOf3/Itis21hts5sCA0tsGexdpEhf81yTNjsiLzVyZzsAP3EpP28 WMfWjAER/lojdu/F4RL0AHQFYc9MqUgFQFd58/rh2c03rzQB0GPZPsWsHAQqw/phi44+ MyR2gE1xSTft1s/MYwi5n2Z8xB0vzpMATnki7ddFCsrWQ+XEsqWSgpOsTKVu044CbM2R WlRd0WGyugAKJWMsT/0KQxMOw2DV2xUEAFg8Gdyy7Ynxe2oxaUs2Ti8c05W/EtmOfD3y TiNbAYaikqUvPf55LXuf4dlbc6DZduscgbELcB3zb31ODLYO/0Dn9cmE/QdVGrJ80xDF moaA== 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=t7aCkStPuFb3pNd6EkIj1GF7o2vI7Au+iPyJwPEXbTBs8JhyG7Nn5oz9C2xZrOJ9r6 OrSnHQUPwsvbC497jn2WM7SEpsqx3OmZjLsulXEhSwxGnMBzPwQVGZcnhC5+44Wo3Qsi kB+FmeBVRC3WpTuZ11BZmfhmYkUaL2ylhmDpPtUwo3hXM8x90ZIocb+KlT3sSsCLV24A AbX6RgDkLUJpTI+71AA5wAwRfscAvk/r54kcgmLENZMIY9kMO8WAKbV6hnijlfxpsC5u qtGnAwnywk8R8gdRKd/DpGUClFcpqueoA15rhB5/XRGW4aCJhv0YIoH4401O+KYKudCY F/7g== 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 b8-20020a056402084800b004169f49cf79si10777570edz.191.2022.03.14.02.29.28; Mon, 14 Mar 2022 02:29:52 -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 S235787AbiCNCCE (ORCPT + 99 others); Sun, 13 Mar 2022 22:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbiCNCCC (ORCPT ); Sun, 13 Mar 2022 22:02:02 -0400 X-Greylist: delayed 274 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 13 Mar 2022 19:00:52 PDT Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 018B4DF06; Sun, 13 Mar 2022 19:00:52 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-03 (Coremail) with SMTP id rQCowAD3_8PIoS5iA8O+Ag--.25406S2; Mon, 14 Mar 2022 10:00:40 +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: [PATCHi v2] hv_netvsc: Add check for kvmalloc_array Date: Mon, 14 Mar 2022 10:00:39 +0800 Message-Id: <20220314020039.2365031-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAD3_8PIoS5iA8O+Ag--.25406S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKFW3Jw4xCrW3Wr15tr1fJFb_yoWDZwb_Cr 48urnxur47CryrKF42gFy7Xr9Yyw1qqF1fAFW2qrZxJFy8ArW7Ww1rZrnrXr4fur45uF9x C3ZrAa1Yv39FgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb3kFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7Cj xVA2Y2ka0xkIwI1lc2xSY4AK67AK6r4UMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Zr0_Wr1U MIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIda VFxhVjvjDU0xZFpf9x0JUWSoXUUUUU= 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