Skip to content

Commit 6bb49e5

Browse files
committed
WorkStruct: Typedef the work function prototype
Define a type for the work function prototype. It's not only kept in the work_struct struct, it's also passed as an argument to several functions. This makes it easier to change it. Signed-Off-By: David Howells <dhowells@redhat.com>
1 parent 52bad64 commit 6bb49e5

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎drivers/block/floppy.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ static DECLARE_WORK(floppy_work, NULL, NULL);
996996

997997
static void schedule_bh(void (*handler) (void))
998998
{
999-
PREPARE_WORK(&floppy_work, (void (*)(void *))handler, NULL);
999+
PREPARE_WORK(&floppy_work, (work_func_t)handler, NULL);
10001000
schedule_work(&floppy_work);
10011001
}
10021002

@@ -1008,7 +1008,7 @@ static void cancel_activity(void)
10081008

10091009
spin_lock_irqsave(&floppy_lock, flags);
10101010
do_floppy = NULL;
1011-
PREPARE_WORK(&floppy_work, (void *)empty, NULL);
1011+
PREPARE_WORK(&floppy_work, (work_func_t)empty, NULL);
10121012
del_timer(&fd_timer);
10131013
spin_unlock_irqrestore(&floppy_lock, flags);
10141014
}

‎include/linux/workqueue.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
struct workqueue_struct;
1313

14+
typedef void (*work_func_t)(void *data);
15+
1416
struct work_struct {
1517
unsigned long pending;
1618
struct list_head entry;
17-
void (*func)(void *);
19+
work_func_t func;
1820
void *data;
1921
void *wq_data;
2022
};
@@ -91,7 +93,7 @@ extern int FASTCALL(schedule_work(struct work_struct *work));
9193
extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
9294

9395
extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
94-
extern int schedule_on_each_cpu(void (*func)(void *info), void *info);
96+
extern int schedule_on_each_cpu(work_func_t func, void *info);
9597
extern void flush_scheduled_work(void);
9698
extern int current_is_keventd(void);
9799
extern int keventd_up(void);
@@ -100,8 +102,7 @@ extern void init_workqueues(void);
100102
void cancel_rearming_delayed_work(struct delayed_work *work);
101103
void cancel_rearming_delayed_workqueue(struct workqueue_struct *,
102104
struct delayed_work *);
103-
int execute_in_process_context(void (*fn)(void *), void *,
104-
struct execute_work *);
105+
int execute_in_process_context(work_func_t fn, void *, struct execute_work *);
105106

106107
/*
107108
* Kill off a pending schedule_delayed_work(). Note that the work callback

‎kernel/workqueue.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq)
217217
while (!list_empty(&cwq->worklist)) {
218218
struct work_struct *work = list_entry(cwq->worklist.next,
219219
struct work_struct, entry);
220-
void (*f) (void *) = work->func;
220+
work_func_t f = work->func;
221221
void *data = work->data;
222222

223223
list_del_init(cwq->worklist.next);
@@ -513,7 +513,7 @@ EXPORT_SYMBOL(schedule_delayed_work_on);
513513
*
514514
* schedule_on_each_cpu() is very slow.
515515
*/
516-
int schedule_on_each_cpu(void (*func)(void *info), void *info)
516+
int schedule_on_each_cpu(work_func_t func, void *info)
517517
{
518518
int cpu;
519519
struct work_struct *works;
@@ -578,7 +578,7 @@ EXPORT_SYMBOL(cancel_rearming_delayed_work);
578578
* Returns: 0 - function was executed
579579
* 1 - function was scheduled for execution
580580
*/
581-
int execute_in_process_context(void (*fn)(void *data), void *data,
581+
int execute_in_process_context(work_func_t fn, void *data,
582582
struct execute_work *ew)
583583
{
584584
if (!in_interrupt()) {

0 commit comments

Comments
 (0)