From 5ad19305fc87a9928e787d888ab95b954ba80a9e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 18 Mar 2019 16:20:36 -0400 Subject: [PATCH] Fix: atomic_long_add_unless() returns a boolean Because of a documentation error in older kernels, it was assumed that atomic_long_add_unless would return the old value, but the implementation actually returns a boolean. Also add missing error code int 'ret' and compare against the right type max value. Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- lttng-abi.c | 7 +++---- lttng-events.c | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lttng-abi.c b/lttng-abi.c index 0534472a..ca943791 100644 --- a/lttng-abi.c +++ b/lttng-abi.c @@ -419,8 +419,8 @@ int lttng_abi_create_channel(struct file *session_file, transport_name = ""; break; } - if (atomic_long_add_unless(&session_file->f_count, - 1, INT_MAX) == INT_MAX) { + if (!atomic_long_add_unless(&session_file->f_count, 1, LONG_MAX)) { + ret = -EOVERFLOW; goto refcount_error; } /* @@ -1072,8 +1072,7 @@ int lttng_abi_create_event(struct file *channel_file, goto file_error; } /* The event holds a reference on the channel */ - if (atomic_long_add_unless(&channel_file->f_count, - 1, INT_MAX) == INT_MAX) { + if (!atomic_long_add_unless(&channel_file->f_count, 1, LONG_MAX)) { ret = -EOVERFLOW; goto refcount_error; } diff --git a/lttng-events.c b/lttng-events.c index 742bec4d..0d62f9fb 100644 --- a/lttng-events.c +++ b/lttng-events.c @@ -1141,8 +1141,8 @@ int lttng_session_list_tracker_pids(struct lttng_session *session) ret = PTR_ERR(tracker_pids_list_file); goto file_error; } - if (atomic_long_add_unless(&session->file->f_count, - 1, INT_MAX) == INT_MAX) { + if (!atomic_long_add_unless(&session->file->f_count, 1, LONG_MAX)) { + ret = -EOVERFLOW; goto refcount_error; } ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file); -- 2.34.1