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 10F653D1CD1 for ; Mon, 15 Jun 2026 15:22:55 +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=1781536977; cv=none; b=XlPOrhHc4KNn+rz8VXmPYLuVGwbhBH8tUDEjZPtZvQMrELN9kighpi/qifCQ5EpTSVuGtds0pAHYgyqHsHcn6vB/rfh/6SPZQ0Q03xJWu3z3ISoifo8qMM6M6++24v0Hxm5lS6VwFIzf+H9arg87Ku2p2yoxEEElh3lqMvnr3D0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781536977; c=relaxed/simple; bh=3MZoQTA89UBII/UlCCyNFf/wK8Zaem+x1/iBAFHrQ48=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=IsaRq+PwzM17K0YOGT5EPgXVKR2eEPK9cUpnkwDqTu+TcuzS1YBQzC0LHBN2bgHUNQBwK05d3RIf2v24IexxM07RyqfTA+XO7y3ib9zr3D4RyXEx55P+i2cqghH4CxWptItavmLkxfeuM7z9RdU4f7aMUryrOV40/PkfyZFYD7U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0kG16Hat; 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="0kG16Hat" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7E6D1F000E9; Mon, 15 Jun 2026 15:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781536975; bh=RQAT4tQl6nI3eaSzpj1T/vkfPeb0TZ1ucIKNi69NIsY=; h=Subject:To:Cc:From:Date; b=0kG16Hat/YOLTbHbEf19CwioxiBeatdp0yNLBiFGDi84Do5W31wiPjYRWj1Pbd4+G ZJn1yqiXGc9k6CPqSQ0C/O1fElN1qyAYGRCJfQkZ7TLYxaK2mkcA18Rn7vfNj/NPb2 QVQPhNWumSft9UkpmUni881WCJc3MEcAAK3CosPE= Subject: FAILED: patch "[PATCH] nvmem: core: fix use-after-free bugs in error paths" failed to apply to 6.1-stable tree To: bartosz.golaszewski@oss.qualcomm.com,gregkh@linuxfoundation.org,srini@kernel.org Cc: From: Date: Mon, 15 Jun 2026 16:51:22 +0200 Message-ID: <2026061522-petunia-studio-b99f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y git checkout FETCH_HEAD git cherry-pick -x 5b6b6fc491899d583eaa75344e094796ae9b530b # git commit -s git send-email --to '' --in-reply-to '2026061522-petunia-studio-b99f@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 5b6b6fc491899d583eaa75344e094796ae9b530b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 30 May 2026 21:43:40 +0100 Subject: [PATCH] nvmem: core: fix use-after-free bugs in error paths Fix several instances of error paths in which we call __nvmem_device_put() - which may end up freeing the underlying memory and other resources - and then keep on using the nvmem structure. Always put the reference to the nvmem device as the last step before returning the error code. Cc: stable@vger.kernel.org Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation") Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time") Signed-off-by: Bartosz Golaszewski Signed-off-by: Srinivas Kandagatla Link: https://patch.msgid.link/20260530204340.116743-3-srini@kernel.org Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 311cb2e5a5c0..e871181751f3 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1468,18 +1468,16 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); of_node_put(cell_np); if (!cell_entry) { - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); - if (nvmem->layout) - return ERR_PTR(-EPROBE_DEFER); - else - return ERR_PTR(-ENOENT); + ret = nvmem->layout ? -EPROBE_DEFER : -ENOENT; + __nvmem_device_put(nvmem); + return ERR_PTR(ret); } cell = nvmem_create_cell(cell_entry, id, cell_index); if (IS_ERR(cell)) { - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); + __nvmem_device_put(nvmem); } return cell; @@ -1593,8 +1591,8 @@ void nvmem_cell_put(struct nvmem_cell *cell) kfree_const(cell->id); kfree(cell); - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); + __nvmem_device_put(nvmem); } EXPORT_SYMBOL_GPL(nvmem_cell_put);