From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA603C4167D for ; Wed, 23 Nov 2022 12:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237318AbiKWMEj (ORCPT ); Wed, 23 Nov 2022 07:04:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiKWMEh (ORCPT ); Wed, 23 Nov 2022 07:04:37 -0500 Received: from metanate.com (unknown [IPv6:2001:8b0:1628:5005::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 506E062F6; Wed, 23 Nov 2022 04:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metanate.com; s=stronger; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-ID:Content-Description; bh=5JMIrXWfVVUBawjQhTsB12rkc3V2fqv2OGN2cVRUBRs=; b=TN91uAo4CNv5C7fEtaNVdRScjZ r8YBSVaWiMa+2ppar+coZcihrgglWDIJfTsLSaQwpUhf1rVEmcd9kLzW+lXPH6AYxvX3dyTwXxv1x RbvYqzICSadoDgk2up5jwHMyZl4vSrPKOgTmiSFPFOkXKFD/VNmT3ZkuxETK/dTX6VQu+2OBedXun QfvLoZZ9UCnkzlfqSe9uGPcdnsDWWR2c0vhOxejyjs2JoSjgn1QZ1qHA91tVW3WTM0hplyFJRx2WI MKkNKP5+0FMvgjSWMD7G4Y7GKMU8RBa/Buf+T5sUGCT0+61+MnakBdfUCQRcyNmQ3VKs/gwLHOril B1CvOObg==; Received: from dougal.metanate.com ([192.168.88.1] helo=donbot) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oxoUU-0007F2-2m; Wed, 23 Nov 2022 12:04:34 +0000 Date: Wed, 23 Nov 2022 12:04:33 +0000 From: John Keeping To: Andrzej Pietrasiewicz Cc: linux-usb@vger.kernel.org, Fabien Chouteau , Peter Korsgaard , Felipe Balbi , Andrzej Pietrasiewicz , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Lee Jones , Alan Stern Subject: Re: [PATCH 2/3] usb: gadget: f_hid: fix refcount leak on error path Message-ID: References: <20221122123523.3068034-1-john@metanate.com> <20221122123523.3068034-3-john@metanate.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Authenticated: YES Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 23, 2022 at 12:55:14PM +0100, Andrzej Pietrasiewicz wrote: > W dniu 22.11.2022 o 13:35, John Keeping pisze: > > When failing to allocate report_desc, opts->refcnt has already been > > incremented so it needs to be decremented to avoid leaving the options > > structure permanently locked. > > > > Fixes: 21a9476a7ba8 ("usb: gadget: hid: add configfs support") > > Signed-off-by: John Keeping > > I'd personally place the bugfix before patches 1 and 3, but anyway Patch 1 is also a bugfix, I ordered 1 & 2 based on the order of the commits in the Fixes: tags. > Reviewed-by: Andrzej Pietrasiewicz > > > --- > > drivers/usb/gadget/function/f_hid.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c > > index 8b8bbeaa27cb..6be6009f911e 100644 > > --- a/drivers/usb/gadget/function/f_hid.c > > +++ b/drivers/usb/gadget/function/f_hid.c > > @@ -1292,6 +1292,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) > > GFP_KERNEL); > > if (!hidg->report_desc) { > > put_device(&hidg->dev); > > + --opts->refcnt; > > mutex_unlock(&opts->lock); > > return ERR_PTR(-ENOMEM); > > } >