Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1615873pxb; Mon, 11 Oct 2021 09:32:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn85bWfYZWPLTkzmst1CcKmJGfbg5SPitPHj6lbK2E2Ws2M5ffcOwcjNSGU1+uVeBTPZHz X-Received: by 2002:a17:902:d2cd:b0:13f:14dd:aeff with SMTP id n13-20020a170902d2cd00b0013f14ddaeffmr19910958plc.67.1633969964838; Mon, 11 Oct 2021 09:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969964; cv=none; d=google.com; s=arc-20160816; b=EnLf/AtyDgjgnDG8ZByeF/8RJtlUQorisk1tf5m6RpAiyQcqtR/FiWaRXs8JrhVQFV BGUumPiaY6PnDshU/pBjMYKJPuDMUHSZmwdVPDrSGYlfHMCOEggpW6cmun43s2ltNFTe DVXV0cy0eOJrOeVchF6iummmWdTb5QGhVK9uKMDWB5bzcjiy802r4yRRDCWI8aoSRlCo 4v4qZ8GDfYqMrqsxpL843kAC9lCBJIMVveQJfo/XIpEJZ4LB7c0HggpvkC/CImEkDZMo HBWHQgjAjiAadrU3zFstRJwPkKRomHBt1J3vvqzJiZLL6PwCA36iJ8cce0mew/4uM83m 1D/g== 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=pMR+WOsTFEKmVTVK25QZwIBxEG8SIzOAoARZILbjYqE=; b=xKWWULXPbXWqomxHdjspVY9+/SgdaH/N6IVhatxekmZ8c/O+8F3Q1uHea5szqix8bN waMmSWZxV4ft64PQRHKnAMzdxjHfEb5m6Jnmr7tcgFxuU+5GGUOLD3DW5XwBXthKCr3x I83GeVurDyWd3I6KjC64EMId9vemxROYFg6t2BK4X3KST7mTc3Jw56l/3P4XgG298Q86 qYH2mFtsRsEGgqzJT5EcDSZDcqO1xmDOXVtZhpHoVU8s7dE4cQ8yerOc15x3to29J31H eksnRfInrQuEc7OknLBwSjua8L2UpnOQmSJayDPnhNDbCs0WfBPzauwSs1jy+a+3zod2 SQEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v60gMA9I; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u2si9436233plk.33.2021.10.11.09.32.32; Mon, 11 Oct 2021 09:32:44 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v60gMA9I; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237999AbhJKN7q (ORCPT + 99 others); Mon, 11 Oct 2021 09:59:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:41068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237916AbhJKN5N (ORCPT ); Mon, 11 Oct 2021 09:57:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A18F561050; Mon, 11 Oct 2021 13:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960440; bh=/+o8pKia5fG22sirI5SOdT3jsRxnD1yMd6ydaJaHwdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v60gMA9IDMMbQyKmInLLnRiltOuL1L6IopCLAyLkT2BgSTuHw8CH+zukSsCsa54ld fBkLkL/B1mt32CO3q6JGM6T28I5y/jXhy2mAgV1V5NZsgkl2YsoBkq5ZhRqNRhOJd+ h7h+6MuWwyBu5w3P5Y2DjxqnKpIrDgMDJg70E+L0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tao Liu , Catherine Sully , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 60/83] gve: Avoid freeing NULL pointer Date: Mon, 11 Oct 2021 15:46:20 +0200 Message-Id: <20211011134510.460465207@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tao Liu [ Upstream commit 922aa9bcac92b3ab6a423526a8e785b35a60b441 ] Prevent possible crashes when cleaning up after unsuccessful initializations. Fixes: 893ce44df5658 ("gve: Add basic driver framework for Compute Engine Virtual NIC") Signed-off-by: Tao Liu Signed-off-by: Catherine Sully Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/google/gve/gve_main.c | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 0b714b606ba1..22b2c6a8d08f 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -71,6 +71,9 @@ static int gve_alloc_counter_array(struct gve_priv *priv) static void gve_free_counter_array(struct gve_priv *priv) { + if (!priv->counter_array) + return; + dma_free_coherent(&priv->pdev->dev, priv->num_event_counters * sizeof(*priv->counter_array), @@ -131,6 +134,9 @@ static int gve_alloc_stats_report(struct gve_priv *priv) static void gve_free_stats_report(struct gve_priv *priv) { + if (!priv->stats_report) + return; + del_timer_sync(&priv->stats_report_timer); dma_free_coherent(&priv->pdev->dev, priv->stats_report_len, priv->stats_report, priv->stats_report_bus); @@ -301,18 +307,19 @@ static void gve_free_notify_blocks(struct gve_priv *priv) { int i; - if (priv->msix_vectors) { - /* Free the irqs */ - for (i = 0; i < priv->num_ntfy_blks; i++) { - struct gve_notify_block *block = &priv->ntfy_blocks[i]; - int msix_idx = i; + if (!priv->msix_vectors) + return; - irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, - NULL); - free_irq(priv->msix_vectors[msix_idx].vector, block); - } - free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); + /* Free the irqs */ + for (i = 0; i < priv->num_ntfy_blks; i++) { + struct gve_notify_block *block = &priv->ntfy_blocks[i]; + int msix_idx = i; + + irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector, + NULL); + free_irq(priv->msix_vectors[msix_idx].vector, block); } + free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv); dma_free_coherent(&priv->pdev->dev, priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks), priv->ntfy_blocks, priv->ntfy_block_bus); -- 2.33.0