Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5764098rwb; Tue, 22 Nov 2022 04:46:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf61W1x7LCMNwGokp3sMrFULjjcEMPv3cZkmZrFg5eR4CJzIENOu1H6kZSd+OySyxTk9+1dg X-Received: by 2002:a63:f455:0:b0:461:4e55:eab with SMTP id p21-20020a63f455000000b004614e550eabmr22039418pgk.174.1669121207360; Tue, 22 Nov 2022 04:46:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669121207; cv=none; d=google.com; s=arc-20160816; b=isEql5BXR42rDLjV5TTWWAVLF2CnOpnlFAV/aNZ8+rdjd2SGvBP6HSVIHMTyi2X25W v1fyzDoU2XLzbrB9Q86sZBvRcmseBV2P1umz05Z4fp63F/VjnW5U3EQRJwV6/LkAYgAf 4pGy6xYUUBBFgfSwl0QQc4HFdTSagiRwxkk7S7Oosn93kAMr+kyDdtsgJHF27iLk3TAy 6+Tod9OnKQyXaQLz6H6H5FIKzFVlWS4LNsh78k+W1lIfjmEmsUOwr+rao9oAahs39war EPZMnKvd6mIkxNwCGN0HWPNRkTPgi3mTWrRUaq7Q20xuyJ/92oVSB5xi9eM35jCmyr9f 9Fuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3XtypsQCZfitCCQMZ1INOCA+bpbOa3aJWCZ30RBSfxk=; b=M78INDlIKLJNkbi98pcgFpwkIH8N8Pg32BG48LiGTdj4N2oj3SZxcNGKUMDUZeJ09a XLsRQoXxTOJxjZlvKwB/7QSMiDlcnKTEJT1LaeXC0PGrFPxP6whz5BN6DGAj+BpwvkLY wZHdBsU9cXMtdIWrfgHlwl4B8loLsmEa0WOcKMFwyvMsAbhOk6EZgqOfsI+15yKHKZAI Dp5hRvgwwA1s7iUei/12cBrxwy0DKyCJP5j1hrszZKm7CUKhxHX7V0+TCpMss99cmX4u PpePv6Ad0mXuKeLhnm9bw8kDs45IUGl/5c9PmeZMO/JqbnKqAAW14lfsVg87Rm0lTzIw bJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@metanate.com header.s=stronger header.b=2rn+vgcs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metanate.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a170902b20200b001786b70f913si12708184plr.164.2022.11.22.04.46.35; Tue, 22 Nov 2022 04:46:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@metanate.com header.s=stronger header.b=2rn+vgcs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=metanate.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233286AbiKVMft (ORCPT + 90 others); Tue, 22 Nov 2022 07:35:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233565AbiKVMff (ORCPT ); Tue, 22 Nov 2022 07:35:35 -0500 Received: from metanate.com (unknown [IPv6:2001:8b0:1628:5005::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1814D5B852; Tue, 22 Nov 2022 04:35:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Reply-To: Content-ID:Content-Description; bh=3XtypsQCZfitCCQMZ1INOCA+bpbOa3aJWCZ30RBSfxk=; b=2rn+vgcsNJmicNvWa5wF/GIy4x UxlKu5IshzDEjq5aSmeYRYuEs7FD750VvMNtMSQTvXT2rJhUQC17zuVlSHAr02mHxmY+9QfveG2O3 t9qBgfNgAIL6OIdR/9MiCe1HHzWDD2iej2/9sHiRmx5NVTFzBIAR3A3Ig75Sx+So037RT9yJ5z6Gg AOXVnmI0+st2vmoTplh36lbyHddmVEWV1rviobn5ORveSLp79psMWQ2yyAJg9NAd6pfeO+mViB4FT gUYGKdb2efe2Qseg1MnAJMSCKxA4/Hvp3CzfSIRDMJ4xpRwnSRGKQ2eg5afAagbDSyi8pmWK0O9Nq z2leee9A==; Received: from [81.174.171.191] (helo=donbot.metanate.com) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oxSUt-0003da-Gn; Tue, 22 Nov 2022 12:35:32 +0000 From: John Keeping To: linux-usb@vger.kernel.org Cc: Fabien Chouteau , Peter Korsgaard , Felipe Balbi , Andrzej Pietrasiewicz , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , John Keeping , Lee Jones , Alan Stern Subject: [PATCH 2/3] usb: gadget: f_hid: fix refcount leak on error path Date: Tue, 22 Nov 2022 12:35:22 +0000 Message-Id: <20221122123523.3068034-3-john@metanate.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221122123523.3068034-1-john@metanate.com> References: <20221122123523.3068034-1-john@metanate.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated: YES X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); } -- 2.38.1