qcacmn: Do not directly alias 'struct timer_list'

There are a number of places where the kernel's timer_list type has been
used in conjunction with qdf_timer APIs. To prevent reintroduction of
similar issues in the future, do not directly alias qdf_timer_t to
timer_list.

See also: I410b7fafad18be01141008b6220fbe34ab07601e

Change-Id: Ic4cef0d6301230197443d4d5247188f2af643674
CRs-Fixed: 2388595
This commit is contained in:
Dustin Brown
2019-01-15 13:04:42 -08:00
committed by nshrivas
parent 340c627dcf
commit bf8e81ef4c
2 changed files with 56 additions and 106 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014-2016, 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2014-2016, 2018-2019 The Linux Foundation. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for * Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the * any purpose with or without fee is hereby granted, provided that the
@@ -27,8 +27,7 @@
#include <qdf_types.h> #include <qdf_types.h>
#include <i_qdf_timer.h> #include <i_qdf_timer.h>
/* Platform timer object */ typedef struct __qdf_timer_t qdf_timer_t;
typedef __qdf_timer_t qdf_timer_t;
/** /**
* qdf_timer_init() - initialize a timer * qdf_timer_init() - initialize a timer
@@ -53,23 +52,24 @@ qdf_timer_init(qdf_handle_t hdl, qdf_timer_t *timer, qdf_timer_func_t func,
} }
/** /**
* qdf_timer_start() - start a one-shot timer * qdf_timer_start() - start a timer
* @timer: Timer object pointer * @timer: timer to start
* @msec: Expiration period in milliseconds * @msec: Expiration period in milliseconds
* *
* Return: none * Return: none
*/ */
static inline void static inline void qdf_timer_start(qdf_timer_t *timer, int msec)
qdf_timer_start(qdf_timer_t *timer, int msec)
{ {
__qdf_timer_start(timer, msec); __qdf_timer_start(timer, msec);
} }
/** /**
* qdf_timer_mod() - modify existing timer to new timeout value * qdf_timer_mod() - modify the timeout on a timer
* @timer: Timer object pointer * @timer: timer to modify
* @msec: Expiration period in milliseconds * @msec: Expiration period in milliseconds
* *
* If @timer is not active, it will be activated.
*
* Return: none * Return: none
*/ */
static inline void qdf_timer_mod(qdf_timer_t *timer, int msec) static inline void qdf_timer_mod(qdf_timer_t *timer, int msec)
@@ -78,39 +78,40 @@ static inline void qdf_timer_mod(qdf_timer_t *timer, int msec)
} }
/** /**
* qdf_timer_stop() - cancel qdf timer * qdf_timer_stop() - cancel a timer
* @timer: Timer object pointer * @timer: timer to cancel
* *
* return: bool TRUE Timer was cancelled and deactived * Note! The timer callback may be executing when this function call returns.
* FALSE Timer was cancelled but already got fired. * If you want to ensure that it is not, use qdf_timer_sync_cancel() instead.
* *
* The function will return after any running timer completes. * Return: true if @timer was deactivated, false if @timer was not active
*/ */
static inline bool qdf_timer_stop(qdf_timer_t *timer) static inline bool qdf_timer_stop(qdf_timer_t *timer)
{ {
return __qdf_timer_stop(timer); return __qdf_timer_stop(timer);
} }
/** /**
* qdf_timer_sync_cancel - Cancel a timer synchronously * qdf_timer_sync_cancel - Cancel a timer synchronously
* The function will return after any running timer completes. * @timer: timer to cancel
* @timer: timer object pointer
* *
* return: bool TRUE timer was cancelled and deactived * If the timer callback is already running, this function blocks until it
* FALSE timer was not cancelled * completes.
*
* Return: true if @timer was deactivated, false if @timer was not active
*/ */
static inline bool qdf_timer_sync_cancel(qdf_timer_t *timer) static inline bool qdf_timer_sync_cancel(qdf_timer_t *timer)
{ {
return __qdf_timer_sync_cancel(timer); return __qdf_timer_sync_cancel(timer);
} }
/** /**
* qdf_timer_free() - free qdf timer * qdf_timer_free() - free a timer
* @timer: Timer object pointer * @timer: timer to free
*
* If the timer callback is already running, this function blocks until it
* completes.
* *
* The function will return after any running timer completes.
* Return: none * Return: none
*/ */
static inline void qdf_timer_free(qdf_timer_t *timer) static inline void qdf_timer_free(qdf_timer_t *timer)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014-2018 The Linux Foundation. All rights reserved. * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved.
* *
* Permission to use, copy, modify, and/or distribute this software for * Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the * any purpose with or without fee is hereby granted, provided that the
@@ -38,119 +38,68 @@
__setup_timer((timer), (fn), (data), TIMER_DEFERRABLE) __setup_timer((timer), (fn), (data), TIMER_DEFERRABLE)
#endif #endif
/* timer data type */ struct __qdf_timer_t {
typedef struct timer_list __qdf_timer_t; struct timer_list os_timer;
};
typedef void (*__qdf_dummy_timer_func_t)(unsigned long arg); typedef void (*__legacy_timer_callback_t)(unsigned long arg);
/** static inline QDF_STATUS __qdf_timer_init(struct __qdf_timer_t *timer,
* __qdf_timer_init() - initialize a softirq timer
* @timer: Pointer to timer object
* @func: Function pointer
* @arg: Argument
* @type: deferrable or non deferrable timer type
*
* Timer type QDF_TIMER_TYPE_SW means its a deferrable sw timer which will
* not cause CPU wake upon expiry
* Timer type QDF_TIMER_TYPE_WAKE_APPS means its a non-deferrable timer which
* will cause CPU wake up on expiry
*
* Return: QDF_STATUS
*/
static inline QDF_STATUS __qdf_timer_init(struct timer_list *timer,
qdf_timer_func_t func, void *arg, qdf_timer_func_t func, void *arg,
QDF_TIMER_TYPE type) QDF_TIMER_TYPE type)
{ {
bool is_on_stack = object_is_on_stack(timer); struct timer_list *os_timer = &timer->os_timer;
__qdf_dummy_timer_func_t callback = (__qdf_dummy_timer_func_t)func; bool is_on_stack = object_is_on_stack(os_timer);
__legacy_timer_callback_t callback = (__legacy_timer_callback_t)func;
unsigned long ctx = (unsigned long)arg; unsigned long ctx = (unsigned long)arg;
if (type == QDF_TIMER_TYPE_SW) { if (type == QDF_TIMER_TYPE_SW) {
if (is_on_stack) if (is_on_stack)
setup_deferrable_timer_on_stack(timer, callback, ctx); setup_deferrable_timer_on_stack(os_timer, callback,
ctx);
else else
setup_deferrable_timer(timer, callback, ctx); setup_deferrable_timer(os_timer, callback, ctx);
} else { } else {
if (is_on_stack) if (is_on_stack)
setup_timer_on_stack(timer, callback, ctx); setup_timer_on_stack(os_timer, callback, ctx);
else else
setup_timer(timer, callback, ctx); setup_timer(os_timer, callback, ctx);
} }
return QDF_STATUS_SUCCESS; return QDF_STATUS_SUCCESS;
} }
/** static inline void __qdf_timer_start(struct __qdf_timer_t *timer, uint32_t msec)
* __qdf_timer_start() - start a qdf softirq timer
* @timer: Pointer to timer object
* @delay: Delay in milliseconds
*
* Return: None
*/
static inline void __qdf_timer_start(struct timer_list *timer, uint32_t delay)
{ {
timer->expires = jiffies + msecs_to_jiffies(delay); struct timer_list *os_timer = &timer->os_timer;
add_timer(timer);
os_timer->expires = jiffies + msecs_to_jiffies(msec);
add_timer(os_timer);
} }
/** static inline void __qdf_timer_mod(struct __qdf_timer_t *timer, uint32_t msec)
* __qdf_timer_mod() - modify a timer
* @timer: Pointer to timer object
* @delay: Delay in milliseconds
*
* Return: None
*/
static inline void __qdf_timer_mod(struct timer_list *timer, uint32_t delay)
{ {
mod_timer(timer, jiffies + msecs_to_jiffies(delay)); mod_timer(&timer->os_timer, jiffies + msecs_to_jiffies(msec));
} }
/** static inline bool __qdf_timer_stop(struct __qdf_timer_t *timer)
* __qdf_timer_stop() - cancel a timer
* @timer: Pointer to timer object
*
* Return: true if timer was cancelled and deactived,
* false if timer was cancelled but already got fired.
*/
static inline bool __qdf_timer_stop(struct timer_list *timer)
{ {
if (likely(del_timer(timer))) return !!del_timer(&timer->os_timer);
return 1;
else
return 0;
} }
/** static inline void __qdf_timer_free(struct __qdf_timer_t *timer)
* __qdf_timer_free() - free a qdf timer
* @timer: Pointer to timer object
*
* Return: None
*/
static inline void __qdf_timer_free(struct timer_list *timer)
{ {
del_timer_sync(timer); struct timer_list *os_timer = &timer->os_timer;
if (object_is_on_stack(timer)) del_timer_sync(os_timer);
destroy_timer_on_stack(timer);
if (object_is_on_stack(os_timer))
destroy_timer_on_stack(os_timer);
} }
/** static inline bool __qdf_timer_sync_cancel(struct __qdf_timer_t *timer)
* __qdf_sostirq_timer_sync_cancel() - Synchronously canel a timer
* @timer: Pointer to timer object
*
* Synchronization Rules:
* 1. caller must make sure timer function will not use
* qdf_set_timer to add iteself again.
* 2. caller must not hold any lock that timer function
* is likely to hold as well.
* 3. It can't be called from interrupt context.
*
* Return: true if timer was cancelled and deactived,
* false if timer was cancelled but already got fired.
*/
static inline bool __qdf_timer_sync_cancel(struct timer_list *timer)
{ {
return del_timer_sync(timer); return del_timer_sync(&timer->os_timer);
} }
#endif /*_QDF_TIMER_PVT_H*/ #endif /* _I_QDF_TIMER_H */