Skip to content

Commit 4516d7a

Browse files
committed
remove provider reference counter
1 parent 4644789 commit 4516d7a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

include/dpusm/provider.h

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ typedef struct dpusm_provider_handle {
1313
struct module *module;
1414
dpusm_pc_t capabilities; /* constant set of capabilities */
1515
const dpusm_pf_t *funcs; /* reference to a struct */
16-
atomic_t refs; /* how many users are holding this provider */
1716
struct list_head list;
1817
struct dpusm_provider_handle *self;
1918
} dpusm_ph_t;

src/provider.c

+11-10
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ dpusmph_init(struct module *module, const dpusm_pf_t *funcs)
227227
dpusmph->module = module;
228228
dpusmph->funcs = funcs;
229229
dpusmph->self = dpusmph;
230-
atomic_set(&dpusmph->refs, 0);
231230
}
232231

233232
return dpusmph;
@@ -301,8 +300,10 @@ dpusm_provider_unregister_handle(dpusm_t *dpusm, dpusm_ph_t **provider) {
301300
}
302301

303302
int rc = 0;
304-
const int refs = atomic_read(&(*provider)->refs);
305-
if (refs) {
303+
304+
/* have to add 1 because module_exit subtracts 1 before entering provider exit */
305+
const int refs = module_refcount((*provider)->module) + 1;
306+
if (refs > 0) {
306307
printk("%s: Unregistering provider \"%s\" with %d references remaining.\n",
307308
__func__, module_name((*provider)->module), refs);
308309
rc = -EBUSY;
@@ -349,17 +350,18 @@ dpusm_provider_get(dpusm_t *dpusm, const char *name) {
349350
read_lock(&dpusm->lock);
350351
dpusm_ph_t **provider = find_provider(dpusm, name);
351352
if (provider) {
353+
struct module *module = (*provider)->module;
354+
352355
/* make sure provider can't be unloaded before user */
353-
if (!try_module_get((*provider)->module)) {
356+
if (!try_module_get(module)) {
354357
printk("Error: Could not increment reference count of %s\n", name);
355358
return NULL;
356359
}
357360

358-
atomic_inc(&(*provider)->refs);
359361
atomic_inc(&dpusm->active);
360362

361363
printk("%s: User has been given a handle to \"%s\" (%p) (now %d users).\n",
362-
__func__, name, *provider, atomic_read(&(*provider)->refs));
364+
__func__, name, *provider, module_refcount(module));
363365

364366
if ((*provider)->funcs->at_connect) {
365367
(*provider)->funcs->at_connect();
@@ -384,14 +386,13 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
384386

385387
struct module *module = (*provider)->module;
386388

387-
if (!atomic_read(&(*provider)->refs)) {
389+
if (!module_refcount(module)) {
388390
printk("%s Error: Cannot decrement provider \"%s\" user count already at 0.\n",
389391
__func__, module_name(module));
390392
return DPUSM_ERROR;
391393
}
392394

393395
module_put(module);
394-
atomic_dec(&(*provider)->refs);
395396
atomic_dec(&dpusm->active);
396397

397398
if ((*provider)->funcs) { /* provider might have been invalidated */
@@ -401,7 +402,7 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
401402
}
402403

403404
printk("%s: User has returned a handle to \"%s\" (%p) (now %d users).\n",
404-
__func__, module_name(module), *provider, atomic_read(&(*provider)->refs));
405+
__func__, module_name(module), *provider, module_refcount(module));
405406
return DPUSM_OK;
406407
}
407408

@@ -422,7 +423,7 @@ void dpusm_provider_invalidate(dpusm_t *dpusm, const char *name) {
422423
(*provider)->funcs = NULL;
423424
memset(&(*provider)->capabilities, 0, sizeof((*provider)->capabilities));
424425
printk("%s: Provider \"%s\" has been invalidated with %d users active.\n",
425-
__func__, name, atomic_read(&(*provider)->refs));
426+
__func__, name, module_refcount((*provider)->module));
426427
/* not decrementing module reference count here - provider is still registered */
427428
}
428429
else {

0 commit comments

Comments
 (0)