Browse Source

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
Dustin Brown 6 years ago
parent
commit
bf8e81ef4c
2 changed files with 56 additions and 106 deletions
  1. 24 23
      qdf/inc/qdf_timer.h
  2. 32 83
      qdf/linux/src/i_qdf_timer.h

+ 24 - 23
qdf/inc/qdf_timer.h

@@ -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
  * any purpose with or without fee is hereby granted, provided that the
@@ -27,8 +27,7 @@
 #include <qdf_types.h>
 #include <i_qdf_timer.h>
 
-/* Platform timer object */
-typedef __qdf_timer_t qdf_timer_t;
+typedef struct __qdf_timer_t qdf_timer_t;
 
 /**
  * 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
- * @timer: Timer object pointer
+ * qdf_timer_start() - start a timer
+ * @timer: timer to start
  * @msec: Expiration period in milliseconds
  *
  * Return: none
  */
-static inline void
-qdf_timer_start(qdf_timer_t *timer, int msec)
+static inline void qdf_timer_start(qdf_timer_t *timer, int msec)
 {
 	__qdf_timer_start(timer, msec);
 }
 
 /**
- * qdf_timer_mod() - modify existing timer to new timeout value
- * @timer: Timer object pointer
+ * qdf_timer_mod() - modify the timeout on a timer
+ * @timer: timer to modify
  * @msec: Expiration period in milliseconds
  *
+ * If @timer is not active, it will be activated.
+ *
  * Return: none
  */
 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
- * @timer: Timer object pointer
+ * qdf_timer_stop() - cancel a timer
+ * @timer: timer to cancel
  *
- * return: bool TRUE Timer was cancelled and deactived
- * FALSE Timer was cancelled but already got fired.
+ * Note! The timer callback may be executing when this function call returns.
+ * 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)
 {
 	return __qdf_timer_stop(timer);
 }
 
-
 /**
  * qdf_timer_sync_cancel - Cancel a timer synchronously
- * The function will return after any running timer completes.
- * @timer: timer object pointer
+ * @timer: timer to cancel
  *
- * return: bool TRUE timer was cancelled and deactived
- * FALSE timer was not cancelled
+ * If the timer callback is already running, this function blocks until it
+ * completes.
+ *
+ * Return: true if @timer was deactivated, false if @timer was not active
  */
 static inline bool qdf_timer_sync_cancel(qdf_timer_t *timer)
 {
 	return __qdf_timer_sync_cancel(timer);
 }
 
-
 /**
- * qdf_timer_free() - free qdf timer
- * @timer: Timer object pointer
+ * qdf_timer_free() - free a timer
+ * @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
  */
 static inline void qdf_timer_free(qdf_timer_t *timer)

+ 32 - 83
qdf/linux/src/i_qdf_timer.h

@@ -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
  * any purpose with or without fee is hereby granted, provided that the
@@ -38,119 +38,68 @@
 	__setup_timer((timer), (fn), (data), TIMER_DEFERRABLE)
 #endif
 
-/* timer data type */
-typedef struct timer_list __qdf_timer_t;
+struct __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);
 
-/**
- * __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,
+static inline QDF_STATUS __qdf_timer_init(struct __qdf_timer_t *timer,
 					  qdf_timer_func_t func, void *arg,
 					  QDF_TIMER_TYPE type)
 {
-	bool is_on_stack = object_is_on_stack(timer);
-	__qdf_dummy_timer_func_t callback = (__qdf_dummy_timer_func_t)func;
+	struct timer_list *os_timer = &timer->os_timer;
+	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;
 
 	if (type == QDF_TIMER_TYPE_SW) {
 		if (is_on_stack)
-			setup_deferrable_timer_on_stack(timer, callback, ctx);
+			setup_deferrable_timer_on_stack(os_timer, callback,
+							ctx);
 		else
-			setup_deferrable_timer(timer, callback, ctx);
+			setup_deferrable_timer(os_timer, callback, ctx);
 	} else {
 		if (is_on_stack)
-			setup_timer_on_stack(timer, callback, ctx);
+			setup_timer_on_stack(os_timer, callback, ctx);
 		else
-			setup_timer(timer, callback, ctx);
+			setup_timer(os_timer, callback, ctx);
 	}
 
 	return QDF_STATUS_SUCCESS;
 }
 
-/**
- * __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)
+static inline void __qdf_timer_start(struct __qdf_timer_t *timer, uint32_t msec)
 {
-	timer->expires = jiffies + msecs_to_jiffies(delay);
-	add_timer(timer);
+	struct timer_list *os_timer = &timer->os_timer;
+
+	os_timer->expires = jiffies + msecs_to_jiffies(msec);
+	add_timer(os_timer);
 }
 
-/**
- * __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)
+static inline void __qdf_timer_mod(struct __qdf_timer_t *timer, uint32_t msec)
 {
-	mod_timer(timer, jiffies + msecs_to_jiffies(delay));
+	mod_timer(&timer->os_timer, jiffies + msecs_to_jiffies(msec));
 }
 
-/**
- * __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)
+static inline bool __qdf_timer_stop(struct __qdf_timer_t *timer)
 {
-	if (likely(del_timer(timer)))
-		return 1;
-	else
-		return 0;
+	return !!del_timer(&timer->os_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)
+static inline void __qdf_timer_free(struct __qdf_timer_t *timer)
 {
-	del_timer_sync(timer);
+	struct timer_list *os_timer = &timer->os_timer;
 
-	if (object_is_on_stack(timer))
-		destroy_timer_on_stack(timer);
+	del_timer_sync(os_timer);
+
+	if (object_is_on_stack(os_timer))
+		destroy_timer_on_stack(os_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)
+static inline bool __qdf_timer_sync_cancel(struct __qdf_timer_t *timer)
 {
-	return del_timer_sync(timer);
+	return del_timer_sync(&timer->os_timer);
 }
 
-#endif /*_QDF_TIMER_PVT_H*/
+#endif /* _I_QDF_TIMER_H */