From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938835AbcKQSeF (ORCPT ); Thu, 17 Nov 2016 13:34:05 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33685 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753053AbcKQSeE (ORCPT ); Thu, 17 Nov 2016 13:34:04 -0500 Date: Thu, 17 Nov 2016 15:38:22 +0100 From: Johan Hovold To: Alexander Shishkin Cc: linux-kernel@vger.kernel.org, Johan Hovold Subject: Re: [PATCH] stm class: fix device leak in open error path Message-ID: <20161117143822.GB10490@localhost> References: <1477997094-29192-1-git-send-email-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1477997094-29192-1-git-send-email-johan@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 01, 2016 at 11:44:54AM +0100, Johan Hovold wrote: > 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 > --- > drivers/hwtracing/stm/core.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c > index 51f81d64ca37..47811f5c9bc9 100644 > --- a/drivers/hwtracing/stm/core.c > +++ b/drivers/hwtracing/stm/core.c > @@ -368,8 +368,10 @@ static int stm_char_open(struct inode *inode, struct file *file) > return -ENODEV; > > stmf = kzalloc(sizeof(*stmf), GFP_KERNEL); > - if (!stmf) > - return -ENOMEM; > + if (!stmf) { > + err = -ENOMEM; > + goto err_put_device; > + } > > stm_output_init(&stmf->output); > stmf->stm = to_stm_device(dev); > @@ -382,9 +384,10 @@ static int stm_char_open(struct inode *inode, struct file *file) > return nonseekable_open(inode, file); > > err_free: > + kfree(stmf); > +err_put_device: > /* matches class_find_device() above */ > put_device(dev); > - kfree(stmf); > > return err; > } Any comments to this one, Alexander? Thanks, Johan