From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (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 4C41F2DF68 for ; Thu, 17 Jul 2025 09:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752743321; cv=none; b=bnWBAtfjCQa39viX7o5Q7cnWBOghIejHhZ375h9vDjnblTY722SrlUcLh0ZqaYVOpSFinS8BO/+jymlXbv78ywPDqKdBd7Jl1PqyORw4igftZCdgjXzwAWq6pLip3KzN1sizx+6lMxT6eN6h+7x56YCRvS2fc2fIxolADOXFkAQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752743321; c=relaxed/simple; bh=bGbkeH3UzSnkKV/TrdEg2b6wrUlUl3RzjeZN571VM9o=; h=From:Date:Subject:MIME-Version:Message-Id:In-Reply-To:To:Cc: Content-Type:References; b=XnH3JFWHwqipd5lDu/lHQYwt2XQSS8BhONPToJQv0/NE9h+pnkF/pzZxQcGSGitTYhCu7l+4sklEqHiTD87N//l5qOY2FJvBPeHlrP3LzMyjJy+jad/vH1KxjsiRzzzRtq0oSZxMSdhNaaTqFCMHwf3tMJh58a9axEsOocV55nY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=o2motPbh; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="o2motPbh" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20250717090831euoutp0226e85dd7c87f792fcd31251edc6a100e~S-sFw3zp_1531515315euoutp02I for ; Thu, 17 Jul 2025 09:08:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20250717090831euoutp0226e85dd7c87f792fcd31251edc6a100e~S-sFw3zp_1531515315euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1752743311; bh=nDSmSNpkyDqN+0uDTeiaM6bqnry5ClWU0W8WQ15siTk=; h=From:Date:Subject:In-Reply-To:To:Cc:References:From; b=o2motPbhm36QUgClLstkmJ71FnCsOblOikU3CBdS6drDSzEefOnO2VXf4t5fEDfZq bwiLlex21BG2k2XWnN04qNaVPAfvuzv4Y5MBfM1FbzODbJNVkD1M6gT2Kuirqt7sRO Ndop7P3M4N4BHFGhA5gddhoVdHd/ivmV2HJ9O7N8= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20250717090830eucas1p191fbd4e0baa40468884307a1b6277be3~S-sEtNIw52894328943eucas1p1k; Thu, 17 Jul 2025 09:08:30 +0000 (GMT) Received: from AMDC4942.eu.corp.samsungelectronics.net (unknown [106.210.136.40]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250717090829eusmtip219cf93ca91b35a023e836ca35c24a3eb~S-sDm3ayG0473704737eusmtip2k; Thu, 17 Jul 2025 09:08:29 +0000 (GMT) From: Michal Wilczynski Date: Thu, 17 Jul 2025 11:08:23 +0200 Subject: [PATCH v12 1/3] pwm: Export `pwmchip_release` for external use Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-Id: <20250717-rust-next-pwm-working-fan-for-sending-v12-1-40f73defae0c@samsung.com> In-Reply-To: <20250717-rust-next-pwm-working-fan-for-sending-v12-0-40f73defae0c@samsung.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Michal Wilczynski , Drew Fustini , Guo Ren , Fu Wei , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Marek Szyprowski , Benno Lossin , Michael Turquette , Drew Fustini , Benno Lossin Cc: linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org X-Mailer: b4 0.15-dev X-CMS-MailID: 20250717090830eucas1p191fbd4e0baa40468884307a1b6277be3 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20250717090830eucas1p191fbd4e0baa40468884307a1b6277be3 X-EPHeader: CA X-CMS-RootMailID: 20250717090830eucas1p191fbd4e0baa40468884307a1b6277be3 References: <20250717-rust-next-pwm-working-fan-for-sending-v12-0-40f73defae0c@samsung.com> The upcoming Rust abstraction layer for the PWM subsystem uses a custom `dev->release` handler to safely manage the lifetime of its driver data. To prevent leaking the memory of the `struct pwm_chip` (allocated by `pwmchip_alloc`), this custom handler must also call the original `pwmchip_release` function to complete the cleanup. Make `pwmchip_release` a global, exported function so that it can be called from the Rust FFI bridge. This involves removing the `static` keyword, adding a prototype to the public header, and exporting the symbol. Signed-off-by: Michal Wilczynski --- drivers/pwm/core.c | 3 ++- include/linux/pwm.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 4d842c69219445ff1c97ebdb9f1f64031c183a84..bbf729b95c7b94b05bc25bdc1febafb0f2437121 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -1598,12 +1598,13 @@ void pwmchip_put(struct pwm_chip *chip) } EXPORT_SYMBOL_GPL(pwmchip_put); -static void pwmchip_release(struct device *pwmchip_dev) +void pwmchip_release(struct device *pwmchip_dev) { struct pwm_chip *chip = pwmchip_from_dev(pwmchip_dev); kfree(chip); } +EXPORT_SYMBOL_GPL(pwmchip_release); struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv) { diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 63a17d2b4ec8d0d34a02b05240efb75b637dd99f..82707802ff93432086e5a8f915b519b987c68041 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -480,6 +480,12 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner); #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE) void pwmchip_remove(struct pwm_chip *chip); +/* + * For FFI wrapper use only: + * The Rust PWM abstraction needs this to properly free the pwm_chip. + */ +void pwmchip_release(struct device *dev); + int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner); #define devm_pwmchip_add(dev, chip) __devm_pwmchip_add(dev, chip, THIS_MODULE) -- 2.34.1