linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Clark, Rob" <rob@ti.com>
To: emilgoode@gmail.com
Cc: gregkh@linuxfoundation.org, andy.gross@ti.com,
	daniel.vetter@ffwll.ch, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] staging: drm/omap: Add error handling
Date: Fri, 17 Aug 2012 12:27:01 -0500	[thread overview]
Message-ID: <CAO8GWq=5PEp5ikB_YZ+bUPuKoGWS8jNed7QZECCTmR2qDTMcXg@mail.gmail.com> (raw)
In-Reply-To: <502e7651.241a700a.4d05.7e27@mx.google.com>

On Fri, Aug 17, 2012 at 11:53 AM,  <emilgoode@gmail.com> wrote:
> From: Emil Goode <emilgoode@gmail.com>
>
> This patch adds fail checks for kmalloc and kzalloc calls
> and also adds a error path that frees allocated pages by
> introducing a call to _drm_gem_put_pages.
>
> Signed-off-by: Emil Goode <emilgoode@gmail.com>

Looks good, thanks

Signed-off-by: Rob Clark <rob@ti.com>

> ---
>  drivers/staging/omapdrm/omap_gem.c |   17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c
> index 74082aa..c828743 100644
> --- a/drivers/staging/omapdrm/omap_gem.c
> +++ b/drivers/staging/omapdrm/omap_gem.c
> @@ -226,7 +226,8 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
>         struct drm_device *dev = obj->dev;
>         struct omap_gem_object *omap_obj = to_omap_bo(obj);
>         struct page **pages;
> -       int i, npages = obj->size >> PAGE_SHIFT;
> +       int npages = obj->size >> PAGE_SHIFT;
> +       int i, ret;
>         dma_addr_t *addrs;
>
>         WARN_ON(omap_obj->pages);
> @@ -246,18 +247,32 @@ static int omap_gem_attach_pages(struct drm_gem_object *obj)
>          */
>         if (omap_obj->flags & (OMAP_BO_WC|OMAP_BO_UNCACHED)) {
>                 addrs = kmalloc(npages * sizeof(addrs), GFP_KERNEL);
> +               if (!addrs) {
> +                       ret = -ENOMEM;
> +                       goto free_pages;
> +               }
> +
>                 for (i = 0; i < npages; i++) {
>                         addrs[i] = dma_map_page(dev->dev, pages[i],
>                                         0, PAGE_SIZE, DMA_BIDIRECTIONAL);
>                 }
>         } else {
>                 addrs = kzalloc(npages * sizeof(addrs), GFP_KERNEL);
> +               if (!addrs) {
> +                       ret = -ENOMEM;
> +                       goto free_pages;
> +               }
>         }
>
>         omap_obj->addrs = addrs;
>         omap_obj->pages = pages;
>
>         return 0;
> +
> +free_pages:
> +       _drm_gem_put_pages(obj, pages, true, false);
> +
> +       return ret;
>  }
>
>  /** release backing pages */
> --
> 1.7.10.4
>

      reply	other threads:[~2012-08-17 17:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-17 16:53 [PATCH] staging: drm/omap: Add error handling emilgoode
2012-08-17 17:27 ` Clark, Rob [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='CAO8GWq=5PEp5ikB_YZ+bUPuKoGWS8jNed7QZECCTmR2qDTMcXg@mail.gmail.com' \
    --to=rob@ti.com \
    --cc=andy.gross@ti.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=devel@driverdev.osuosl.org \
    --cc=emilgoode@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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).