From nobody Tue Mar 28 07:25:06 2023 X-Original-To: dev-commits-src-all@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 4Pm1RQ4hJQz41WV2; Tue, 28 Mar 2023 07:25:06 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pm1RQ3jdYz3qGp; Tue, 28 Mar 2023 07:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679988306; 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=OhcXr2K3zfd0bShnJXtL1xjZxYgbEWiVNa3ScAcYAVo=; b=K6UNleLrBWUdqCRXZBeDIs6m9EMY+sMiygEpFKjuQX+2+tw8JgBC86dlDyhJEu2r3/4xXi SODgwYERV/hsnxQdhUPWGgM5PkvGNovL6BGdn1ceFjflKUxjZ0maDQqm2VAZyrIXbm8UcM MdNFqOJ/w2kolJeX/3tT9MWYCfS5xagiy+ncOSRxnkgzQ9MneTj9QWLJcVoLg9LfuCyETi pGKJIhtmtX0HYjp2V8Hkbs2HLl9U9cCf6mEniXiFPp6IsUDc91yLiInqVw0SaX4Iz1nuoB msJ5lc90PynU3ZTlBTGek+Ycab6T2DbVMhJsyXeC6sN57KC6wbIU4fuujk5kyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679988306; 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=OhcXr2K3zfd0bShnJXtL1xjZxYgbEWiVNa3ScAcYAVo=; b=PYVJPThb+2y/94ZrmHQdlmNrgfc0OnseakcT9XK4qOCPX/sCmZvqQ1CqUtwHKiBZXyTAt+ 4ivHwZg1x+/KkC9EXQ8H/M444bmsLA+3wfqwqeK7iJvDRJiusgz2RMk5kLbdcwZFPOy+nW Lg1O/4NvKKFE5+vF9GULsFdOXvq37M7knDzbfim/0HWKURbt9vPyh+ix0RUrDzcsuEPL6q mGmrozYbFefiCCVU4t/b2EtfZcyQe6IkGD9AZR7kB+Dk6abuZ+6Bbgt+AN1vPFMLq8EPXf LzOY00qC8BxgNtUwolFUsIqLrvhVm4BiuDFMJ9ZG9uGGejt1vK4E8VkGpl1jCg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679988306; a=rsa-sha256; cv=none; b=tnCUgXxhrzf8yAfaWuUHEt9bUkjuW+QgB24sRDwmj5HdCsDqiYgcvkXeOJrpFq0NOh9hXB 2tCKMph+fTyqrGbb4R/knbBLhd42cn1YEWE+r/0ruxS3oWdGxCQTqqH2zMW2VsAp37/Dil R3YxasjzA5n1pidBrHO2pjugu2frds8UwbkHTL3OuG2swWh1m4n2lcDyXlmjiK0vHU2Q0m 31OuDKcmRA4+XsQVNrXmov7idEinJTFYAXPSwuNFaMhctbNRErhBA1pUXMQPSKc+V86Ok8 8wZZY/LObC7diFD08TQownqnUgyC/Ms3PG+bA7Jbt7Fo+CM0nzhzn4EM6C6IEg== 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 4Pm1RQ2SW1zvyc; Tue, 28 Mar 2023 07:25:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32S7P64H036534; Tue, 28 Mar 2023 07:25:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32S7P60m036533; Tue, 28 Mar 2023 07:25:06 GMT (envelope-from git) Date: Tue, 28 Mar 2023 07:25:06 GMT Message-Id: <202303280725.32S7P60m036533@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: aaf6129c9dcd - main - linuxkpi: Add devm_add_action and devm_add_action_or_reset List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aaf6129c9dcde5eb020f585901a6f32d850d8cf6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=aaf6129c9dcde5eb020f585901a6f32d850d8cf6 commit aaf6129c9dcde5eb020f585901a6f32d850d8cf6 Author: Emmanuel Vadot AuthorDate: 2023-03-17 11:22:06 +0000 Commit: Emmanuel Vadot CommitDate: 2023-03-28 07:19:05 +0000 linuxkpi: Add devm_add_action and devm_add_action_or_reset Those adds a new devres and will exectute some function on release. Reviewed by: bz Differential Revision: https://reviews.freebsd.org/D39142 Sponsored by: Beckhoff Automation GmbH & Co. KG --- sys/compat/linuxkpi/common/include/linux/device.h | 7 ++++ sys/compat/linuxkpi/common/src/linux_devres.c | 43 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h index 4b665e8db8d1..df6f10bd573b 100644 --- a/sys/compat/linuxkpi/common/include/linux/device.h +++ b/sys/compat/linuxkpi/common/include/linux/device.h @@ -680,4 +680,11 @@ devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp) #define devm_kcalloc(_dev, _sizen, _size, _gfp) \ devm_kmalloc((_dev), ((_sizen) * (_size)), (_gfp) | __GFP_ZERO) +int lkpi_devm_add_action(struct device *dev, void (*action)(void *), void *data); +#define devm_add_action(dev, action, data) \ + lkpi_devm_add_action(dev, action, data); +int lkpi_devm_add_action_or_reset(struct device *dev, void (*action)(void *), void *data); +#define devm_add_action_or_reset(dev, action, data) \ + lkpi_devm_add_action_or_reset(dev, action, data) + #endif /* _LINUXKPI_LINUX_DEVICE_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_devres.c b/sys/compat/linuxkpi/common/src/linux_devres.c index 96ff3e486d1d..0072713af322 100644 --- a/sys/compat/linuxkpi/common/src/linux_devres.c +++ b/sys/compat/linuxkpi/common/src/linux_devres.c @@ -224,3 +224,46 @@ lkpi_devm_kmalloc_release(struct device *dev __unused, void *p __unused) /* Nothing to do. Freed with the devres. */ } + +struct devres_action { + void *data; + void (*action)(void *); +}; + +static void +lkpi_devm_action_release(struct device *dev, void *res) +{ + struct devres_action *devres; + + devres = (struct devres_action *)res; + devres->action(devres->data); +} + +int +lkpi_devm_add_action(struct device *dev, void (*action)(void *), void *data) +{ + struct devres_action *devres; + + KASSERT(action != NULL, ("%s: action is NULL\n", __func__)); + devres = lkpi_devres_alloc(lkpi_devm_action_release, + sizeof(struct devres_action), GFP_KERNEL); + if (devres == NULL) + return (-ENOMEM); + devres->data = data; + devres->action = action; + devres_add(dev, devres); + + return (0); +} + +int +lkpi_devm_add_action_or_reset(struct device *dev, void (*action)(void *), void *data) +{ + int rv; + + rv = lkpi_devm_add_action(dev, action, data); + if (rv != 0) + action(data); + + return (rv); +}