* [PING PATCH] drm/bochs: replace ioremap with devm_ioremap to avoid immo leak
@ 2023-03-29 5:26 Gencen Gan
2023-03-31 15:10 ` [PING] " Sui Jingfeng
0 siblings, 1 reply; 2+ messages in thread
From: Gencen Gan @ 2023-03-29 5:26 UTC (permalink / raw)
To: Gerd Hoffmann, David Airlie, Daniel Vetter
Cc: Gan Gecen, virtualization, dri-devel, linux-kernel
From: Gan Gecen <gangecen@hust.edu.cn>
Smatch reports:
drivers/gpu/drm/tiny/bochs.c:290 bochs_hw_init()
warn: 'bochs->mmio' from ioremap() not released on
lines: 246,250,254.
In the function bochs_load() that calls bochs_hw_init()
only, if bochs_hw_init(dev) returns -ENODEV(-19), it
will jumps to err_free_dev instead of err_hw_fini, so
bochs->immo won't be freed.
We would prefer to replace ioremap with devm_ioremap
to avoid adding lengthy error handling. The function
`devm_ioremap` will automatically release the allocated
resources after use.
Signed-off-by: Gan Gecen <gangecen@hust.edu.cn>
---
drivers/gpu/drm/tiny/bochs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
index 024346054c70..0d7e119a732f 100644
--- a/drivers/gpu/drm/tiny/bochs.c
+++ b/drivers/gpu/drm/tiny/bochs.c
@@ -223,7 +223,7 @@ static int bochs_hw_init(struct drm_device *dev)
}
ioaddr = pci_resource_start(pdev, 2);
iosize = pci_resource_len(pdev, 2);
- bochs->mmio = ioremap(ioaddr, iosize);
+ bochs->mmio = devm_ioremap(&pdev->dev, ioaddr, iosize);
if (bochs->mmio == NULL) {
DRM_ERROR("Cannot map mmio region\n");
return -ENOMEM;
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PING] drm/bochs: replace ioremap with devm_ioremap to avoid immo leak
2023-03-29 5:26 [PING PATCH] drm/bochs: replace ioremap with devm_ioremap to avoid immo leak Gencen Gan
@ 2023-03-31 15:10 ` Sui Jingfeng
0 siblings, 0 replies; 2+ messages in thread
From: Sui Jingfeng @ 2023-03-31 15:10 UTC (permalink / raw)
To: Gencen Gan, Gerd Hoffmann, David Airlie, Daniel Vetter
Cc: linux-kernel, dri-devel, virtualization
Hi,
I'm noticed you patch, interesting!
On 2023/3/29 13:26, Gencen Gan wrote:
> From: Gan Gecen <gangecen@hust.edu.cn>
>
> Smatch reports:
>
> drivers/gpu/drm/tiny/bochs.c:290 bochs_hw_init()
> warn: 'bochs->mmio' from ioremap() not released on
> lines: 246,250,254.
>
> In the function bochs_load() that calls bochs_hw_init()
> only, if bochs_hw_init(dev) returns -ENODEV(-19), it
> will jumps to err_free_dev instead of err_hw_fini, so
> bochs->immo won't be freed.
`mmio`, not `immo`, you should also fix the typos in you patch's
commit title.
> We would prefer to replace ioremap with devm_ioremap
> to avoid adding lengthy error handling. The function
> `devm_ioremap` will automatically release the allocated
> resources after use.
Yet, I notice that there is iounmap in bochs_hw_fini() function, does
double free will happen?
static void bochs_hw_fini(struct drm_device *dev)
{
struct bochs_device *bochs = dev->dev_private;
// ...
if (bochs->mmio)
iounmap(bochs->mmio);
// ...
}
I still advise you free it by adding error handling code, free it manually.
Because still there other ioremap() function in the driver.
But you can choose to heard other reviewer's voice, I can only help to
review.
> Signed-off-by: Gan Gecen <gangecen@hust.edu.cn>
> ---
> drivers/gpu/drm/tiny/bochs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
> index 024346054c70..0d7e119a732f 100644
> --- a/drivers/gpu/drm/tiny/bochs.c
> +++ b/drivers/gpu/drm/tiny/bochs.c
> @@ -223,7 +223,7 @@ static int bochs_hw_init(struct drm_device *dev)
> }
> ioaddr = pci_resource_start(pdev, 2);
> iosize = pci_resource_len(pdev, 2);
> - bochs->mmio = ioremap(ioaddr, iosize);
> + bochs->mmio = devm_ioremap(&pdev->dev, ioaddr, iosize);
> if (bochs->mmio == NULL) {
> DRM_ERROR("Cannot map mmio region\n");
> return -ENOMEM;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-31 15:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 5:26 [PING PATCH] drm/bochs: replace ioremap with devm_ioremap to avoid immo leak Gencen Gan
2023-03-31 15:10 ` [PING] " Sui Jingfeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®