public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: 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,
	Ian Abbott <abbotti@mev.co.uk>,
	emamd001@umn.edu, smccaman@umn.edu
Subject: Re: [PATCH] staging: comedi: drivers: prevent memory leak
Date: Tue, 17 Sep 2019 09:33:47 +0300	[thread overview]
Message-ID: <20190917063004.GG18977@kadam> (raw)
In-Reply-To: <20190917024147.26290-1-navid.emamdoost@gmail.com>

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. */

regards,
dan carpenter


  reply	other threads:[~2019-09-17  6:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17  2:41 [PATCH] staging: comedi: drivers: prevent memory leak Navid Emamdoost
2019-09-17  6:33 ` Dan Carpenter [this message]
2019-09-17 10:13   ` Ian Abbott

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=20190917063004.GG18977@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=abbotti@mev.co.uk \
    --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