From nobody Fri Sep 5 23:29:11 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cJXc767qCz66YlV; Fri, 05 Sep 2025 23:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cJXc74Dxqz41C4; Fri, 05 Sep 2025 23:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757114951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GX7hWqTbOxGFIL4xVERYlBm1D2jqikNgfwqjKZm0bNQ=; b=TkKVuMkASuQmnHUTKvLRRpfRC4xLkQ4kXQC3ApPer5mP8p85OsV4J8FPbnpGZuZyo57nG3 XcuCfDD1yVoV82iNHsdpJcR7f1aS1ix3MTxb157ZCfmZt6JtaSEzyxvJiwMx4Pl5HT/0il nUu7q7GJNxkVFcsbTk1eov4QQsnUIunI3hUVUby3YP+Ut5MghT3DdQf1ONa/AOzdAWKFDX SH58EgDT0xAGIKQcpYOBAe3NmK7YtftIHrlEqTBJHMVUEZbDweIB3CLjFulmMO6QKMFTVq MMeL3Cx29TWYRvg1X7CU0CSELNZZnEdjgIAr1zeki3ofqtADWUyqJsNA3OCrWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1757114951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GX7hWqTbOxGFIL4xVERYlBm1D2jqikNgfwqjKZm0bNQ=; b=o+AYKTgmt9896ehgU2AGR3FQExxsSr5Pvcj0MNY7PNFZ9pg+R+f1m9ZlPo/OaEe2cn+jx1 MWaA5zqdEMTQwJoMB+ZgKpimHQj5fMLac2N6Gjpf5x0F7ArgveOMD9+K7haQeYxxNzcH2R hrvdmdBYB/NeJMoMeHarGd/5fECH1WiTcLGk7nn8dVBAfLXadfmOQ3nGp4eixQx4+Kk3ZL zEcRjhez1k8c0tVIXs/mll1aUHcCSKuODgYX6Lw5LUUioJc2cXBE2uUC/sFZT7Tr6hg5o9 HJtlWgbuv0lFYirzbWbVJ1rRFmLMoBrHSslVm6whppNuJJfsbJ2bD7n1ClW8GA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1757114951; a=rsa-sha256; cv=none; b=BTQkAfejHqkwhuYg71aYuC1kHEjDDEYZk7ndrcpuOb8ohBXD686PwuIOXdbTtalg7p+sQo bnCt0BvkJIbKwWgvRfcfbX4xzZfbpSYJKn5+MfmF7p2rT4P73jcmALLl6/AzYE35vOfARv 1aQnqSNiNJiZgABdrH7dgPqORWtlX0oK+tuJ2UvSFLlrdDz4LxISbmFs/6/wr2igdFpJP7 We4Zc6HBxxasgGl2dpRl7G76Fh6zMkAQB3cLtnNod98uk8+UyfMqAZOaE8jPY+M9x/xztg WgMK79pCQ/M1JWl23FX/P53Rhoj6cKn0quBEcobB2IxA8kaYpYjeLhV2Ct90XA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cJXc73Q7Qz183d; Fri, 05 Sep 2025 23:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 585NTBxe029584; Fri, 5 Sep 2025 23:29:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 585NTBrH029581; Fri, 5 Sep 2025 23:29:11 GMT (envelope-from git) Date: Fri, 5 Sep 2025 23:29:11 GMT Message-Id: <202509052329.585NTBrH029581@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 4ab64e34911a - main - LinuxKPI: devres: divorce dem_kfree from lkpi_devm_kmalloc_release List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4ab64e34911ab06e567caaf07ed18f7770a61cc8 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=4ab64e34911ab06e567caaf07ed18f7770a61cc8 commit 4ab64e34911ab06e567caaf07ed18f7770a61cc8 Author: Bjoern A. Zeeb AuthorDate: 2025-09-04 20:28:18 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-09-05 23:24:17 +0000 LinuxKPI: devres: divorce dem_kfree from lkpi_devm_kmalloc_release dem_kfree() is called from all over the place and should actually do something; contrary to lkpi_devm_kmalloc_release() it can also take a const void *. We have to __DECONST() that though as the entire devres framework does otherwise not take a const argument. This was discovered during the rtw89 upadte to 6.16. Sponsored by: The FreeBSD Foundation (initially) MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52082 --- sys/compat/linuxkpi/common/include/linux/device.h | 5 +++-- sys/compat/linuxkpi/common/src/linux_devres.c | 26 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h index 2556b0c45e49..7dd6340746d2 100644 --- a/sys/compat/linuxkpi/common/include/linux/device.h +++ b/sys/compat/linuxkpi/common/include/linux/device.h @@ -4,7 +4,7 @@ * Copyright (c) 2010 Panasas, Inc. * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. * All rights reserved. - * Copyright (c) 2021-2022 The FreeBSD Foundation + * Copyright (c) 2021-2025 The FreeBSD Foundation * * Portions of this software were developed by Björn Zeeb * under sponsorship from the FreeBSD Foundation. @@ -284,7 +284,8 @@ int lkpi_devres_destroy(struct device *, void(*release)(struct device *, void *) void lkpi_devres_release_free_list(struct device *); void lkpi_devres_unlink(struct device *, void *); void lkpi_devm_kmalloc_release(struct device *, void *); -#define devm_kfree(_d, _p) lkpi_devm_kmalloc_release(_d, _p) +void lkpi_devm_kfree(struct device *, const void *); +#define devm_kfree(_d, _p) lkpi_devm_kfree(_d, _p) static inline const char * dev_driver_string(const struct device *dev) diff --git a/sys/compat/linuxkpi/common/src/linux_devres.c b/sys/compat/linuxkpi/common/src/linux_devres.c index 84f03ba0dd7d..23c91cb5ab2f 100644 --- a/sys/compat/linuxkpi/common/src/linux_devres.c +++ b/sys/compat/linuxkpi/common/src/linux_devres.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2020-2021 The FreeBSD Foundation + * Copyright (c) 2020-2025 The FreeBSD Foundation * * This software was developed by Bj\xc3\xb6rn Zeeb under sponsorship from * the FreeBSD Foundation. @@ -223,6 +223,30 @@ lkpi_devm_kmalloc_release(struct device *dev __unused, void *p __unused) /* Nothing to do. Freed with the devres. */ } +static int +lkpi_devm_kmalloc_match(struct device *dev __unused, void *p, void *mp) +{ + return (p == mp); +} + +void +lkpi_devm_kfree(struct device *dev, const void *p) +{ + void *mp; + int error; + + if (p == NULL) + return; + + /* I assume Linux simply casts the const away... */ + mp = __DECONST(void *, p); + error = lkpi_devres_destroy(dev, lkpi_devm_kmalloc_release, + lkpi_devm_kmalloc_match, mp); + if (error != 0) + dev_warn(dev, "%s: lkpi_devres_destroy failed with %d\n", + __func__, error); +} + struct devres_action { void *data; void (*action)(void *);