瀏覽代碼

configfs: Introduce config_item_get_unless_zero()

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
[hch: minor style tweak]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Bart Van Assche 8 年之前
父節點
當前提交
19e72d3abb
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 8 0
      fs/configfs/item.c
  2. 2 1
      include/linux/configfs.h

+ 8 - 0
fs/configfs/item.c

@@ -138,6 +138,14 @@ struct config_item *config_item_get(struct config_item *item)
 }
 }
 EXPORT_SYMBOL(config_item_get);
 EXPORT_SYMBOL(config_item_get);
 
 
+struct config_item *config_item_get_unless_zero(struct config_item *item)
+{
+	if (item && kref_get_unless_zero(&item->ci_kref))
+		return item;
+	return NULL;
+}
+EXPORT_SYMBOL(config_item_get_unless_zero);
+
 static void config_item_cleanup(struct config_item *item)
 static void config_item_cleanup(struct config_item *item)
 {
 {
 	struct config_item_type *t = item->ci_type;
 	struct config_item_type *t = item->ci_type;

+ 2 - 1
include/linux/configfs.h

@@ -74,7 +74,8 @@ extern void config_item_init_type_name(struct config_item *item,
 				       const char *name,
 				       const char *name,
 				       struct config_item_type *type);
 				       struct config_item_type *type);
 
 
-extern struct config_item * config_item_get(struct config_item *);
+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 *);
 extern void config_item_put(struct config_item *);
 
 
 struct config_item_type {
 struct config_item_type {