From nobody Tue Apr 7 14:04:17 2026 Received: from mail.unwrap.rs (mail.unwrap.rs [172.232.15.166]) (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 3761C1534EC for ; Wed, 25 Feb 2026 23:54:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=172.232.15.166 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772063672; cv=none; b=r6kMcMOi1XKn1KwN8Ne0g7jGCG3YlDujDrN/SxNwJMr7mxDj7Ac6Z3TLdKxsi7Xk6/xY5GyNVuluAiiYBXsmPp4VAvZI52W3V0efRgOgdsmVHaEyGBQOB9t3d3iU61v57VwwzJS9zP8o0PS8yVOO9r3451dOX/+pu8+0J4EpECM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772063672; c=relaxed/simple; bh=dWeyK97MysGz4yse0rNuLpj11M3Y4gvQUxxxnpjrn4c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hwXCm0oA8SnUmm+IgHQ9+LfSzGWFhtk1/GqhIxtiY7Ev1/1zZto25N8o1CYPla3RhU5MVEfgJfvfwhvmgGD1+43zea5kr8EFTyipsSQ/n3MuMZwf153u1tXnQ6c5q4pw16qrtu/5LTSol8E4BCcJZQorAopUA805ZDqNeyQotvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=unwrap.rs; spf=pass smtp.mailfrom=unwrap.rs; arc=none smtp.client-ip=172.232.15.166 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=unwrap.rs Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unwrap.rs From: Cole Leavitt To: kees@kernel.org Cc: tony.luck@intel.com, gpiccoli@igalia.com, linux-kernel@vger.kernel.org, cole@unwrap.rs Subject: [PATCH] pstore/ram: fix resource leak when ioremap() fails Date: Wed, 25 Feb 2026 16:54:06 -0700 Message-ID: <20260225235406.11790-1-cole@unwrap.rs> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In persistent_ram_iomap(), ioremap() or ioremap_wc() may return NULL on failure. Currently, if this happens, the function returns NULL without releasing the memory region acquired by request_mem_region(). This leads to a resource leak where the memory region remains reserved but unusable. Additionally, the caller persistent_ram_buffer_map() handles NULL correctly by returning -ENOMEM, but without this check, a NULL return combined with request_mem_region() succeeding leaves resources in an inconsistent state. This is the ioremap() counterpart to commit 05363abc7625 ("pstore: ram_core: fix incorrect success return when vmap() fails") which fixed a similar issue in the vmap() path. Fixes: 404a6043385d ("staging: android: persistent_ram: handle reserving an= d mapping memory") Signed-off-by: Cole Leavitt --- fs/pstore/ram_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index ed97494abf60..0cc971f70eb0 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -493,6 +493,15 @@ static void *persistent_ram_iomap(phys_addr_t start, s= ize_t size, * there is no need handle anything special like we do when the * vmap() case in persistent_ram_vmap() above. */ + /* + * ioremap() may fail. Release the mem region and return NULL + * to let the caller handle the error. + */ + if (!va) { + release_mem_region(start, size); + return NULL; + } + return va; } =20 --=20 2.52.0