Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db1afffa authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman
Browse files

kref: remove kref_set



Of the three uses of kref_set in the kernel:

 One really should be kref_put as the code is letting go of a
    reference,
 Two really should be kref_init because the kref is being
    initialised.

This suggests that making kref_set available encourages bad code.
So fix the three uses and remove kref_set completely.

Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Acked-by: default avatarMimi Zohar <zohar@us.ibm.com>
Acked-by: default avatarSerge Hallyn <serue@us.ibm.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent dd336c55
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ struct kref {
	atomic_t refcount;
	atomic_t refcount;
};
};


void kref_set(struct kref *kref, int num);
void kref_init(struct kref *kref);
void kref_init(struct kref *kref);
void kref_get(struct kref *kref);
void kref_get(struct kref *kref);
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
+2 −2
Original line number Original line Diff line number Diff line
@@ -54,8 +54,8 @@ int create_user_ns(struct cred *new)
#endif
#endif
	/* tgcred will be cleared in our caller bc CLONE_THREAD won't be set */
	/* tgcred will be cleared in our caller bc CLONE_THREAD won't be set */


	/* alloc_uid() incremented the userns refcount.  Just set it to 1 */
	/* root_user holds a reference to ns, our reference can be dropped */
	kref_set(&ns->kref, 1);
	put_user_ns(ns);


	return 0;
	return 0;
}
}
+2 −13
Original line number Original line Diff line number Diff line
@@ -15,24 +15,14 @@
#include <linux/module.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/slab.h>


/**
 * kref_set - initialize object and set refcount to requested number.
 * @kref: object in question.
 * @num: initial reference counter
 */
void kref_set(struct kref *kref, int num)
{
	atomic_set(&kref->refcount, num);
	smp_mb();
}

/**
/**
 * kref_init - initialize object.
 * kref_init - initialize object.
 * @kref: object in question.
 * @kref: object in question.
 */
 */
void kref_init(struct kref *kref)
void kref_init(struct kref *kref)
{
{
	kref_set(kref, 1);
	atomic_set(&kref->refcount, 1);
	smp_mb();
}
}


/**
/**
@@ -72,7 +62,6 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
	return 0;
	return 0;
}
}


EXPORT_SYMBOL(kref_set);
EXPORT_SYMBOL(kref_init);
EXPORT_SYMBOL(kref_init);
EXPORT_SYMBOL(kref_get);
EXPORT_SYMBOL(kref_get);
EXPORT_SYMBOL(kref_put);
EXPORT_SYMBOL(kref_put);
+2 −2
Original line number Original line Diff line number Diff line
@@ -94,7 +94,7 @@ void iint_free(struct kref *kref)
		       iint->opencount);
		       iint->opencount);
		iint->opencount = 0;
		iint->opencount = 0;
	}
	}
	kref_set(&iint->refcount, 1);
	kref_init(&iint->refcount);
	kmem_cache_free(iint_cache, iint);
	kmem_cache_free(iint_cache, iint);
}
}


@@ -133,7 +133,7 @@ static void init_once(void *foo)
	iint->readcount = 0;
	iint->readcount = 0;
	iint->writecount = 0;
	iint->writecount = 0;
	iint->opencount = 0;
	iint->opencount = 0;
	kref_set(&iint->refcount, 1);
	kref_init(&iint->refcount);
}
}


static int __init ima_iintcache_init(void)
static int __init ima_iintcache_init(void)