From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754085AbcKRNBV (ORCPT ); Fri, 18 Nov 2016 08:01:21 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33224 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754068AbcKRNBS (ORCPT ); Fri, 18 Nov 2016 08:01:18 -0500 Date: Fri, 18 Nov 2016 14:01:15 +0100 From: Johan Hovold To: Alexander Shishkin Cc: Johan Hovold , linux-kernel@vger.kernel.org Subject: Re: [PATCH] stm class: fix device leak in open error path Message-ID: <20161118130115.GG10490@localhost> References: <1477997094-29192-1-git-send-email-johan@kernel.org> <874m35f1dd.fsf@ashishki-desk.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874m35f1dd.fsf@ashishki-desk.ger.corp.intel.com> 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 Fri, Nov 18, 2016 at 01:55:58PM +0200, Alexander Shishkin wrote: > Johan Hovold 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 > > 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