mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jens Taprogge <jens.taprogge@taprogge.org>,
	industrypack-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ipack: add missing put_device() after device_register() failed
Date: Tue, 26 Feb 2013 14:28:42 -0800	[thread overview]
Message-ID: <20130226222842.GA20670@core.coreip.homeip.net> (raw)
In-Reply-To: <1361869395-23110-1-git-send-email-siglesias@igalia.com>

On Tue, Feb 26, 2013 at 10:03:15AM +0100, Samuel Iglesias Gonsalvez wrote:
> put_device() must be called after device_register() fails,
> since device_register() always initializes the refcount
> on the device structure to one.
> 
> dev->id is free'd inside of ipack_device_release function.
> So, it's not needed to do it here.
> 
> Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> ---
>  drivers/ipack/ipack.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ipack/ipack.c b/drivers/ipack/ipack.c
> index 7ec6b20..3588ccf 100644
> --- a/drivers/ipack/ipack.c
> +++ b/drivers/ipack/ipack.c
> @@ -449,7 +449,7 @@ int ipack_device_register(struct ipack_device *dev)
>  
>  	ret = device_register(&dev->dev);
>  	if (ret < 0)
> -		kfree(dev->id);
> +		put_device(&dev->dev);

Now callers have no idea if they have to free (put_device) it in case of
failure or it is already done for them, because a few lines earlier, if
pack_device_read_id() fails, it simply returns error code.

IMO if a function did not allocate object it should not try to free it,
callers should dispose of the device as they see fit.

What is missing, however, is dev->id = NULL assignment so that if caller
does put_device() kit won't double-free the memory. Also it would make
sense to split device_register into device_init() and device_add() so
that device_init() is very first thing you do and in case of all
failures callers should use put_device().

Also tpci200.c need to learn to clean up after itself and I also not
sure why it tries to provide its own release function.

Thanks.

-- 
Dmitry

  reply	other threads:[~2013-02-26 22:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-26  9:03 Samuel Iglesias Gonsalvez
2013-02-26 22:28 ` Dmitry Torokhov [this message]
2013-02-27  9:00   ` Samuel Iglesias Gonsálvez
2013-03-08  8:21     ` [PATCH 1/3] ipack: avoid double free on device->id Samuel Iglesias Gonsalvez
2013-03-08  8:21       ` [PATCH 2/3] ipack: add ipack_get_device() ipack_put_device() Samuel Iglesias Gonsalvez
2013-03-08  8:21       ` [PATCH 3/3] ipack: split ipack_device_register() in several functions Samuel Iglesias Gonsalvez
2013-03-08 17:47       ` [PATCH 1/3] ipack: avoid double free on device->id Greg Kroah-Hartman
2013-03-08 18:11         ` Samuel Iglesias Gonsálvez
2013-03-08 18:11         ` Samuel Iglesias Gonsálvez
2013-03-08 19:36           ` Greg Kroah-Hartman
2013-03-11  7:58             ` Samuel Iglesias Gonsálvez

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=20130226222842.GA20670@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=industrypack-devel@lists.sourceforge.net \
    --cc=jens.taprogge@taprogge.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=siglesias@igalia.com \
    /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®