Skip to content

Commit 922aa9b

Browse files
xliutaox-gdavem330
authored andcommitted
gve: Avoid freeing NULL pointer
Prevent possible crashes when cleaning up after unsuccessful initializations. Fixes: 893ce44 ("gve: Add basic driver framework for Compute Engine Virtual NIC") Signed-off-by: Tao Liu <[email protected]> Signed-off-by: Catherine Sully <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d03477e commit 922aa9b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

drivers/net/ethernet/google/gve/gve_main.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static int gve_alloc_counter_array(struct gve_priv *priv)
8282

8383
static void gve_free_counter_array(struct gve_priv *priv)
8484
{
85+
if (!priv->counter_array)
86+
return;
87+
8588
dma_free_coherent(&priv->pdev->dev,
8689
priv->num_event_counters *
8790
sizeof(*priv->counter_array),
@@ -142,6 +145,9 @@ static int gve_alloc_stats_report(struct gve_priv *priv)
142145

143146
static void gve_free_stats_report(struct gve_priv *priv)
144147
{
148+
if (!priv->stats_report)
149+
return;
150+
145151
del_timer_sync(&priv->stats_report_timer);
146152
dma_free_coherent(&priv->pdev->dev, priv->stats_report_len,
147153
priv->stats_report, priv->stats_report_bus);
@@ -370,18 +376,19 @@ static void gve_free_notify_blocks(struct gve_priv *priv)
370376
{
371377
int i;
372378

373-
if (priv->msix_vectors) {
374-
/* Free the irqs */
375-
for (i = 0; i < priv->num_ntfy_blks; i++) {
376-
struct gve_notify_block *block = &priv->ntfy_blocks[i];
377-
int msix_idx = i;
379+
if (!priv->msix_vectors)
380+
return;
378381

379-
irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector,
380-
NULL);
381-
free_irq(priv->msix_vectors[msix_idx].vector, block);
382-
}
383-
free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv);
382+
/* Free the irqs */
383+
for (i = 0; i < priv->num_ntfy_blks; i++) {
384+
struct gve_notify_block *block = &priv->ntfy_blocks[i];
385+
int msix_idx = i;
386+
387+
irq_set_affinity_hint(priv->msix_vectors[msix_idx].vector,
388+
NULL);
389+
free_irq(priv->msix_vectors[msix_idx].vector, block);
384390
}
391+
free_irq(priv->msix_vectors[priv->mgmt_msix_idx].vector, priv);
385392
dma_free_coherent(&priv->pdev->dev,
386393
priv->num_ntfy_blks * sizeof(*priv->ntfy_blocks),
387394
priv->ntfy_blocks, priv->ntfy_block_bus);

0 commit comments

Comments
 (0)