From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 712A93314AC for ; Fri, 3 Jul 2026 19:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783107594; cv=none; b=AhrbVInkmqM6fq2BXBAN6e1c6eWj5QyUrlJ8WMrX45pF1POlnHj6BLH19saZOpoZSFLG00/ndVdpXlP/foy/lVObQYsPBZu2TYy9rb5SI/dgQ7NknWacUZEspFhH7wYRs/PrwsXDqflBVeocVX2EscRF30h1oE4KtBiQdVDrHMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783107594; c=relaxed/simple; bh=cqEZRJv7tWTgKRoN4adZzdInLmkRCuJ5Uo0VyqJuYaU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sS3H9nLRqjTdU7KfLlaKy9S8YX2h4WLPnoK5R1GmP3FpuVvrpmcrthmmxGNC704BfWWJmGGhSGA+Zan2CzWaZVW2kfckQqAjkmqYs+7s1XQWzcJiNZO0R7yKTDUziO7TcvPxIAa+69DhBlehwDsadMXQpC5KMX2kyQrRYRLUsqk= 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=iZuu44D6; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=imCz7XTN; arc=none smtp.client-ip=205.220.168.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="iZuu44D6"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="imCz7XTN" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 663HjCh8686578 for ; Fri, 3 Jul 2026 19:39:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=kAqGWShsALr UvOo44yJ9PZPqBuVxxzDIDv0SXARnsDY=; b=iZuu44D62fDE9nUkMGsQ/kikCWN vJtcLEgw6+dGCeIIHuOlMsUIpFKZZGJPJqfdF+O1SYEhJ9Ewxr3bmWpbtRmLiIqQ jYkNIvEv+KCpR6MtdXix1MGky2N2ZQ+IKKh/NsqwJzV4809aM+q8nNtoVSj4h9GS 7ZOJF8MX23ckx9HxrND4qmrfOFK47QtXOdWwXxI5gur6l6dxQmmA/LR6so3jKGq/ W7A00TMFaZJ0ko+VVC0tHFFvu0ryV81DeIP4S6UmjKnzb0SJmxCATCZFjAZe9zfa KCzmbOBkJT97xvyMzhw69zt86W2jJf7+4G93pb8Mz+QzA56HX9qkqRm3E6A== Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f64b5brnn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 03 Jul 2026 19:39:51 +0000 (GMT) Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-37ca4367860so2242064a91.1 for ; Fri, 03 Jul 2026 12:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1783107591; x=1783712391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kAqGWShsALrUvOo44yJ9PZPqBuVxxzDIDv0SXARnsDY=; b=imCz7XTNXbbxst+q2sIytN6PFNeB73MLPbAvkC1cHwORS1GGW+IMJGRWSF5dap8Lpl WnSCd7s9Dm7NTis237Lwd8OSC2ys+uLI/5JV1vFO81PgU6kto8u6rlHDDjAYAXHv0JEZ UjJkDkuLVmFYDdPrk8TPC4tnXmPnnIIor4xdZcle9aOVUpC2iCL41L8C207+PzjVu0P5 ObdtEf1BzK/Qm6exA+zzkX92CsH0MDT1kaOf0iJYbtbNY9mFtzGB27IstY8fKOmXgzfY EYcI7V1XRwpJ6CTprWCOl0IzDVN6A/zpkbV9Gt7yIzmHmouD7f5hDOb1o4RAT5Gkvcgq YdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783107591; x=1783712391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kAqGWShsALrUvOo44yJ9PZPqBuVxxzDIDv0SXARnsDY=; b=fx+OPWbMzMIV2CgvMpYKoNzAsf0BxDLKOGJsipnNNm/ca5jdy4RoaJsCxDMZU4zt6H qQHZOB75qYE8fkQidoDJdkl76Vs5p40PNWulEE6ZitOBWbQt9ZX1TVVmiV/72LTD3oyn C6nyQZ/GefsaMxu8LFLyUtLl4iPug0pMERbg4RDkw9lQlxV27bpMXlHyeqH8UzDw0MBF zdgIbvb/9pkLdm5mAjslkuD5qHcM4nk4QjN19+jDFWW5Rpx/De/zXKMYRBO1GTzXfK58 Q98oCajmH2g6tHW5o9RP1IdESjP3vRMuKUv5X41PVDI77nNhHBxWjdPFmm3bE3nwszpa 0MsQ== X-Forwarded-Encrypted: i=1; AHgh+RpVw/t4Ton7jEOpViDltzsfG5sGvlleFOMuiqmHlKpZGO1/fbKmnsp3p9L1YG/fOjlv6VIucQFJT6Qd@vger.kernel.org X-Gm-Message-State: AOJu0YxJesmmrIdH5yX9OYJCGb1afHAYoGb66TtDBEjtRK3V0QeitxI4 lUoq7YMx8514Y8Xt6fjWCvmyyS2xUFQPAgI7WCZcDMBoTTgR+pj10ZwageOAAiPofa+Y5dWEve2 /WSj9XtgT8/wBS8MjQdd50vSPas5rCt72TemO9+lW/x/JyFg488Nt+TI7ICN9+V7u X-Gm-Gg: AfdE7ck5Qg3T9W7uVNIwev/CQFpZ/AuVvBOF/7lG+Uxc7tsmk/12lXnoTVui4/vRmHS 0YbXDufqy92KF+YzUEjSkk1DH7IaKMHaWE9VwxeqD66a1jhMXbWyDV+0WYL5MwXpSgf+gMBmPuN DtA61j5C7hcbeN8NDqYKje7a0QiGwCH1o40ujYi3NK5q6+hGuaxy0QVN3x4Kouj8ojSdOU8JcmW 0hzaQzZnO4GhFJuGjdqw3knHCgvYlihoxECOJB9+AK6aMpUd4uDGFrN5m5dZEh8bFp/+kWYkROm Sgfd0fYmUZ2E1I6s2GHmbWy/lriFSkEiMt5k0sert0N1clkaZF7eIZ5Eb7sMDeAiWNlCw7OEs+c ooKdF9V4gTfm9u7GQMDCpKeAOownpLZ/DrE21qw== X-Received: by 2002:a17:90a:e70c:b0:380:ce69:2669 with SMTP id 98e67ed59e1d1-381122ebda9mr5933746a91.9.1783107590252; Fri, 03 Jul 2026 12:39:50 -0700 (PDT) X-Received: by 2002:a17:90a:e70c:b0:380:ce69:2669 with SMTP id 98e67ed59e1d1-381122ebda9mr5933658a91.9.1783107589588; Fri, 03 Jul 2026 12:39:49 -0700 (PDT) Received: from hu-mojha-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30f290b6bc2sm10065845eec.27.2026.07.03.12.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2026 12:39:49 -0700 (PDT) From: Mukesh Ojha To: Bjorn Andersson , Konrad Dybcio , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Joel Stanley , Andrew Jeffery , Paul Cercueil , Anitha Chrisanthus , Paul Kocialkowski , Linus Walleij , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Alexey Brodkin , Laurent Pinchart , Tomi Valkeinen , Michal Simek , Daniel Scally , Jacopo Mondi , Mauro Carvalho Chehab , Eddie James , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Minghsiu Tsai , Houlong Wei , Matthias Brugger , AngeloGioacchino Del Regno , Joseph Liu , Marvin Lin , Dmitry Osipenko , Krzysztof Kozlowski , Thierry Reding , Jonathan Hunter , Srinivas Kandagatla , Arnd Bergmann , Greg Kroah-Hartman , Ge Gordon , Adrian Hunter , Ulf Hansson , Rob Herring , Saravana Kannan , Mathieu Poirier , Jaroslav Kysela , Takashi Iwai , Shengjiu Wang , Xiubo Li , Liam Girdwood , Mark Brown , Frank Li , Sascha Hauer , Peter Ujfalusi , Bard Liao , Daniel Baluta , Orson Zhai , Baolin Wang , Peter Chen , Fugang Duan Cc: Ekansh Gupta , BST Linux Kernel Upstream Group , Fabio Estevam , Nicolin Chen , Pengutronix Kernel Team , Kai Vehmanen , Pierre-Louis Bossart , Vijendar Mukunda , Chunyan Zhang , CIX Linux Kernel Upstream Group , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-media@vger.kernel.org, openbmc@lists.ozlabs.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-tegra@vger.kernel.org, linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-staging@lists.linux.dev, linux-sound@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, imx@lists.linux.dev, sound-open-firmware@alsa-project.org, Konrad Dybcio , Mukesh Ojha Subject: [PATCH 01/42] of: reserved_mem: Introduce devres-managed initialization functions Date: Sat, 4 Jul 2026 01:08:14 +0530 Message-ID: <20260703193855.110619-2-mukesh.ojha@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260703193855.110619-1-mukesh.ojha@oss.qualcomm.com> References: <20260703193855.110619-1-mukesh.ojha@oss.qualcomm.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAzMDE5OCBTYWx0ZWRfXw4ZGeVcShg0g iBq/VyFJV2vET7F3Nwn4v7sUhaSfRrBQgvCSZ4lBmEkRh6qKsDwZCO1siEElJUqZ3kxnumi5IoI linlTXvPjWgvX62+UHPgzFIYxmeAjkw= X-Authority-Analysis: v=2.4 cv=FOQrAeos c=1 sm=1 tr=0 ts=6a481007 cx=c_pps a=RP+M6JBNLl+fLTcSJhASfg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=C96w-YAaP-Zupzk_Mv8A:9 a=iS9zxrgQBfv6-_F4QbHw:22 X-Proofpoint-ORIG-GUID: yioXcmJGYjMK1CUgC9PzB7BQY1M_u12b X-Proofpoint-GUID: yioXcmJGYjMK1CUgC9PzB7BQY1M_u12b X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzAzMDE5OCBTYWx0ZWRfX9PQbElFc7chJ TkCW+r+Hit2/HjKQNxa+BXS1VdQEup138oy0KkFVt/FrFx3NQQfAMb0r9Pf7tZnIuEjlQTgSN9K bjvucIZTXLSOGPQzmwT52v/GBSLGq48gnjq2jcCmvGw+ZmRdswZA1BUKCmj13G9t/AjL+3HC3V1 AHVKgXq3duZ/NsrNHGI9QTZqrXY7iY5S4OhfWOKUes8SchSuHxM1l+zBggDmPxesUI6aA1c9+b6 JiaBpLKMEIM9Sn5PyxdoOcWJaiAqEM5UWT5GuXn6lr8Uhw5vdmT7lkNPOvFDhX9qiXKYQuO8uvZ qdrCggGP5Fns7xoEWdeH1lNS5stMMFG8pe1bDwltcjKHjNSDq3XXOeUDX0md62eUUmPwSP6Nboa de6lP2ZxSHZELDiKEmH9ptsLPPudGd0vmoHgg1y5ZPIy99WcYqM07x1kpYHAkK+0gJUxyxPmURn Cukj3vCaMKR7IAV9iEA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-03_03,2026-07-03_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 clxscore=1015 malwarescore=0 phishscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607030198 From: Konrad Dybcio Introduce devres-based helpers for of_reserved_mem_device_init(_by_idx) 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 --- drivers/of/of_reserved_mem.c | 41 +++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 25 ++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 82222bd45ac6..b35541e9fbe8 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -787,6 +787,47 @@ 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); +} + +/** + * devm_of_reserved_mem_device_init_by_idx() - Resource managed of_reserved_mem_device_init_by_idx() + * @dev: Pointer to the device to configure + * @np: Pointer to the device node with 'memory-region' property + * @idx: Index of selected region + * + * This is a resource managed version of of_reserved_mem_device_init_by_idx(). + * 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_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; +} +EXPORT_SYMBOL_GPL(devm_of_reserved_mem_device_init_by_idx); + /** * 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..b9fd78123d77 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -40,6 +40,9 @@ 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_by_idx(struct device *dev, + struct device_node *np, int idx); + 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 +71,13 @@ 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_by_idx(struct device *dev, + struct device_node *np, + int idx) +{ + return -EOPNOTSUPP; +} + static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) { return NULL; @@ -108,4 +118,19 @@ static inline int of_reserved_mem_device_init(struct device *dev) return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0); } +/** + * devm_of_reserved_mem_device_init() - Resource managed version of 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 error code or zero on success. + */ +static inline int devm_of_reserved_mem_device_init(struct device *dev) +{ + return devm_of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0); +} + #endif /* __OF_RESERVED_MEM_H */ -- 2.53.0