dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Joseph Kogut <joseph.kogut@gmail.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Joseph Kogut <joseph.kogut@gmail.com>,
	dri-devel@lists.freedesktop.org,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 1/1] drm: drm_legacy_addbufs_pci(): fix return without cleanup
Date: Fri, 14 May 2021 13:48:36 -0700	[thread overview]
Message-ID: <20210514204836.793539-1-joseph.kogut@gmail.com> (raw)
In-Reply-To: <YJ6BJBgS0HnPgzsJ@mwanda>

The patch 70556e24e18e: "drm: remove usage of drm_pci_alloc/free" leads
to the following static checker warning:

    drivers/gpu/drm/drm_bufs.c:1090 drm_legacy_addbufs_pci()
    warn: inconsistent returns '&dev->struct_mutex'.
      Locked on  : 988
      Unlocked on: 938,944,951,959,973,1005,1042,1060,1090

Fix the return without cleanup by removing the early return and taking
the original return path on allocation failure, including the intended
unlocks.

Signed-off-by: Joseph Kogut <joseph.kogut@gmail.com>
---
 drivers/gpu/drm/drm_bufs.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 94bc1f6049c9..ea3ca81be9dd 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -984,17 +984,18 @@ int drm_legacy_addbufs_pci(struct drm_device *dev,
 
 	while (entry->buf_count < count) {
 		dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
-		if (!dmah)
-			return -ENOMEM;
-
-		dmah->size = total;
-		dmah->vaddr = dma_alloc_coherent(dev->dev,
-						 dmah->size,
-						 &dmah->busaddr,
-						 GFP_KERNEL);
-		if (!dmah->vaddr) {
-			kfree(dmah);
-
+		if (dmah) {
+			dmah->size = total;
+			dmah->vaddr = dma_alloc_coherent(dev->dev,
+							 dmah->size,
+							 &dmah->busaddr,
+							 GFP_KERNEL);
+			if (!dmah->vaddr) {
+				kfree(dmah);
+				dmah = NULL;
+			}
+		}
+		if (!dmah) {
 			/* Set count correctly so we free the proper amount. */
 			entry->buf_count = count;
 			entry->seg_count = count;
-- 
2.31.1


      parent reply	other threads:[~2021-05-14 20:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14 13:54 [bug report] drm: remove usage of drm_pci_alloc/free Dan Carpenter
2021-05-14 15:13 ` Joseph Kogut
2021-05-14 16:34   ` Joseph Kogut
2021-05-15  6:57     ` Dan Carpenter
2021-05-14 20:48 ` Joseph Kogut [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210514204836.793539-1-joseph.kogut@gmail.com \
    --to=joseph.kogut@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).