Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1253688
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Arnd Bergmann <arnd@arndb.de> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2 1/6] vfio: platform: add capability to register a reset function |
| Date | Thu, 22 Oct 2015 12:10:03 +0200 |
| Message-ID | <qmkYP-7xa-37@gated-at.bofh.it> (permalink) |
| References | <qmkFs-6UJ-7@gated-at.bofh.it> <qmkFs-6UJ-21@gated-at.bofh.it> |
| X-Original-To | Eric Auger <eric.auger@linaro.org> |
| User-Agent | KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) |
| MIME-Version | 1.0 |
| Content-Transfer-Encoding | 7Bit |
| Content-Type | text/plain; charset="us-ascii" |
| X-Provags-ID | V03:K0:sWiI+Y8zkozTbJZ5q5I5QAxpJu1KDijPoG7K1Gfi223CjFNs36W SfeNg6pUOnIj7BTi5AeXM0J0cHF1Pyuk2lA+x6Vh2YFm1NsalWtCMwKVc/5a7w8wSDDXh9X Ndvd/FuDRquleLEAqn2w8Kon0qIZzjxuN8rELGM+O6EDQY5WL5QyJ9ak5xxF0ZyvyOlnb8x /9g6u+6XjiQkwHb9gn0Pw== |
| X-Ui-Out-Filterresults | notjunk:1;V01:K0:utMzLVEAUs0=:2aA+6t/e+iLPmnXbNeLHEx JrqIOKDdAyVNFM7Cwc3n36fYsK+nb0bZ9J/NGwa2IhhlkLGn2XPus4MpsiUDixHyCg39yxKdc scBZRmlUaPEf7nzfb3kgiB7g7YrHmiPZ+JMwAwvlkkQPSaN3DaL55ysafnzQuYw6ff1gySus2 0Vtt2vDgNGKXHMsTR6kzcMBjDwHUoc5DeDhnW+0yuNmw9fPJYsXI86ZzKCINkirvo/to/A5JH VnxsJ9SyfyPMBEX8LbXqINhWG2wTm6miK1rZiXflZTbnpPnDafD+uaYtRk15kWCFdoTSG3OeX SPp6bjIqX4NyP4ToXfRp/edaDIIrJEPNerdw9p1C/+6VFkMvg7bXzMeA9Jb6LzOqe1CWOqlFA 0A1fYMu4vpZvLgdY6y1QN4umJAOnxdm6HTDXH1q5mFWphUjr6ZXVZkcmidPja01Og5vVtud4a BArl1W6tOGo42U4dBzhht5QM4RYKEu60yTzvjbu3A935SW7fTEblEPkr7i81zvHMr6uEQuKhP uiBhiW1KFyLjbFwD7B9g2S0nvq1uCIG/9oyvPibPHtGW0elvjZX5VwrrwMu4livSkAZdaw90U 12HosJk665Ui9iVvdoT+EfXRWzzRl/MCCgxChk4YbJbh+VbvzJPNcNfTJRu9v9/bNpZLJNqz7 bVzAmXULI8piWmrVW6xYqahaae1U5i5TwnTsV/KLcQ36Yq4nMQwX5opTDFiefDOFEE2VZKAyJ mQSV8VP390a0nTMo |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 106 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | eric.auger@st.com, alex.williamson@redhat.com, b.reynal@virtualopensystems.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, christoffer.dall@linaro.org, linux-kernel@vger.kernel.org, patches@linaro.org |
| X-Original-Date | Thu, 22 Oct 2015 12:06:02 +0200 |
| X-Original-Message-ID | <4039449.LR9NiiaAaC@wuerfel> |
| X-Original-References | <1445506922-6005-1-git-send-email-eric.auger@linaro.org> <1445506922-6005-2-git-send-email-eric.auger@linaro.org> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1253688 |
Show key headers only | View raw
On Thursday 22 October 2015 11:41:57 Eric Auger wrote:
> In preparation for subsequent changes in reset function lookup,
> lets introduce a dynamic list of reset combos (compat string,
> reset module, reset function). The list can be populated/voided with
> two new functions, vfio_platform_register/unregister_reset. Those are
> not yet used in this patch.
>
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
Looks correct to me now, just a little style comments.
> drivers/vfio/platform/vfio_platform_common.c | 77 +++++++++++++++++++++++++++
> drivers/vfio/platform/vfio_platform_private.h | 7 +++
> 2 files changed, 84 insertions(+)
>
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index e43efb5..52a4c7b 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -23,6 +23,15 @@
>
> #include "vfio_platform_private.h"
>
> +struct vfio_platform_reset_node {
> + struct list_head link;
> + char *compat;
> + struct module *owner;
> + vfio_platform_reset_fn_t reset;
> +};
> +
> +static LIST_HEAD(reset_list);
> +static DEFINE_MUTEX(reset_lock);
> static DEFINE_MUTEX(driver_lock);
I wonder if having a single mutex here would be enough. If you don't expect
drivers to register/unregister a lot, you could just use driver_lock here
as well.
> static const struct vfio_platform_reset_combo reset_lookup_table[] = {
> @@ -573,3 +582,71 @@ struct vfio_platform_device *vfio_platform_remove_common(struct device *dev)
> return vdev;
> }
> EXPORT_SYMBOL_GPL(vfio_platform_remove_common);
> +
> +int vfio_platform_register_reset(struct module *reset_owner,
> + const char *compat,
> + vfio_platform_reset_fn_t reset)
> +{
> + struct vfio_platform_reset_node *node, *iter;
> + bool found = false;
> +
> + mutex_lock(&reset_lock);
> + list_for_each_entry(iter, &reset_list, link) {
> + if (!strcmp(iter->compat, compat)) {
> + found = true;
> + break;
> + }
> + }
> + if (found) {
> + mutex_unlock(&reset_lock);
> + return -EINVAL;
> + }
This seems to be an unnecesssary safeguard. I would not bother
with the search, or otherwise do a WARN_ON here.
> + node = kmalloc(sizeof(*node), GFP_KERNEL);
> + if (!node) {
> + mutex_unlock(&reset_lock);
> + return -ENOMEM;
> + }
> +
> + node->compat = kstrdup(compat, GFP_KERNEL);
> + if (!node->compat) {
> + kfree(node);
> + mutex_unlock(&reset_lock);
> + return -ENOMEM;
> + }
If you hold a lock, it's better to use a goto for handling errors
and put the unlock and kfree there. I think it can be avoided
entirely here though:
It should be safe to define the interface as keeping a reference
on the string and not do a kstrdup here. I would expect users to
pass a string literal.
We could even go as far as defining the entire interface as a shim,
like
#define vfio_platform_register_reset(__compat, __reset) \
static struct vfio_platform_reset_node __reset ## _node = { \
.owner = THIS_MODULE, \
.compat = __compat, \
.reset = __reset, \
}; \
__vfio_platform_register_reset(&__reset ## node);
to make the function really simple.
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 0/6] VFIO platform reset module rework Eric Auger <eric.auger@linaro.org> - 2015-10-22 11:50 +0200
[PATCH v2 1/6] vfio: platform: add capability to register a reset function Eric Auger <eric.auger@linaro.org> - 2015-10-22 11:50 +0200
Re: [PATCH v2 1/6] vfio: platform: add capability to register a reset function Arnd Bergmann <arnd@arndb.de> - 2015-10-22 12:10 +0200
[PATCH v2 5/6] vfio: platform: use list of registered reset function Eric Auger <eric.auger@linaro.org> - 2015-10-22 11:50 +0200
Re: [PATCH v2 5/6] vfio: platform: use list of registered reset function Arnd Bergmann <arnd@arndb.de> - 2015-10-22 12:20 +0200
Re: [PATCH v2 5/6] vfio: platform: use list of registered reset function Eric Auger <eric.auger@linaro.org> - 2015-10-22 13:50 +0200
csiph-web