Commit 2c5653b7 authored by Benjamin Romer's avatar Benjamin Romer Committed by Greg Kroah-Hartman

staging: unisys: remove typedef for PERIODIC_WORK

In periodic_work.h, remove the typedef PERIODIC_WORK and replace it with
struct periodic_work, and update functions used to manipulate the
structure to use the new name. The functions used to manipulate the
PERIODIC_WORK type are updated to use the fixed name, corrected for
clarity, and changed to not use periodic_work as the parameter's name.
Signed-off-by: default avatarBenjamin Romer <benjamin.romer@unisys.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 239436eb
...@@ -23,16 +23,16 @@ ...@@ -23,16 +23,16 @@
/* PERIODIC_WORK an opaque structure to users. /* PERIODIC_WORK an opaque structure to users.
* Fields are declared only in the implementation .c files. * Fields are declared only in the implementation .c files.
*/ */
typedef struct PERIODIC_WORK_Tag PERIODIC_WORK; struct periodic_work;
PERIODIC_WORK *visor_periodic_work_create(ulong jiffy_interval, struct periodic_work *visor_periodic_work_create(ulong jiffy_interval,
struct workqueue_struct *workqueue, struct workqueue_struct *workqueue,
void (*workfunc)(void *), void (*workfunc)(void *),
void *workfuncarg, void *workfuncarg,
const char *devnam); const char *devnam);
void visor_periodic_work_destroy(PERIODIC_WORK *periodic_work); void visor_periodic_work_destroy(struct periodic_work *pw);
BOOL visor_periodic_work_nextperiod(PERIODIC_WORK *periodic_work); BOOL visor_periodic_work_nextperiod(struct periodic_work *pw);
BOOL visor_periodic_work_start(PERIODIC_WORK *periodic_work); BOOL visor_periodic_work_start(struct periodic_work *pw);
BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work); BOOL visor_periodic_work_stop(struct periodic_work *pw);
#endif #endif
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
struct PERIODIC_WORK_Tag { struct periodic_work {
rwlock_t lock; rwlock_t lock;
struct delayed_work work; struct delayed_work work;
void (*workfunc)(void *); void (*workfunc)(void *);
...@@ -43,42 +43,41 @@ struct PERIODIC_WORK_Tag { ...@@ -43,42 +43,41 @@ struct PERIODIC_WORK_Tag {
static void periodic_work_func(struct work_struct *work) static void periodic_work_func(struct work_struct *work)
{ {
PERIODIC_WORK *periodic_work = struct periodic_work *pw;
container_of(work, struct PERIODIC_WORK_Tag, work.work);
(*periodic_work->workfunc)(periodic_work->workfuncarg); pw = container_of(work, struct periodic_work, work.work);
(*pw->workfunc)(pw->workfuncarg);
} }
PERIODIC_WORK *visor_periodic_work_create(ulong jiffy_interval, struct periodic_work *visor_periodic_work_create(ulong jiffy_interval,
struct workqueue_struct *workqueue, struct workqueue_struct *workqueue,
void (*workfunc)(void *), void (*workfunc)(void *),
void *workfuncarg, void *workfuncarg,
const char *devnam) const char *devnam)
{ {
PERIODIC_WORK *periodic_work = kzalloc(sizeof(PERIODIC_WORK), struct periodic_work *pw;
GFP_KERNEL | __GFP_NORETRY);
if (periodic_work == NULL) { pw = kzalloc(sizeof(*pw), GFP_KERNEL | __GFP_NORETRY);
ERRDRV("periodic_work allocation failed "); if (!pw)
return NULL; return NULL;
}
rwlock_init(&periodic_work->lock); rwlock_init(&pw->lock);
periodic_work->jiffy_interval = jiffy_interval; pw->jiffy_interval = jiffy_interval;
periodic_work->workqueue = workqueue; pw->workqueue = workqueue;
periodic_work->workfunc = workfunc; pw->workfunc = workfunc;
periodic_work->workfuncarg = workfuncarg; pw->workfuncarg = workfuncarg;
periodic_work->devnam = devnam; pw->devnam = devnam;
return periodic_work; return pw;
} }
EXPORT_SYMBOL_GPL(visor_periodic_work_create); EXPORT_SYMBOL_GPL(visor_periodic_work_create);
void visor_periodic_work_destroy(PERIODIC_WORK *periodic_work) void visor_periodic_work_destroy(struct periodic_work *pw)
{ {
if (periodic_work == NULL) kfree(pw);
return;
kfree(periodic_work);
} }
EXPORT_SYMBOL_GPL(visor_periodic_work_destroy); EXPORT_SYMBOL_GPL(visor_periodic_work_destroy);
...@@ -89,27 +88,26 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_destroy); ...@@ -89,27 +88,26 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_destroy);
* If this function returns FALSE, there was a failure and the * If this function returns FALSE, there was a failure and the
* periodic work is no longer scheduled * periodic work is no longer scheduled
*/ */
BOOL visor_periodic_work_nextperiod(PERIODIC_WORK *periodic_work) BOOL visor_periodic_work_nextperiod(struct periodic_work *pw)
{ {
BOOL rc = FALSE; BOOL rc = FALSE;
write_lock(&periodic_work->lock); write_lock(&pw->lock);
if (periodic_work->want_to_stop) { if (pw->want_to_stop) {
periodic_work->is_scheduled = FALSE; pw->is_scheduled = FALSE;
periodic_work->want_to_stop = FALSE; pw->want_to_stop = FALSE;
rc = TRUE; /* yes, TRUE; see visor_periodic_work_stop() */ rc = TRUE; /* yes, TRUE; see visor_periodic_work_stop() */
goto Away; goto unlock;
} else if (queue_delayed_work(periodic_work->workqueue, } else if (queue_delayed_work(pw->workqueue, &pw->work,
&periodic_work->work, pw->jiffy_interval) < 0) {
periodic_work->jiffy_interval) < 0) { ERRDEV(pw->devnam, "queue_delayed_work failed!");
ERRDEV(periodic_work->devnam, "queue_delayed_work failed!"); pw->is_scheduled = FALSE;
periodic_work->is_scheduled = FALSE;
rc = FALSE; rc = FALSE;
goto Away; goto unlock;
} }
rc = TRUE; rc = TRUE;
Away: unlock:
write_unlock(&periodic_work->lock); write_unlock(&pw->lock);
return rc; return rc;
} }
EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod); EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod);
...@@ -120,34 +118,32 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod); ...@@ -120,34 +118,32 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod);
* If this function returns FALSE, then no work was started * If this function returns FALSE, then no work was started
* (either because it was already started, or because of a failure). * (either because it was already started, or because of a failure).
*/ */
BOOL visor_periodic_work_start(PERIODIC_WORK *periodic_work) BOOL visor_periodic_work_start(struct periodic_work *pw)
{ {
BOOL rc = FALSE; BOOL rc = FALSE;
write_lock(&periodic_work->lock); write_lock(&pw->lock);
if (periodic_work->is_scheduled) { if (pw->is_scheduled) {
rc = FALSE; rc = FALSE;
goto Away; goto unlock;
} }
if (periodic_work->want_to_stop) { if (pw->want_to_stop) {
ERRDEV(periodic_work->devnam, ERRDEV(pw->devnam,
"dev_start_periodic_work failed!"); "dev_start_periodic_work failed!");
rc = FALSE; rc = FALSE;
goto Away; goto unlock;
} }
INIT_DELAYED_WORK(&periodic_work->work, &periodic_work_func); INIT_DELAYED_WORK(&pw->work, &periodic_work_func);
if (queue_delayed_work(periodic_work->workqueue, if (queue_delayed_work(pw->workqueue, &pw->work,
&periodic_work->work, pw->jiffy_interval) < 0) {
periodic_work->jiffy_interval) < 0) { ERRDEV(pw->devnam, "%s queue_delayed_work failed!", __func__);
ERRDEV(periodic_work->devnam,
"%s queue_delayed_work failed!", __func__);
rc = FALSE; rc = FALSE;
goto Away; goto unlock;
} }
periodic_work->is_scheduled = TRUE; pw->is_scheduled = TRUE;
rc = TRUE; rc = TRUE;
Away: unlock:
write_unlock(&periodic_work->lock); write_unlock(&pw->lock);
return rc; return rc;
} }
...@@ -190,21 +186,20 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_start); ...@@ -190,21 +186,20 @@ EXPORT_SYMBOL_GPL(visor_periodic_work_start);
* this deadlock, you will get hung up in an infinite loop saying * this deadlock, you will get hung up in an infinite loop saying
* "waiting for delayed work...". * "waiting for delayed work...".
*/ */
BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work) BOOL visor_periodic_work_stop(struct periodic_work *pw)
{ {
BOOL stopped_something = FALSE; BOOL stopped_something = FALSE;
write_lock(&periodic_work->lock); write_lock(&pw->lock);
stopped_something = periodic_work->is_scheduled && stopped_something = pw->is_scheduled && (!pw->want_to_stop);
(!periodic_work->want_to_stop); while (pw->is_scheduled) {
while (periodic_work->is_scheduled) { pw->want_to_stop = TRUE;
periodic_work->want_to_stop = TRUE; if (cancel_delayed_work(&pw->work)) {
if (cancel_delayed_work(&periodic_work->work)) {
/* We get here if the delayed work was pending as /* We get here if the delayed work was pending as
* delayed work, but was NOT run. * delayed work, but was NOT run.
*/ */
ASSERT(periodic_work->is_scheduled); ASSERT(pw->is_scheduled);
periodic_work->is_scheduled = FALSE; pw->is_scheduled = FALSE;
} else { } else {
/* If we get here, either the delayed work: /* If we get here, either the delayed work:
* - was run, OR, * - was run, OR,
...@@ -216,9 +211,9 @@ BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work) ...@@ -216,9 +211,9 @@ BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work)
* explains the loop... * explains the loop...
*/ */
} }
if (periodic_work->is_scheduled) { if (pw->is_scheduled) {
write_unlock(&periodic_work->lock); write_unlock(&pw->lock);
WARNDEV(periodic_work->devnam, WARNDEV(pw->devnam,
"waiting for delayed work..."); "waiting for delayed work...");
/* We rely on the delayed work function running here, /* We rely on the delayed work function running here,
* and eventually calling * and eventually calling
...@@ -227,11 +222,11 @@ BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work) ...@@ -227,11 +222,11 @@ BOOL visor_periodic_work_stop(PERIODIC_WORK *periodic_work)
* subsequently clear is_scheduled. * subsequently clear is_scheduled.
*/ */
SLEEPJIFFIES(10); SLEEPJIFFIES(10);
write_lock(&periodic_work->lock); write_lock(&pw->lock);
} else } else
periodic_work->want_to_stop = FALSE; pw->want_to_stop = FALSE;
} }
write_unlock(&periodic_work->lock); write_unlock(&pw->lock);
return stopped_something; return stopped_something;
} }
EXPORT_SYMBOL_GPL(visor_periodic_work_stop); EXPORT_SYMBOL_GPL(visor_periodic_work_stop);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment