dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Joseph Kogut <joseph.kogut@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [bug report] drm: remove usage of drm_pci_alloc/free
Date: Fri, 14 May 2021 08:13:15 -0700	[thread overview]
Message-ID: <CAMWSM7gBU9VOZovOB29ZGKNvL_tXxWk1z0GD44n0=wYk+eAXUA@mail.gmail.com> (raw)
In-Reply-To: <YJ6BJBgS0HnPgzsJ@mwanda>

Hi Dan,

On Fri, May 14, 2021 at 6:54 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> Hello Joseph Kogut,
>
> The patch 70556e24e18e: "drm: remove usage of drm_pci_alloc/free"
> from Apr 22, 2021, 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
>
> drivers/gpu/drm/drm_bufs.c
>    965          temp_pagelist = kmalloc_array(dma->page_count + (count << page_order),
>    966                                        sizeof(*dma->pagelist),
>    967                                        GFP_KERNEL);
>    968          if (!temp_pagelist) {
>    969                  kfree(entry->buflist);
>    970                  kfree(entry->seglist);
>    971                  mutex_unlock(&dev->struct_mutex);
>    972                  atomic_dec(&dev->buf_alloc);
>    973                  return -ENOMEM;
>
> There is a bunch of clean up happenning on the existing returns.
>
>    974          }
>    975          memcpy(temp_pagelist,
>    976                 dma->pagelist, dma->page_count * sizeof(*dma->pagelist));
>    977          DRM_DEBUG("pagelist: %d entries\n",
>    978                    dma->page_count + (count << page_order));
>    979
>    980          entry->buf_size = size;
>    981          entry->page_order = page_order;
>    982          byte_count = 0;
>    983          page_count = 0;
>    984
>    985          while (entry->buf_count < count) {
>    986                  dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
>    987                  if (!dmah)
>    988                          return -ENOMEM;
>
> This new return has no clean up.  We a mutex_unlock(&dev->struct_mutex).
>
>    989
>    990                  dmah->size = total;
>    991                  dmah->vaddr = dma_alloc_coherent(dev->dev,
>    992                                                   dmah->size,
>    993                                                   &dmah->busaddr,
>    994                                                   GFP_KERNEL);
>    995                  if (!dmah->vaddr) {
>    996                          kfree(dmah);
>    997
>    998                          /* Set count correctly so we free the proper amount. */
>    999                          entry->buf_count = count;
>   1000                          entry->seg_count = count;
>   1001                          drm_cleanup_buf_error(dev, entry);
>   1002                          kfree(temp_pagelist);
>   1003                          mutex_unlock(&dev->struct_mutex);
>   1004                          atomic_dec(&dev->buf_alloc);
>   1005                          return -ENOMEM;
>   1006                  }
>   1007                  entry->seglist[entry->seg_count++] = dmah;
>   1008                  for (i = 0; i < (1 << page_order); i++) {
>   1009                          DRM_DEBUG("page %d @ 0x%08lx\n",
>
> regards,
> dan carpenter

Thanks for the report, I'll follow up with a patch to fix this.

Best,
Joseph

  reply	other threads:[~2021-05-14 15:13 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 [this message]
2021-05-14 16:34   ` Joseph Kogut
2021-05-15  6:57     ` Dan Carpenter
2021-05-14 20:48 ` [PATCH 1/1] drm: drm_legacy_addbufs_pci(): fix return without cleanup Joseph Kogut

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='CAMWSM7gBU9VOZovOB29ZGKNvL_tXxWk1z0GD44n0=wYk+eAXUA@mail.gmail.com' \
    --to=joseph.kogut@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --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).