Return-Path: Received: from esa4.hgst.iphmx.com ([216.71.154.42]:31817 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765538AbdEWXtJ (ORCPT ); Tue, 23 May 2017 19:49:09 -0400 From: Bart Van Assche To: Nicholas Bellinger CC: , Bart Van Assche , Joel Becker , "Christoph Hellwig" , Subject: [PATCH 09/33] configfs: Introduce config_item_get_unless_zero() Date: Tue, 23 May 2017 16:48:30 -0700 Message-ID: <20170523234854.21452-10-bart.vanassche@sandisk.com> In-Reply-To: <20170523234854.21452-1-bart.vanassche@sandisk.com> References: <20170523234854.21452-1-bart.vanassche@sandisk.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This new function is needed to fix a deadlock in the SCSI target XCOPY implementation. Signed-off-by: Bart Van Assche Cc: Joel Becker Cc: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org --- fs/configfs/item.c | 6 ++++++ include/linux/configfs.h | 1 + 2 files changed, 7 insertions(+) diff --git a/fs/configfs/item.c b/fs/configfs/item.c index 8b2a994042dd..e3501b9bbb60 100644 --- a/fs/configfs/item.c +++ b/fs/configfs/item.c @@ -138,6 +138,12 @@ struct config_item *config_item_get(struct config_item *item) } EXPORT_SYMBOL(config_item_get); +struct config_item *config_item_get_unless_zero(struct config_item *item) +{ + return item && kref_get_unless_zero(&item->ci_kref) ? item : NULL; +} +EXPORT_SYMBOL(config_item_get_unless_zero); + static void config_item_cleanup(struct config_item *item) { struct config_item_type *t = item->ci_type; diff --git a/include/linux/configfs.h b/include/linux/configfs.h index 2319b8c108e8..406e16dabc28 100644 --- a/include/linux/configfs.h +++ b/include/linux/configfs.h @@ -75,6 +75,7 @@ extern void config_item_init_type_name(struct config_item *item, struct config_item_type *type); extern struct config_item * config_item_get(struct config_item *); +extern struct config_item * config_item_get_unless_zero(struct config_item *); extern void config_item_put(struct config_item *); struct config_item_type { -- 2.12.2