diff options
author | Alexandru Ardelean <alexandru.ardelean@analog.com> | 2020-11-19 18:49:02 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-12-09 21:59:00 +0300 |
commit | d57801c45f53e3da999e2a0beb932717fe335c41 (patch) | |
tree | f5239bccdeb6a0df8fde44672e95951d0b56d2a3 /drivers | |
parent | 16d546c42db5d9ea91e4d9d3bde5e80eb0cf6bf8 (diff) | |
download | linux-d57801c45f53e3da999e2a0beb932717fe335c41.tar.xz |
uio: uio_fsl_elbc_gpcm: use device-managed allocators
This change moves all the simple allocations to use device-managed
allocator functions. This way their life-time is tied to the
platform_device object, so when this gets free'd these allocations also get
cleaned up.
The final effect is that error & exit paths get cleaned up a bit.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20201119154903.82099-3-alexandru.ardelean@analog.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/uio/uio_fsl_elbc_gpcm.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/drivers/uio/uio_fsl_elbc_gpcm.c b/drivers/uio/uio_fsl_elbc_gpcm.c index be8a6905f507..7d8eb9dc2068 100644 --- a/drivers/uio/uio_fsl_elbc_gpcm.c +++ b/drivers/uio/uio_fsl_elbc_gpcm.c @@ -299,7 +299,7 @@ static int get_of_data(struct fsl_elbc_gpcm *priv, struct device_node *node, /* get optional uio name */ if (of_property_read_string(node, "uio_name", &dt_name) != 0) dt_name = "eLBC_GPCM"; - *name = kstrdup(dt_name, GFP_KERNEL); + *name = devm_kstrdup(priv->dev, dt_name, GFP_KERNEL); if (!*name) return -ENOMEM; @@ -324,7 +324,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) return -ENODEV; /* allocate private data */ - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; @@ -334,14 +334,12 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) ret = get_of_data(priv, node, &res, ®_br_new, ®_or_new, &irq, &uio_name); if (ret) - goto out_err0; + return ret; /* allocate UIO structure */ - info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) { - ret = -ENOMEM; - goto out_err0; - } + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; /* get current BR/OR values */ reg_br_cur = in_be32(&priv->lbc->bank[priv->bank].br); @@ -354,8 +352,7 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) != fsl_lbc_addr(res.start)) { dev_err(priv->dev, "bank in use by another peripheral\n"); - ret = -ENODEV; - goto out_err1; + return -ENODEV; } /* warn if behavior settings changing */ @@ -382,12 +379,11 @@ static int uio_fsl_elbc_gpcm_probe(struct platform_device *pdev) info->mem[0].internal_addr = ioremap(res.start, resource_size(&res)); if (!info->mem[0].internal_addr) { dev_err(priv->dev, "failed to map chip region\n"); - ret = -ENODEV; - goto out_err1; + return -ENODEV; } /* set all UIO data */ - info->mem[0].name = kasprintf(GFP_KERNEL, "%pOFn", node); + info->mem[0].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%pOFn", node); info->mem[0].addr = res.start; info->mem[0].size = resource_size(&res); info->mem[0].memtype = UIO_MEM_PHYS; @@ -428,12 +424,6 @@ out_err2: if (priv->shutdown) priv->shutdown(info, true); iounmap(info->mem[0].internal_addr); -out_err1: - kfree(info->mem[0].name); - kfree(info); -out_err0: - kfree(uio_name); - kfree(priv); return ret; } @@ -447,10 +437,6 @@ static int uio_fsl_elbc_gpcm_remove(struct platform_device *pdev) if (priv->shutdown) priv->shutdown(info, false); iounmap(info->mem[0].internal_addr); - kfree(info->mem[0].name); - kfree(info->name); - kfree(info); - kfree(priv); return 0; |