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 5962C3E008A; Tue, 21 Jul 2026 22:52:06 +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=1784674327; cv=none; b=AcYKP+Q2xe2JbbWEY28QovOXLzq6+sdB1xI20pEAGnJ8LG8+Vy7VTAyqLc15aQ5XaVpCB0Q4RzpUXeQEeG1+LfmciGyXSXkBwIsDlGh1yqZ3r9XIVAHr5CtqvWvZ8UKZX5p4JBAd1QfDQOUvSbPwuhm4NFvMI89naCXrymgfSqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674327; c=relaxed/simple; bh=gw8chrPHNe6CvxQZqqA+B64b9ZyawVrNCNnOj31Elps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GoUVdh6OuVN+ZW+Z+wQtfXN4r6n0Z6nJ7X4BqjiSNo2ZnDQxP4Amvq80tt5/8w6b8BJP7E1Uaq6bV/6luXNERkIcUc0lK4IU60UfSEYFIpw4yu5L7KnirCLqz0zWDUT703gBYpgM1SW/QggjB+b2yzJkZTA9jiluUW3S7yGeJqk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oUc6DYTJ; 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="oUc6DYTJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C05871F000E9; Tue, 21 Jul 2026 22:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784674326; bh=rI6FSR8Ygg6Z+6ZD2rp97EUFEnBG8ToPrWHDXaSKr3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oUc6DYTJUh65EYyUzTSb/E4ESKClp4K+4mPsKQANZDV/WgWtctUgAYshoojr7anLt lVnaw60qSevHFjkIkv9/qlbjytTbEN9mwOEBVahw+qOwUszvC2nUyZqZbXUi/9YdhK g4XL4/8lw64svUiTDHQc2fKxtRxfCnIKFKyPCz0w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Lee Jones Subject: [PATCH 5.10 456/699] mfd: sm501: Fix reference leak on failed device registration Date: Tue, 21 Jul 2026 17:23:35 +0200 Message-ID: <20260721152405.985603423@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@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 commit 8c2f0b42fc252e1bf1c7746447091a468e784ca1 upstream. When platform_device_register() fails in sm501_register_device(), the embedded struct device in pdev has already been initialized by device_initialize(), but the failure path only reports the error and returns without dropping the device reference for the current platform device: sm501_register_device() -> platform_device_register(pdev) -> device_initialize(&pdev->dev) -> setup_pdev_dma_masks(pdev) -> platform_device_add(pdev) This leads to a reference leak when platform_device_register() fails. Fix this by calling platform_device_put() before returning the error. The issue was identified by a static analysis tool I developed and confirmed by manual review. Fixes: b6d6454fdb66f ("[PATCH] mfd: SM501 core driver") Cc: stable@vger.kernel.org Signed-off-by: Guangshuo Li Link: https://patch.msgid.link/20260415162627.3558789-1-lgs201920130244@gmail.com Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman --- drivers/mfd/sm501.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/mfd/sm501.c +++ b/drivers/mfd/sm501.c @@ -747,9 +747,11 @@ static int sm501_register_device(struct if (ret >= 0) { dev_dbg(sm->dev, "registered %s\n", pdev->name); list_add_tail(&smdev->list, &sm->devices); - } else + } else { dev_err(sm->dev, "error registering %s (%d)\n", pdev->name, ret); + platform_device_put(pdev); + } return ret; }