linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Johan Hovold <johan@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] stm class: fix device leak in open error path
Date: Fri, 18 Nov 2016 14:01:15 +0100	[thread overview]
Message-ID: <20161118130115.GG10490@localhost> (raw)
In-Reply-To: <874m35f1dd.fsf@ashishki-desk.ger.corp.intel.com>

On Fri, Nov 18, 2016 at 01:55:58PM +0200, Alexander Shishkin wrote:
> Johan Hovold <johan@kernel.org> writes:
> 
> > Make sure to drop the reference taken by class_find_device() also on
> > allocation errors in open().
> >
> > Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for...")
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> 
> Good catch, thanks! I'm going to change it a bit to look like this
> if you don't mind:
> 
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index 51f81d64ca..cf6c9ea14c 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -361,7 +361,7 @@ static int stm_char_open(struct inode *inode, struct file *file)
>         struct stm_file *stmf;
>         struct device *dev;
>         unsigned int major = imajor(inode);
> -       int err = -ENODEV;
> +       int err = -ENOMEM;
> 
>         dev = class_find_device(&stm_class, NULL, &major, major_match);
>         if (!dev)
> @@ -369,8 +369,9 @@ static int stm_char_open(struct inode *inode, struct file *file)
> 
>         stmf = kzalloc(sizeof(*stmf), GFP_KERNEL);
>         if (!stmf)
> -               return -ENOMEM;
> +               goto err_put_device;
> 
> +       err = -ENODEV;
>         stm_output_init(&stmf->output);
>         stmf->stm = to_stm_device(dev);

Sure. I find it more readable to set the errno in the error path, but I
don't mind.

Thanks,
Johan

      reply	other threads:[~2016-11-18 13:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-01 10:44 [PATCH] stm class: fix device leak in open error path Johan Hovold
2016-11-17 14:38 ` Johan Hovold
2016-11-18 11:55 ` Alexander Shishkin
2016-11-18 13:01   ` Johan Hovold [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=20161118130115.GG10490@localhost \
    --to=johan@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --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).