From patchwork Fri May 31 02:35:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenbaodong X-Patchwork-Id: 10969519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B09686C5 for ; Fri, 31 May 2019 02:38:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C6DE28C18 for ; Fri, 31 May 2019 02:38:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BD1928C5E; Fri, 31 May 2019 02:38:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BFC3328C18 for ; Fri, 31 May 2019 02:38:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hWXOX-0002My-Iq; Fri, 31 May 2019 02:35:49 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hWXOV-0002Mt-WE for xen-devel@lists.xenproject.org; Fri, 31 May 2019 02:35:48 +0000 X-Inumbo-ID: c9d7a5b6-834c-11e9-8980-bc764e045a96 Received: from mxnavi-mail.mxnavi.com (unknown [116.90.87.199]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id c9d7a5b6-834c-11e9-8980-bc764e045a96; Fri, 31 May 2019 02:35:45 +0000 (UTC) Received: from localhost.localdomain (61.161.186.150) by mxnavi-mail.mxnavi.com (116.90.87.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1591.10; Fri, 31 May 2019 10:33:31 +0800 From: Baodong Chen To: Date: Fri, 31 May 2019 10:35:28 +0800 Message-ID: <1559270128-28496-1-git-send-email-chenbaodong@mxnavi.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [61.161.186.150] X-ClientProxiedBy: mxnavi-mail.mxnavi.com (116.90.87.199) To mxnavi-mail.mxnavi.com (116.90.87.199) Subject: [Xen-devel] [PATCH] xen: notifier: refine 'notifier_head', use 'list_head' directly X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Baodong Chen Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Baodong Chen --- xen/common/notifier.c | 25 ++++++------------------- xen/include/xen/notifier.h | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/xen/common/notifier.c b/xen/common/notifier.c index 34488a8..f959a79 100644 --- a/xen/common/notifier.c +++ b/xen/common/notifier.c @@ -21,10 +21,10 @@ void __init notifier_chain_register( struct notifier_head *nh, struct notifier_block *n) { - struct list_head *chain = &nh->head.chain; + struct list_head *chain = &nh->head; struct notifier_block *nb; - while ( chain->next != &nh->head.chain ) + while ( chain->next != &nh->head ) { nb = list_entry(chain->next, struct notifier_block, chain); if ( n->priority > nb->priority ) @@ -35,19 +35,6 @@ void __init notifier_chain_register( list_add(&n->chain, chain); } -/** - * notifier_chain_unregister - Remove notifier from a raw notifier chain - * @nh: Pointer to head of the raw notifier chain - * @n: Entry to remove from notifier chain - * - * Removes a notifier from a raw notifier chain. - * All locking must be provided by the caller. - */ -void __init notifier_chain_unregister( - struct notifier_head *nh, struct notifier_block *n) -{ - list_del(&n->chain); -} /** * notifier_call_chain - Informs the registered notifiers about an event. @@ -71,16 +58,16 @@ int notifier_call_chain( { int ret = NOTIFY_DONE; struct list_head *cursor; - struct notifier_block *nb; + struct notifier_block *nb = NULL; bool_t reverse = !!(val & NOTIFY_REVERSE); - cursor = &(pcursor && *pcursor ? *pcursor : &nh->head)->chain; + cursor = (pcursor && *pcursor ? &(*pcursor)->chain : &nh->head); do { cursor = reverse ? cursor->prev : cursor->next; - nb = list_entry(cursor, struct notifier_block, chain); - if ( cursor == &nh->head.chain ) + if ( cursor == &nh->head ) break; + nb = list_entry(cursor, struct notifier_block, chain); ret = nb->notifier_call(nb, val, v); } while ( !(ret & NOTIFY_STOP_MASK) ); diff --git a/xen/include/xen/notifier.h b/xen/include/xen/notifier.h index d1ff9b1..b1961cb 100644 --- a/xen/include/xen/notifier.h +++ b/xen/include/xen/notifier.h @@ -29,18 +29,27 @@ struct notifier_block { }; struct notifier_head { - struct notifier_block head; + struct list_head head; }; -#define NOTIFIER_INIT(name) { .head.chain = LIST_HEAD_INIT(name.head.chain) } +#define NOTIFIER_HEAD(name) \ + struct notifier_head name = {.head = LIST_HEAD_INIT(name.head)} -#define NOTIFIER_HEAD(name) \ - struct notifier_head name = NOTIFIER_INIT(name) void notifier_chain_register( struct notifier_head *nh, struct notifier_block *nb); -void notifier_chain_unregister( - struct notifier_head *nh, struct notifier_block *nb); + +/** + * notifier_chain_unregister - Remove notifier from a raw notifier chain + * @n: Entry to remove from notifier chain + * + * Removes a notifier from a raw notifier chain. + * All locking must be provided by the caller. + */ +static inline void notifier_chain_unregister(struct notifier_block *n) +{ + list_del(&n->chain); +} int notifier_call_chain( struct notifier_head *nh, unsigned long val, void *v,