From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A2CD79C9 for ; Thu, 12 Jan 2023 14:18:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4180C433EF; Thu, 12 Jan 2023 14:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1673533124; bh=WHvjIPfXR6wCZmEvNgRMRF/Y7PP2OLq3M1aBJnafGwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WuH17J/ZXf2z3rhKcdiPmouQIEgmsEzfJu2333CpaGpdLFcHYTLFUvN4i0EDt7fXy A9m2FvllUNbqZyEdgkG8ymhyOCLId55+c+U/RTEXCm1PwayF6ytWugeUFzoJcFXp7U jnW/qW21S5ijlK8+hBSbGmc0dL6WvgHrmGYtMh/0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lee Jones , Andrzej Pietrasiewicz , John Keeping , Sasha Levin Subject: [PATCH 5.10 378/783] usb: gadget: f_hid: fix refcount leak on error path Date: Thu, 12 Jan 2023 14:51:34 +0100 Message-Id: <20230112135541.821864164@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230112135524.143670746@linuxfoundation.org> References: <20230112135524.143670746@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: John Keeping [ Upstream commit 70a3288a7586526315105c699b687d78cd32559a ] 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") Tested-by: Lee Jones Reviewed-by: Andrzej Pietrasiewicz Reviewed-by: Lee Jones Signed-off-by: John Keeping Link: https://lore.kernel.org/r/20221122123523.3068034-3-john@metanate.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- 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 97e927eacc62..e7cf56b13c64 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.35.1