Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2269552pxp; Mon, 21 Mar 2022 15:27:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuAumU56v+HIszjHcdXuvYKJUO84z5DsCd1S7Q7yVblaGGNPgAt8ZUDSccap6qC9iQOA09 X-Received: by 2002:a17:90b:3907:b0:1c6:a16b:12e3 with SMTP id ob7-20020a17090b390700b001c6a16b12e3mr1362873pjb.157.1647901660024; Mon, 21 Mar 2022 15:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647901660; cv=none; d=google.com; s=arc-20160816; b=qbaHYtfBYkUjJ1RSFzzKJwCIp01BQwMkVJ6JuGqoYh6pfqBTr7fZxyIciG6vPLb/+4 8mKdKYxPZ0sMVnlp+ZSGfPs9Yq2CkhGmxE8CijOsWtgPaj/mGYFpXESH9Ue1e1vrSirT sz6TR2Egm4cnZQ7rp47XSepX1EXuI9xXsUXslRcszDvkprT/u2jy9Sy3y7EIUmPShJ1a HhOgcyFxhKEwUxgwFDAMSNYOOmds/KJ0pH8pKehOL5xUqhRsra684bMOF4uVE1WuaMIY 4Ov7CJ4oi1RHFQDhMxfWbvMvO5OPTtZEig+swEO251izBZQ7SZ4khd8xVS7rbnNHzX7Z FENQ== 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=Aa947eg74aUlH3WMbIQ0xncnpRksByiqUN5HVSELZEw=; b=WhZTNc1wGpSspI0hoEHZUT+ei23CZ/XJV2enOvFxAMDUnyWx/hchm/8t6y/0tpSoI3 jD/ukSbIm4iXp97fi94sIuI7ZQbJU3SZ7SdH4nH9Mu+V4WN3bHpLywUwd8oPImjLBO0b WWvyQQ1h/aNdigmCVKCPs5w19UsiqoME1tKp0zoKLlLZzRFCQ/E36WQUX+Z5uExAmpGJ 341yjfhNANIXWU26dH6s/VfDazLuOTF9Uin02lsgb2Z8f9JLsX05WwWP2FpjbZsoqJMy lLWlIRPvNAMds3chgss82SINKxb8UNtSxj6WrSV6zt+Yiyn2K3MU/V1nKeLhriNgvZ2q WmIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Irc7t7Sr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q13-20020a170902b10d00b00153b691f326si11456688plr.364.2022.03.21.15.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:27:40 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Irc7t7Sr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 64A313AE031; Mon, 21 Mar 2022 14:44:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348984AbiCUOGk (ORCPT + 99 others); Mon, 21 Mar 2022 10:06:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348973AbiCUN6p (ORCPT ); Mon, 21 Mar 2022 09:58:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4BF1717A9; Mon, 21 Mar 2022 06:56:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CED88B816D2; Mon, 21 Mar 2022 13:56:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8BD0C340E8; Mon, 21 Mar 2022 13:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647871012; bh=rTpAFxWKjUXl+FS6u1hAIHGN6xs3GKhIshiVpQ53tVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Irc7t7SrXzQ0UNxCyDTNR1BQSkhPNXjy3IbFiqrI2NzqfDOboxVERMh1wCgQEUnGG rWbCA9JWLFmZrWADrWfqJYeF8z/NCkv9NDDLKo8BA9UaUrMjXbctUBIn6QMYJxk1PF eKK6F83G0WDTV7fjKHWHHqPQf29xOzYgifj7InGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 50/57] hv_netvsc: Add check for kvmalloc_array Date: Mon, 21 Mar 2022 14:52:31 +0100 Message-Id: <20220321133223.437365137@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321133221.984120927@linuxfoundation.org> References: <20220321133221.984120927@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Jiasheng Jiang [ Upstream commit 886e44c9298a6b428ae046e2fa092ca52e822e6a ] 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 Link: https://lore.kernel.org/r/20220314020125.2365084-1-jiasheng@iscas.ac.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 2dff0e110c6f..f094e4bc2175 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1454,6 +1454,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.34.1