From b4118ea0f140cae49a94963b566dd17bdad8d9ee Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 14 May 2017 03:06:54 +0000 Subject: [PATCH] scst/include/backport.h: Add a kref_read() backport This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7178 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- fcst/ft_sess.c | 4 ---- iscsi-scst/kernel/isert-scst/iser_rdma.c | 4 ---- iscsi-scst/kernel/isert-scst/isert_login.c | 4 ---- scst/include/backport.h | 5 +++++ scst/src/scst_sysfs.c | 8 +------- 5 files changed, 6 insertions(+), 19 deletions(-) diff --git a/fcst/ft_sess.c b/fcst/ft_sess.c index c482c74c0..a11507c66 100644 --- a/fcst/ft_sess.c +++ b/fcst/ft_sess.c @@ -482,11 +482,7 @@ static void ft_sess_free(struct kref *kref) static void ft_sess_put(struct ft_sess *sess) { BUG_ON(!sess); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) BUG_ON(kref_read(&sess->kref) <= 0); -#else - BUG_ON(atomic_read(&sess->kref.refcount) <= 0); -#endif kref_put(&sess->kref, ft_sess_free); } diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index bfc03f0d9..192494545 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -1402,11 +1402,7 @@ static void isert_kref_free(struct kref *kref) void isert_conn_free(struct isert_connection *isert_conn) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) sBUG_ON(kref_read(&isert_conn->kref) == 0); -#else - sBUG_ON(atomic_read(&isert_conn->kref.refcount) == 0); -#endif kref_put(&isert_conn->kref, isert_kref_free); } diff --git a/iscsi-scst/kernel/isert-scst/isert_login.c b/iscsi-scst/kernel/isert-scst/isert_login.c index a6ffea6af..6c9e2eac4 100644 --- a/iscsi-scst/kernel/isert-scst/isert_login.c +++ b/iscsi-scst/kernel/isert-scst/isert_login.c @@ -113,11 +113,7 @@ static void isert_kref_release_dev(struct kref *kref) static void isert_dev_release(struct isert_conn_dev *dev) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) sBUG_ON(kref_read(&dev->kref) == 0); -#else - sBUG_ON(atomic_read(&dev->kref.refcount) == 0); -#endif mutex_lock(&isert_listen_dev.conn_lock); kref_put(&dev->kref, isert_kref_release_dev); mutex_unlock(&isert_listen_dev.conn_lock); diff --git a/scst/include/backport.h b/scst/include/backport.h index 29c441981..de3baa95f 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -361,6 +361,11 @@ static inline int __must_check kref_get_unless_zero(struct kref *kref) } #endif +/* See also commit 2c935bc57221 */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) +#define kref_read(kref) (atomic_read(&(kref)->refcount)) +#endif + /* */ /* See also commit 207205a2ba26 */ diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index a2a478709..9f3665ac1 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -1203,13 +1203,7 @@ void scst_kobject_put_and_wait(struct kobject *kobj, const char *category, goto out_free; PRINT_INFO("Waiting for release of sysfs entry for %s %s (%d refs)", - category, name ? : "(?)", -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - kref_read(&kobj->kref) -#else - atomic_read(&kobj->kref.refcount) -#endif - ); + category, name ? : "(?)", kref_read(&kobj->kref)); wait_for_completion(c); PRINT_INFO("Finished waiting for release of %s %s sysfs entry", category, name ? : "(?)");