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 0488818A6A5; Mon, 27 Oct 2025 18:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591408; cv=none; b=n+TiYIJZFWboGsmWw9cVnbi7widT3yY3EspiIqgouFHRtUC1DZjvyOHCTT7hFvkWHcpECZE++GHdvUtGM2WCa0o7TIQzdZPQGGXq5+SROeLHGNTlKRvtLRJ4xhSA4GJRqNDwwtKPSX1eto8seE7WuNKgkD659SsL2/8I+tCrJnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591408; c=relaxed/simple; bh=Y6bAdoHNQ1swdixwnbu6C/BvY/wg3uFgwSz/UajoZSg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=miCuBfGWsOBK5T28Lqo/1WdEwlcmJTkPGNr6vQwDEZZJJRkjCZfyL/UYCRph2bqg+gKlBFEMoj62S35f8AOuI6cIC1sbMLJDgwjRBU0E2CSvlkGGzc0rsTqKPnSuROfKmRFLr/91VrU+qAkHg5ACR3lIlIWNbqzRKoOGbpDckDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=c/qDOFkk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="c/qDOFkk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A18CC4CEF1; Mon, 27 Oct 2025 18:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591407; bh=Y6bAdoHNQ1swdixwnbu6C/BvY/wg3uFgwSz/UajoZSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c/qDOFkkQ+8FlO6EofQ96WYc81UIDOFb9vUKVi5VZdBHIOK+wA+eJTy/UFl07/GBR nndaAfphxfEd0FmIRw5TcyuZxvfYye4DCAL2OhIhWc7bBzfADqdkL1jrnaCsRSTRHN WmzMfNPxMmVKtjcA9pCzj6j6pOMeNrBYJE72x3f8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ma Ke , Dmitry Baryshkov , Mark Brown , Sasha Levin Subject: [PATCH 5.10 184/332] ASoC: wcd934x: fix error handling in wcd934x_codec_parse_data() Date: Mon, 27 Oct 2025 19:33:57 +0100 Message-ID: <20251027183529.525896187@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@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: Ma Ke [ Upstream commit 4e65bda8273c938039403144730923e77916a3d7 ] wcd934x_codec_parse_data() contains a device reference count leak in of_slim_get_device() where device_find_child() increases the reference count of the device but this reference is not properly decreased in the success path. Add put_device() in wcd934x_codec_parse_data() and add devm_add_action_or_reset() in the probe function, which ensures that the reference count of the device is correctly managed. Memory leak in regmap_init_slimbus() as the allocated regmap is not released when the device is removed. Using devm_regmap_init_slimbus() instead of regmap_init_slimbus() to ensure automatic regmap cleanup on device removal. Calling path: of_slim_get_device() -> of_find_slim_device() -> device_find_child(). As comment of device_find_child() says, 'NOTE: you will need to drop the reference with put_device() after use.'. Found by code review. Cc: stable@vger.kernel.org Fixes: a61f3b4f476e ("ASoC: wcd934x: add support to wcd9340/wcd9341 codec") Signed-off-by: Ma Ke Reviewed-by: Dmitry Baryshkov Link: https://patch.msgid.link/20250923065212.26660-1-make24@iscas.ac.cn Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- sound/soc/codecs/wcd934x.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- a/sound/soc/codecs/wcd934x.c +++ b/sound/soc/codecs/wcd934x.c @@ -5011,6 +5011,13 @@ static const struct snd_soc_component_dr .num_dapm_routes = ARRAY_SIZE(wcd934x_audio_map), }; +static void wcd934x_put_device_action(void *data) +{ + struct device *dev = data; + + put_device(dev); +} + static int wcd934x_codec_parse_data(struct wcd934x_codec *wcd) { struct device *dev = &wcd->sdev->dev; @@ -5030,11 +5037,13 @@ static int wcd934x_codec_parse_data(stru } slim_get_logical_addr(wcd->sidev); - wcd->if_regmap = regmap_init_slimbus(wcd->sidev, + wcd->if_regmap = devm_regmap_init_slimbus(wcd->sidev, &wcd934x_ifc_regmap_config); - if (IS_ERR(wcd->if_regmap)) + if (IS_ERR(wcd->if_regmap)) { + put_device(&wcd->sidev->dev); return dev_err_probe(dev, PTR_ERR(wcd->if_regmap), "Failed to allocate ifc register map\n"); + } of_property_read_u32(dev->parent->of_node, "qcom,dmic-sample-rate", &wcd->dmic_sample_rate); @@ -5065,6 +5074,10 @@ static int wcd934x_codec_probe(struct pl return ret; } + ret = devm_add_action_or_reset(dev, wcd934x_put_device_action, &wcd->sidev->dev); + if (ret) + return ret; + /* set default rate 9P6MHz */ regmap_update_bits(wcd->regmap, WCD934X_CODEC_RPM_CLK_MCLK_CFG, WCD934X_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK,