linux/drivers/staging/rtl8712
Kees Cook e99e88a9d2 treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.

Casting from unsigned long:

    void my_callback(unsigned long data)
    {
        struct something *ptr = (struct something *)data;
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, ptr);

and forced object casts:

    void my_callback(struct something *ptr)
    {
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);

become:

    void my_callback(struct timer_list *t)
    {
        struct something *ptr = from_timer(ptr, t, my_timer);
    ...
    }
    ...
    timer_setup(&ptr->my_timer, my_callback, 0);

Direct function assignments:

    void my_callback(unsigned long data)
    {
        struct something *ptr = (struct something *)data;
    ...
    }
    ...
    ptr->my_timer.function = my_callback;

have a temporary cast added, along with converting the args:

    void my_callback(struct timer_list *t)
    {
        struct something *ptr = from_timer(ptr, t, my_timer);
    ...
    }
    ...
    ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;

And finally, callbacks without a data assignment:

    void my_callback(unsigned long data)
    {
    ...
    }
    ...
    setup_timer(&ptr->my_timer, my_callback, 0);

have their argument renamed to verify they're unused during conversion:

    void my_callback(struct timer_list *unused)
    {
    ...
    }
    ...
    timer_setup(&ptr->my_timer, my_callback, 0);

The conversion is done with the following Coccinelle script:

spatch --very-quiet --all-includes --include-headers \
	-I ./arch/x86/include -I ./arch/x86/include/generated \
	-I ./include -I ./arch/x86/include/uapi \
	-I ./arch/x86/include/generated/uapi -I ./include/uapi \
	-I ./include/generated/uapi --include ./include/linux/kconfig.h \
	--dir . \
	--cocci-file ~/src/data/timer_setup.cocci

@fix_address_of@
expression e;
@@

 setup_timer(
-&(e)
+&e
 , ...)

// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@

(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)

@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@

(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
 _E->_timer@_stl.function = _callback;
|
 _E->_timer@_stl.function = &_callback;
|
 _E->_timer@_stl.function = (_cast_func)_callback;
|
 _E->_timer@_stl.function = (_cast_func)&_callback;
|
 _E._timer@_stl.function = _callback;
|
 _E._timer@_stl.function = &_callback;
|
 _E._timer@_stl.function = (_cast_func)_callback;
|
 _E._timer@_stl.function = (_cast_func)&_callback;
)

// callback(unsigned long arg)
@change_callback_handle_cast
 depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@

 void _callback(
-_origtype _origarg
+struct timer_list *t
 )
 {
(
	... when != _origarg
	_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
	... when != _origarg
|
	... when != _origarg
	_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
	... when != _origarg
|
	... when != _origarg
	_handletype *_handle;
	... when != _handle
	_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
	... when != _origarg
|
	... when != _origarg
	_handletype *_handle;
	... when != _handle
	_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
	... when != _origarg
)
 }

// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
 depends on change_timer_function_usage &&
                     !change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@

 void _callback(
-_origtype _origarg
+struct timer_list *t
 )
 {
+	_handletype *_origarg = from_timer(_origarg, t, _timer);
+
	... when != _origarg
-	(_handletype *)_origarg
+	_origarg
	... when != _origarg
 }

// Avoid already converted callbacks.
@match_callback_converted
 depends on change_timer_function_usage &&
            !change_callback_handle_cast &&
	    !change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@

 void _callback(struct timer_list *t)
 { ... }

// callback(struct something *handle)
@change_callback_handle_arg
 depends on change_timer_function_usage &&
	    !match_callback_converted &&
            !change_callback_handle_cast &&
            !change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@

 void _callback(
-_handletype *_handle
+struct timer_list *t
 )
 {
+	_handletype *_handle = from_timer(_handle, t, _timer);
	...
 }

// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
 depends on change_timer_function_usage &&
	    change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@

 void _callback(struct timer_list *t)
 {
-	_handletype *_handle = from_timer(_handle, t, _timer);
 }

// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
 depends on change_timer_function_usage &&
            !change_callback_handle_cast &&
            !change_callback_handle_cast_no_arg &&
	    !change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@

(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)

// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
 depends on change_timer_function_usage &&
            (change_callback_handle_cast ||
             change_callback_handle_cast_no_arg ||
             change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@

(
 _E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
 ;
|
 _E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
 ;
)

// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
 depends on change_timer_function_usage &&
            (change_callback_handle_cast ||
             change_callback_handle_cast_no_arg ||
             change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@

 _callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
 )

// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@

(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)

@change_callback_unused_data
 depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@

 void _callback(
-_origtype _origarg
+struct timer_list *unused
 )
 {
	... when != _origarg
 }

Signed-off-by: Kees Cook <keescook@chromium.org>
2017-11-21 15:57:07 -08:00
..
Kconfig
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
TODO staging: refresh TODO for rtl8712 2016-03-22 22:22:13 -04:00
basic_types.h staging: rtl8712: Fixed FSF address warning in basic_types.h 2016-03-28 07:30:36 -07:00
drv_types.h staging: rtl8712: Fixed FSF address warning in drv_types.h 2016-03-28 07:30:36 -07:00
ethernet.h staging: rtl8712: Fixed FSF address warning in ethernet.h 2016-03-28 07:30:36 -07:00
hal_init.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
ieee80211.c Staging: rtl8712: ieee80211: fixed camelcase coding style issue 2017-05-15 07:43:54 +02:00
ieee80211.h staging: rtl8712u: Fix endian settings for structs describing network packets 2017-02-12 13:26:55 +01:00
mlme_linux.c staging: rtl8712: Convert timers to use timer_setup() 2017-10-18 16:18:31 +02:00
mlme_osdep.h
mp_custom_oid.h
os_intfs.c staging: rtl8712: Convert timers to use timer_setup() 2017-10-18 16:18:31 +02:00
osdep_intf.h rtl8712: intf_priv: Replace semaphore lock with completion 2016-08-21 18:25:47 +02:00
osdep_service.h sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
recv_linux.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
recv_osdep.h
rtl871x_cmd.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
rtl871x_cmd.h Staging: rtl8712: rtl871x_cmd.h - block comments 2017-03-06 09:17:03 +01:00
rtl871x_debug.h
rtl871x_eeprom.c
rtl871x_eeprom.h
rtl871x_event.h Staging: rtl8712: rtl871x_event.h - style fix 2017-03-06 09:17:03 +01:00
rtl871x_ht.h staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl871x_io.c Staging: rtl8712: Clean up tests if NULL returned on failure 2016-03-11 22:09:09 -08:00
rtl871x_io.h Staging: rtl8712: rtl871x_io.h - style fix 2017-03-06 09:17:03 +01:00
rtl871x_ioctl.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rtl871x_ioctl_linux.c staging: rtl8712: Invert comparison to reduce indentation 2017-03-23 14:24:45 +01:00
rtl871x_ioctl_rtl.c staging: rtl8712: checkpatch: Avoid multiple line dereferences 2017-03-21 08:44:55 +01:00
rtl871x_ioctl_rtl.h
rtl871x_ioctl_set.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
rtl871x_ioctl_set.h
rtl871x_led.h staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl871x_mlme.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
rtl871x_mlme.h Staging: rtl8712: rtl871x_mlme.h - style fix 2017-03-06 09:17:03 +01:00
rtl871x_mp.c staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl871x_mp.h staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl871x_mp_ioctl.c Staging: rtl8712: fix spelling errors 2017-01-25 11:33:21 +01:00
rtl871x_mp_ioctl.h Staging: rtl8712: rtl871x_mp_ioctl.h - style fix 2017-03-09 17:37:21 +01:00
rtl871x_mp_phy_regdef.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rtl871x_pwrctrl.c staging: rtl8712: Convert timers to use timer_setup() 2017-10-18 16:18:31 +02:00
rtl871x_pwrctrl.h Staging: rtl8712: rtl871x_pwrctrl.h - style fix 2017-03-06 09:17:03 +01:00
rtl871x_recv.c staging: r8712u: Fix Sparse endian warning in rtl871x_recv.c 2017-02-12 13:26:55 +01:00
rtl871x_recv.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rtl871x_rf.h
rtl871x_security.c staging: rtl8712: Convert timers to use timer_setup() 2017-10-18 16:18:31 +02:00
rtl871x_security.h staging: rtl8712: Convert timers to use timer_setup() 2017-10-18 16:18:31 +02:00
rtl871x_sta_mgt.c staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl871x_wlan_sme.h
rtl871x_xmit.c staging: rtl8712: fixed multiple line derefence issue 2017-04-08 17:05:59 +02:00
rtl871x_xmit.h Staging: rtl8712: remove unused functions 2016-10-16 10:24:51 +02:00
rtl8712_bitdef.h
rtl8712_cmd.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
rtl8712_cmd.h
rtl8712_cmdctrl_bitdef.h
rtl8712_cmdctrl_regdef.h
rtl8712_debugctrl_bitdef.h
rtl8712_debugctrl_regdef.h
rtl8712_edcasetting_bitdef.h
rtl8712_edcasetting_regdef.h
rtl8712_efuse.c staging: rtl8712: fix "Alignment match open parenthesis" 2017-07-16 08:40:58 +02:00
rtl8712_efuse.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rtl8712_event.h Staging: rtl8712: Remove multiple blank lines 2017-09-17 16:35:26 +02:00
rtl8712_fifoctrl_bitdef.h
rtl8712_fifoctrl_regdef.h
rtl8712_gp_bitdef.h
rtl8712_gp_regdef.h
rtl8712_hal.h Staging:rtl8712: Fixed coding style issue 2016-12-06 10:18:07 +01:00
rtl8712_interrupt_bitdef.h
rtl8712_io.c staging: rtl8712: Cleanup _io_ops wrappers 2016-02-07 19:50:09 -08:00
rtl8712_led.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
rtl8712_macsetting_bitdef.h
rtl8712_macsetting_regdef.h
rtl8712_powersave_bitdef.h
rtl8712_powersave_regdef.h
rtl8712_ratectrl_bitdef.h
rtl8712_ratectrl_regdef.h
rtl8712_recv.c staging: rtl8712: Fix indent coding style issue 2017-09-26 09:41:54 +02:00
rtl8712_recv.h staging: rtl8712: changed struct members to __le32 2017-01-03 16:49:19 +01:00
rtl8712_regdef.h
rtl8712_security_bitdef.h
rtl8712_spec.h staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl8712_syscfg_bitdef.h staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
rtl8712_syscfg_regdef.h
rtl8712_timectrl_bitdef.h
rtl8712_timectrl_regdef.h
rtl8712_wmac_bitdef.h
rtl8712_wmac_regdef.h
rtl8712_xmit.c staging: rtl8712: Remove explicit NULL comparison 2017-07-16 08:40:58 +02:00
rtl8712_xmit.h staging: rtl8712: changed variables to __le32 2017-01-03 16:51:16 +01:00
sta_info.h
usb_halinit.c staging: rtl8712: checkpatch cleanup: block comments using a trailing */ 2016-09-12 11:43:52 +02:00
usb_intf.c staging: rtl8712: Fix unbalanced braces around else statement 2017-09-17 16:35:27 +02:00
usb_ops.c staging: rtl8712: changed u32 to __le32 2017-01-03 16:51:16 +01:00
usb_ops.h
usb_ops_linux.c staging: rtl8712: changed uint to __le32 2017-01-03 16:51:16 +01:00
usb_osintf.h
wifi.h Staging: rtl8712 : wifi.h: Fixed Macro argument reuse 2017-06-25 16:31:22 +02:00
wlan_bssdef.h Staging: rtl8712: wlan_bssdef.h - style fix 2017-03-06 09:17:03 +01:00
xmit_linux.c staging: r8712u: Handle some false positives from kmemleak 2016-08-21 18:28:49 +02:00
xmit_osdep.h