From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 AE1F83C0A19 for ; Thu, 30 Jul 2026 07:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785396747; cv=none; b=nEFt6UAGIFNtC2oCEUFxA0khQpP5ReQVFzJZyph3fIFWzQGh1G0GnunGSheUoT2riq7O7CVxxxZBAnI36xbSpXef7GFa3y7+TfnhdtCEX9VNbrxfUShsd9exVELTer2nFITPXF3p/JqmW/+0hJvcW6ozmMSJmSB1Ke273fYTW5o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785396747; c=relaxed/simple; bh=T4AREj5+HianmNbYmA78HX5B12JSJYCHX1SzJU0m8PE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OYIZVdE0T9Bfk/aS3H9Z0Ll8+2oOPpG7a08jUPCuucHKpWryW28kQ6KNJnPU2qzi2eGfWA8xQ/CKn357+Gks6E7oJpG0tOumdspkyjGrSVmKGZ57vzuk7XF8KNAg4BHQStSSltKzPMCsh5yCEi7tzb548E9Y5+Q1tEuuxSabsBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=eIE65cA+; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=DB6L1CW1; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="eIE65cA+"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="DB6L1CW1" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66U7VdLf391073 for ; Thu, 30 Jul 2026 07:32:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=qcppdkim1; bh=eVTfTB4N0vYRMOV+tUMUEwGiB5W3Y86c7/P 8bjIwatQ=; b=eIE65cA+IUiT8Xt5bgvBlqjgj7K41nfXZq7xOMpKXc6C8HeZnCO VF47vzJsigkIKuKjN6towaghLD9c+x90vb9dv7v91fdk0hKvJYgrrAOHS6A2y9Yu voaMTMrsJ7lYij7VEfdPISirRYMI8gjELtmHTYZOB0t72ZytKsHMTK/Tp5KwLpZz ySPuKm8Gu5mGr4v5C44FlXH1q551CMP2JFbhiyX2cK1s1EmdIWewZ0scEPqU351/ g4w994+7Cb3ELVW1vVd1RcMLFFd56KRyMlfITTvPYI8iz3HaGORwGG8ImeB8VQio DYoItaSbeV3R+pnqXkAZOj7iMhZbSPcPL6g== Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fr2a4803v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 30 Jul 2026 07:32:22 +0000 (GMT) Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-c856470fe9fso1722491a12.2 for ; Thu, 30 Jul 2026 00:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1785396741; x=1786001541; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=eVTfTB4N0vYRMOV+tUMUEwGiB5W3Y86c7/P8bjIwatQ=; b=DB6L1CW1JMg+S0QR2JczQztPiQ1vyLBth3+R8f71w3wAWMRvWje7wPSFd2wH8DIh0d hEfkIJxO3MGVoNBYMsjvHx4LHXDedx23NHBCPZ6dLGlSx9jpU3UpkG9fjd04deFU9kvT k2NFuYBm7QyjHpcNlKlmGkt498MU9tk1WTMvkJplLVZFnA02ecclY6OCgGR6m1cN8IyU mCKuFGi0g8m0Us3W0TocfF+qmivCsmyrMPyzy8J2Nj6tfZE4xYk2xyAwI0sNsjU3Ec1+ b6gygP/0DqY8f7JEUtPtSTVXg78p4SvdfeHcU5WS6tZCxpi8TwPcb0Y8Tvs7jIB35EvJ Hrlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785396741; x=1786001541; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eVTfTB4N0vYRMOV+tUMUEwGiB5W3Y86c7/P8bjIwatQ=; b=j5yM4d6IPAQdm7UpzKqN6XaH4CBzvCYehQeN2gMJuxP2CcG/l8ds/Er797AKaQNBI5 YueSlMyaBV6em2+P5mLtACbVcpGnkuUuBh4bZZjSLfrQjTGK6BO8ntUzz6p+DFX7gtPA GDx8YgUrAY9PpUFvasxKflH1nTMt5r7dx7TOMQkTrLNuMQ1IyVZdVjkXCzDYw4jW1Za+ Aa/DVwv6DZe5JSKfay+5gACCuFLl76Pj9POCC2vrPKPhihszqU0sBNaZCkp1A2iBRzUp bhX45DFjcRqfUERUs3lDe2l3RoMiPJ4p1h2XXjCviUACInwba/Nlq3OSuOWig3fEvkyf DLBg== X-Forwarded-Encrypted: i=1; AHgh+RrnMwD7XdzwDH6RhJNXz3TXnm6bfvBf0HAzKSsHVOJ+kwRKpqy7naQasxswwZnqvtA10OEX0HBv3vxrlqk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1N6r21ob47Ur7c2+194jryfBqF6dNWs7DJTzoi+TnJRXMYsed +9SOBBKefH7ZSN9cUgDv5Tj/+FZOX1PFg/gweIM/jln/+wa4fujziNEPpNyZfj3me3q2WlT2y3Q XZcv43/gQuT+F8lWc6IPmx5ll6kT9gkEpCg9j9mt4qPQ8J8YBq7eGrEujYABXxUgB1b8= X-Gm-Gg: AR+sD10tQ7ZtiAZv9VgUH33aQMSn4m5hCG0B8PB49ONk7GNZ+M3+T+6ARlUOZ631pu3 cOAlZYKgloOY1qEvwUeOlqxOHD27+Bu8WoV1xbQg0XX6+PMdmKl2uetojeXsdzlkGkRXDr+D5Gi Is4r7tgykd/BC+j4FqZfPiTtYB3RTThbYrWdKvhkvmC26n8NJof6rnq/9xsFVmuaD4UF5v8XVir ySZFEBl0cF5iP7VpDuI3XWXq7F59zTT7s4V11upeK23ypPI+7iEL8Hm9UYVYPbxGyzU933hsaRn S1MFwkNDGSUF43/HFrbPFq9VixA/sQdqmUb+PK97GeC/pwrBSC1LR3nLtVcXVzW/xbk9/0DWxs3 yfsJHMKIXHu68bLOi96Ia/GGo50w= X-Received: by 2002:a05:6a00:21d5:b0:848:2f74:d8d0 with SMTP id d2e1a72fcca58-84ebc44ebb1mr1613132b3a.65.1785396741152; Thu, 30 Jul 2026 00:32:21 -0700 (PDT) X-Received: by 2002:a05:6a00:21d5:b0:848:2f74:d8d0 with SMTP id d2e1a72fcca58-84ebc44ebb1mr1613098b3a.65.1785396740413; Thu, 30 Jul 2026 00:32:20 -0700 (PDT) Received: from hu-mojha-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84e9fe21994sm2559922b3a.9.2026.07.30.00.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 00:32:20 -0700 (PDT) From: Mukesh Ojha To: Rob Herring , Saravana Kannan Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio , Mukesh Ojha Subject: [PATCH v2] of: reserved_mem: Introduce devres-managed initialization function Date: Thu, 30 Jul 2026 13:02:14 +0530 Message-ID: <20260730073214.1146432-1-mukesh.ojha@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=HphG3UTS c=1 sm=1 tr=0 ts=6a6afe06 cx=c_pps a=oF/VQ+ItUULfLr/lQ2/icg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=C96w-YAaP-Zupzk_Mv8A:9 a=3WC7DwWrALyhR5TkjVHa:22 X-Proofpoint-GUID: N-4vI6A2HDXkoZv06SblUtn-nY0GDvNH X-Proofpoint-Spam-Info: AW1haW4tMjYwNzMwMDA1MiBTYWx0ZWRfX/1FJuW51ZnvT UJlEYYK571GB2NeFQsUS9XPHwwxF6nIdWXAQfNhgSfiwwgWOU30Z1RcSvJSgEWU3wk8vk9iHh4o 8dPzO4KOke4AI/huYXquoUOtZ6QiH3k= X-Proofpoint-ORIG-GUID: N-4vI6A2HDXkoZv06SblUtn-nY0GDvNH X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzMwMDA1MiBTYWx0ZWRfX5AjqIVCJvtft TUf61iYqfjlOBIWmT7khhm8YhLAvhaxVAvqle7PunFuLVn3zFMpMNae8WxIhbZtiWAV/c9IEnKK b32mrrXACWgtckLTkh82E/MDK7nHtxhFDPe2RrrOJetFDQvCNxagKYIDJ/kNQ6hLR+BDcvDpuaR 6KmzGm7HuaRf4YRfKpz6Lku0jBAzdkJ/jXHEwezJLpOrCVi7TlAFxM3vHL0/+qRTrfRbDyJCgeY Y+NEtr3b4aJmsjUQn/Hu6QHxZDfDV/wdr/7lcbMIuHiLtcr2CEwzZzZqgDLDFeUdDYfo1IS4VyZ OUlDo9eEwIxvEIfz1bIkXVLf87paVtuotNqYMHnkwRhgW8JNH37WEkpuQ6cTidg0cRHa2j9clqh /lMWIwdbiXc7HZv73DxWNQcXN3HnkunLpO0wRZAOxCfjicJ1V/kpJ+vMVeYhr2F6wVZ74/ljCzD Hqeplo2w8hZw43SpKcQ== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-30_02,2026-07-29_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 adultscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 phishscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607300052 From: Konrad Dybcio Introduce devres-based helper for of_reserved_mem_device_init() to help fight dangling references and ever so slightly reduce the number of boilerplate deinitialization calls. Signed-off-by: Konrad Dybcio Signed-off-by: Mukesh Ojha --- Changes since v1: https://lore.kernel.org/lkml/20260703193855.110619-2-mukesh.ojha@oss.qualcomm.com/ - Separated from big series with multiple API users to avoid clogging the series. Instead of merging all at once, the plan is to land this API first, then post the individual subsystem patches that use the API. There is enough user of this API given in the last series. - Rebased on latest Linux next tag. drivers/of/of_reserved_mem.c | 44 +++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 7 ++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 7b1616b9c6c2..8c9d6395d6a3 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -796,6 +796,50 @@ void of_reserved_mem_device_release(struct device *dev) } EXPORT_SYMBOL_GPL(of_reserved_mem_device_release); +static void devm_of_reserved_mem_device_release(struct device *dev, void *res) +{ + of_reserved_mem_device_release(*(struct device **)res); +} + +static int devm_of_reserved_mem_device_init_by_idx(struct device *dev, + struct device_node *np, int idx) +{ + struct device **ptr; + int ret; + + ptr = devres_alloc(devm_of_reserved_mem_device_release, sizeof(*ptr), + GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = of_reserved_mem_device_init_by_idx(dev, np, idx); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = dev; + devres_add(dev, ptr); + + return 0; +} + +/** + * devm_of_reserved_mem_device_init() - Resource managed of_reserved_mem_device_init() + * @dev: Pointer to the device to configure + * + * This is a resource managed version of of_reserved_mem_device_init(). + * The reserved memory region will be released automatically when the device + * is unbound. + * + * Returns: Negative errno on failure or zero on success. + */ +int devm_of_reserved_mem_device_init(struct device *dev) +{ + return devm_of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0); +} +EXPORT_SYMBOL_GPL(devm_of_reserved_mem_device_init); + /** * of_reserved_mem_lookup() - acquire reserved_mem from a device node * @np: node pointer of the desired reserved-memory region diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index e8b20b29fa68..49da515859f2 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -40,6 +40,8 @@ int of_reserved_mem_device_init_by_name(struct device *dev, const char *name); void of_reserved_mem_device_release(struct device *dev); +int devm_of_reserved_mem_device_init(struct device *dev); + struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); int of_reserved_mem_region_to_resource(const struct device_node *np, unsigned int idx, struct resource *res); @@ -68,6 +70,11 @@ static inline int of_reserved_mem_device_init_by_name(struct device *dev, static inline void of_reserved_mem_device_release(struct device *pdev) { } +static inline int devm_of_reserved_mem_device_init(struct device *dev) +{ + return -EOPNOTSUPP; +} + static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) { return NULL; -- 2.53.0