Re: [PATCH v1] dpaa2-switch: fix memory leak of dpaa2_switch_acl_entry_add
From: Jakub Kicinski
Date: Tue Mar 01 2022 - 20:41:28 EST
On Tue, 1 Mar 2022 22:15:44 +0800 Yeqi Fu wrote:
> @@ -142,6 +143,7 @@ int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *filter_block,
> DMA_TO_DEVICE);
> if (err) {
> dev_err(dev, "dpsw_acl_add_entry() failed %d\n", err);
> + kfree(cmd_buff);
> return err;
> }
With more context:
return -EFAULT;
}
err = dpsw_acl_add_entry(ethsw->mc_io, 0, ethsw->dpsw_handle,
filter_block->acl_id, acl_entry_cfg);
dma_unmap_single(dev, acl_entry_cfg->key_iova, sizeof(cmd_buff),
DMA_TO_DEVICE);
if (err) {
dev_err(dev, "dpsw_acl_add_entry() failed %d\n", err);
+ kfree(cmd_buff);
return err;
}
kfree(cmd_buff);
return 0;
}
Here we see unmap is "pulled up" above the error check, same thing can
be done with the kfree(). Otherwise it looks slightly weird - the
buffer unmap and kfree are conceptually part of releasing the buffer,
yet they are split across the paths.