diff mbox series

drm/vmwgfx/vmwgfx_drv: Fix an error path in vmw_setup_pci_resources()

Message ID YA6FMboLhnE3uSvb@mwanda (mailing list archive)
State New, archived
Headers show
Series drm/vmwgfx/vmwgfx_drv: Fix an error path in vmw_setup_pci_resources() | expand

Commit Message

Dan Carpenter Jan. 25, 2021, 8:45 a.m. UTC
The devm_memremap() function never returns NULL, it returns error
pointers so the test needs to be fixed.  Also we need to call
pci_release_regions() to avoid a memory leak.

Fixes: be4f77ac6884 ("drm/vmwgfx: Cleanup fifo mmio handling")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Zack Rusin Jan. 25, 2021, 7:13 p.m. UTC | #1
> On Jan 25, 2021, at 03:45, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> The devm_memremap() function never returns NULL, it returns error
> pointers so the test needs to be fixed.  Also we need to call
> pci_release_regions() to avoid a memory leak.
> 
> Fixes: be4f77ac6884 ("drm/vmwgfx: Cleanup fifo mmio handling")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, Dan.

I have a patch based on your report that fixes that too but it comes with a refactoring. I’d be happy to rebase it on top of yours just to get yours in before. If you’d like I can push your patch through drm-misc-next, if not:

Reviewed-by: Zack Rusin <zackr@vmware.com>

z
Dan Carpenter Jan. 26, 2021, 7:34 a.m. UTC | #2
On Mon, Jan 25, 2021 at 07:13:43PM +0000, Zack Rusin wrote:
> 
> 
> > On Jan 25, 2021, at 03:45, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > 
> > The devm_memremap() function never returns NULL, it returns error
> > pointers so the test needs to be fixed.  Also we need to call
> > pci_release_regions() to avoid a memory leak.
> > 
> > Fixes: be4f77ac6884 ("drm/vmwgfx: Cleanup fifo mmio handling")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks, Dan.
> 
> I have a patch based on your report that fixes that too but it comes with a refactoring. I’d be happy to rebase it on top of yours just to get yours in before. If you’d like I can push your patch through drm-misc-next, if not:


No no.  Sorry, just apply your patch and drop mine.  The problem is that
the report I sent was from kbuild and I do my devel work on a different
system so it's harder to track those emails and I forgot.

Looking at it now, the bug report I sent earlier was only for the
pci_release_regions() and not the NULL vs error pointer.  The kbuild
bot is not using full cross function analysis so it can't find those
bugs.  My dev system does much slower builds so it's a tradeoff.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index eb997f4678de..3f603a6b5f90 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -668,9 +668,10 @@  static int vmw_setup_pci_resources(struct vmw_private *dev,
 				      fifo_size,
 				      MEMREMAP_WB);
 
-	if (unlikely(dev->fifo_mem == NULL)) {
+	if (IS_ERR(dev->fifo_mem)) {
 		DRM_ERROR("Failed mapping FIFO memory.\n");
-		return -ENOMEM;
+		pci_release_regions(pdev);
+		return PTR_ERR(dev->fifo_mem);
 	}
 
 	/*