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 7121A331209 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=h2IRW/6qss7bkUtWaw1AppoDpiy3lPB5sfhE09Rs5Haw1vHxKibbNrzVhDNtk++qcmW6qqaLVn92/T1ETfdpLmdjmyyLynF2C1MdmwFAov9wRFcnl3jycA30o8YhTozNrD3S4ZyhXnYIGOrVL/UvU1XZtBM4w9rpfR7D32jhJgE= 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=FQntqbrv; 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="FQntqbrv" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 663HiI1O494262 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-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f68jytkg5-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-f71.google.com with SMTP id 98e67ed59e1d1-38127ae6b99so1224594a91.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=lists.linux.dev; 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=FQntqbrv9RD4XWaGkAPCr9uxWMNl3LE5mDWs8MmpxzV1xAq3wV8JWgTwF419dgXM9X zyRQMAi/+8IwA2+aDTIMD6b2XIaRHXSdjaDhP7oDWfTn87LcnrTdQCWBsOKlkNPWqpkF bv0fB9EqXWWrjquWPUi6OiAqXwgR3XYKdDdc3UJ/EZQpBlYbL4Gx4404ukGGp9nvVsV/ sRb592vhMce1SSXZVJ0dYEWhGPqwIWM6DFLz7BJSxwmLJazQks3QtTrTdoT0qfiYNMTo nm/YYpe1isOu+efPEB1sjcdS4Sim24pnI8nX0DbsXFB/V9PKjUkVeUBe85Xm9df+QAuM RbLA== 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=BSJp86eV4mVccblAI6vCXn5imTh4TYKolR7P/2sAePLrjuAbk8WppHz6dBcQV+LnJT 7gJAxsLe4HGf5Gw7/cUPNIL6mCFI4Xisn/k/KYUs4EfYmL3qvMj5Lk7ppIxMxoQPhksx 6BWN3zvbptsrjdcge3z32wHDNdOSBDW5+pLkwVGzz3oEzcRU3nWOZk5cYEoTGruTvqx7 ld/qXittBMbqLxsyz7j62jJM9DXERNQfNwvM+pt3X5xvSk7AzBmeIJzKcuX4ur3Lf8vV PwfXOnpYD9EgrdNN+rROYG+n3/ODx6IfK+GPezd5YGtrdOpnIHHbxBK9S3EJNL4vKsIu nprg== X-Forwarded-Encrypted: i=1; AHgh+RqU+4Cpzn7/AO5tU3nxlvDN20wGY/oNtxUhVNnSEQ/wudpuddaokLiN/wPvebyHdeidKbg8xKFAhEZg/Fro@lists.linux.dev X-Gm-Message-State: AOJu0Yxwo9UDw2jc30YHxef08xPbrehRFY0whFtLALEP8cFhyxGsIBDT bItsEcBzbClhwIksc6++dKFixu391Ho3HnABsn8eBzDvcD3wxDr3GfGIFJGiYWHOH+VA5F24+oS yRAAAgTjelA3uxIeKVTaS9VlaXEOdo3eKQXDGtCBKAlVi5siXe4pvDicMoOhSatAy2LeH X-Gm-Gg: AfdE7cmzmneWxMrdvPzB2jFQjM6zMJMDZ7mZg0o9EFFk7DDNcidui1/3zgMsJeELZWD mwuPNR84JhMbNUBzyTYEFgov/g8ZRUPcWMejqwWYTWFdva+1QChI4avIop1KZmCEXQjSDyX/O9+ 0irIM4dU3YB0OyipyJl5x39Y+8x7kWnhKBn9ocBe4Kv7RDYgACaAMlFyJjHpl6d4j7jYxYiafWu 9eFV5H4C1xB6kOM78wrdCa9Ly8n1H3OfU1kyUSxIMFZYe40FCI5zzs9KtUR1vcycNKef1KuPMFw Rl1BMcHCUQ5PXKFjhhS3bkxCSNLJ1FvyAButAy9AXVz0bDnufP93NtrgagYny+6ZjVaZdxoJ3Sv uKdGEIZ/lREdo+89blfKVA3aiDRaadpWCIaH8Pg== X-Received: by 2002:a17:90a:e70c:b0:380:ce69:2669 with SMTP id 98e67ed59e1d1-381122ebda9mr5933751a91.9.1783107590254; 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: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzAzMDE5OCBTYWx0ZWRfXyZaxmsaWjhAf /UE3iPwqXx5tm4HKC0XzYCATdK28oo2tdQnll5OrHtpKUZwJlW/EVo7MCwfD3y13Y1y47M1TD7P TqSOnzw3obdYy+dEVeBsHvnbyirk96ZTjbApOBNitZXUElFT7c7yoTwJgyjqCyyMGAi1HvwoMI7 d0mfZ6Zi0eod8xh3ytdo4GsSY7HKHU9C1/OTA223gZKAE/KIjrOGSAd33SOtJ6p2tuLdVI3ZwX0 4OPK0AyGlMMHvOPUKWkQ58/ZTNxyusaD034Uxe5BAz1f4xRUjLcswYzFkfiTk55kleszKrmYJl7 DnhR14a1tlhfDCEDmCIxNFRAEkhZ7cPVp1iogYJYw3eb6h58jAddKJ1YzUqM2jNNn9VQd6LN/YI 4KUHtUsBr2krEzl/9zCiU++tzzofEPn3c24/d8Wv33+R9tUiPTmtX7IZrEz/bxDYBVVSBGBvwbp LiFkBUYNPg22CWohHjg== X-Proofpoint-GUID: 5e7itoSTh5o33XAIBjnWqJnRaRlFOmIC X-Authority-Analysis: v=2.4 cv=QbFWeMbv c=1 sm=1 tr=0 ts=6a481007 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=C96w-YAaP-Zupzk_Mv8A:9 a=uKXjsCUrEbL0IQVhDsJ9:22 X-Proofpoint-ORIG-GUID: 5e7itoSTh5o33XAIBjnWqJnRaRlFOmIC X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAzMDE5OCBTYWx0ZWRfXz1dw3m0zlYc6 jLpWjeiCau5yJTGkgEn49PFdVYQkGWamRYf8KY5tU3kbULHTPklalM2Pp+5vIx2bWFI+v5F1r/Z yBWErLBq2d1bhTtuR/Jfo3VYwVLQihc= 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 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 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