From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 295AD318EDA; Tue, 16 Jun 2026 19:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636920; cv=none; b=XfXoEGr0M2gxuWgklQEJ1Iw/FyKfyROgB1GeOganI5JXP9kaD3o8YPHwHXuGoJnUM73K7Qs/Es2Gq56hs6blIzqaDwZLFAoBLG179sk3523qWb/kLU5slnzb3SW8Pf0ii7vcfLkf+ebwtGSJtjyCZ2b9MVppdRZT5Ud0HxPD+a4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781636920; c=relaxed/simple; bh=erDUTmeowwzJbWNwcainYAcvOZElMOvHfQDMtVzvFLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EbvQK4CiE6N9m9y3PpbHPV/004rILjFHj9Fv5PhuEtBWtH3Ji1lCcPMGR0wJmqscP9lXszVM6iN+1LajqYvFMlGRtXrMO0r42GrV0r3psGWh8Snt7O9ZuI53mQ9vrT3cQ/FShckQi7bEiXLZ940jcrl2VhiprrsN3RrHtUEuGxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oPghjM8Q; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oPghjM8Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 124301F000E9; Tue, 16 Jun 2026 19:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781636919; bh=G0ogQNKzHdgbBfg5QepRAGfGDAA/W84YV0FOEX1IvZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oPghjM8Qyvr1+cGkZ3/A6/CGUSbUpBqJniCOOHukljnl49Q4xjQ+jIjde91tQ3M66 XkObdVpvAZ7xt4g/E3irH7QaYb7LvDZ5y9MmZPyNdL4aX4+jZ5kTzDNsV38vlOFqaB 8ihc119JBo4OCNhbmYaCvQnlB1akpeeHSLuYLP1A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Johan Hovold , Guangshuo Li , Sasha Levin Subject: [PATCH 5.10 331/342] usb: gadget: f_hid: fix device reference leak in hidg_alloc() Date: Tue, 16 Jun 2026 20:30:27 +0530 Message-ID: <20260616145104.020283500@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145048.348037099@linuxfoundation.org> References: <20260616145048.348037099@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit 4f88d65def6f3c90121601b4f62a4c967f3063a6 ] hidg_alloc() initializes hidg->dev with device_initialize() before calling dev_set_name(). If dev_set_name() fails, the function currently jumps to err_unlock and returns without calling put_device(). This leaves the device reference unbalanced and prevents hidg_release() from being called. Calling put_device() here is also safe, since hidg_release() only frees resources owned by hidg. The issue was identified by a static analysis tool I developed and confirmed by manual review. Route the dev_set_name() failure path through err_put_device so the device reference is dropped properly. Fixes: 89ff3dfac604 ("usb: gadget: f_hid: fix f_hidg lifetime vs cdev") Cc: stable Reviewed-by: Johan Hovold Signed-off-by: Guangshuo Li Reviewed-by: Johan Hovold johan@kernel.org Link: https://patch.msgid.link/20260413142119.2977716-1-lgs201920130244@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_hid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -1278,7 +1278,7 @@ static struct usb_function *hidg_alloc(s hidg->dev.devt = MKDEV(major, opts->minor); ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor); if (ret) - goto err_unlock; + goto err_put_device; hidg->bInterfaceSubClass = opts->subclass; hidg->bInterfaceProtocol = opts->protocol; @@ -1313,7 +1313,6 @@ static struct usb_function *hidg_alloc(s err_put_device: put_device(&hidg->dev); -err_unlock: mutex_unlock(&opts->lock); return ERR_PTR(ret); }