mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: devel@driverdev.osuosl.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kjlu@umn.edu, linux-kernel@vger.kernel.org, emamd001@umn.edu,
	smccaman@umn.edu
Subject: Re: [PATCH] staging: comedi: drivers: prevent memory leak
Date: Tue, 17 Sep 2019 11:13:15 +0100	[thread overview]
Message-ID: <86a2ceb0-cc59-2b57-e2b0-f620a42e9ac1@mev.co.uk> (raw)
In-Reply-To: <20190917063004.GG18977@kadam>

On 17/09/2019 07:33, Dan Carpenter wrote:
> On Mon, Sep 16, 2019 at 09:41:43PM -0500, Navid Emamdoost wrote:
>> In das1800_attach, the buffer allocated via kmalloc_array needs to be
>> released if an error happens.
>>
>> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> 
> Commedit calls ->detach() if the ->attach() fails so this patch would
> lead to a double free.  See comedi_device_attach():
> 
> drivers/staging/comedi/drivers.c
>     983          }
>     984          if (!driv->attach) {
>     985                  /* driver does not support manual configuration */
>     986                  dev_warn(dev->class_dev,
>     987                           "driver '%s' does not support attach using comedi_config\n",
>     988                           driv->driver_name);
>     989                  module_put(driv->module);
>     990                  ret = -EIO;
>     991                  goto out;
>     992          }
>     993          dev->driver = driv;
>     994          dev->board_name = dev->board_ptr ? *(const char **)dev->board_ptr
>     995                                           : dev->driver->driver_name;
>     996          ret = driv->attach(dev, it);
>                        ^^^^^^^^^^^^^^^^^^^^^
>     997          if (ret >= 0)
>     998                  ret = comedi_device_postconfig(dev);
>     999          if (ret < 0) {
>    1000                  comedi_device_detach(dev);
>                          ^^^^^^^^^^^^^^^^^^^^^^^^^
> 
>    1001                  module_put(driv->module);
>    1002          }
>    1003          /* On success, the driver module count has been incremented. */

Yes, everything should be freed properly by comedi_device_detach(). 
 From comedi_device_detach(), some of the stuff is freed by 
dev->driver->detach(), and the remainder is freed by 
comedi_device_detach_cleanup().

-- 
-=( Ian Abbott <abbotti@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-

      reply	other threads:[~2019-09-17 10:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17  2:41 Navid Emamdoost
2019-09-17  6:33 ` Dan Carpenter
2019-09-17 10:13   ` Ian Abbott [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=86a2ceb0-cc59-2b57-e2b0-f620a42e9ac1@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=emamd001@umn.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=navid.emamdoost@gmail.com \
    --cc=smccaman@umn.edu \
    /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

all inboxes | Powered by JetHome®