Bluetooth: Convert timers to use timer_setup()

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. As already done in hci_qca, add
struct hci_uart pointer to priv structure.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
This commit is contained in:
Kees Cook 2017-10-04 17:54:29 -07:00 committed by Marcel Holtmann
parent 8a92056837
commit 0435605289
4 changed files with 23 additions and 21 deletions

View File

@ -156,9 +156,9 @@ static void bluecard_detach(struct pcmcia_device *p_dev);
/* ======================== LED handling routines ======================== */ /* ======================== LED handling routines ======================== */
static void bluecard_activity_led_timeout(u_long arg) static void bluecard_activity_led_timeout(struct timer_list *t)
{ {
struct bluecard_info *info = (struct bluecard_info *)arg; struct bluecard_info *info = from_timer(info, t, timer);
unsigned int iobase = info->p_dev->resource[0]->start; unsigned int iobase = info->p_dev->resource[0]->start;
if (test_bit(CARD_ACTIVITY, &(info->hw_state))) { if (test_bit(CARD_ACTIVITY, &(info->hw_state))) {
@ -691,8 +691,7 @@ static int bluecard_open(struct bluecard_info *info)
spin_lock_init(&(info->lock)); spin_lock_init(&(info->lock));
setup_timer(&(info->timer), &bluecard_activity_led_timeout, timer_setup(&info->timer, bluecard_activity_led_timeout, 0);
(u_long)info);
skb_queue_head_init(&(info->txq)); skb_queue_head_init(&(info->txq));

View File

@ -65,6 +65,7 @@ struct bcsp_struct {
u8 rxseq_txack; /* rxseq == txack. */ u8 rxseq_txack; /* rxseq == txack. */
u8 rxack; /* Last packet sent by us that the peer ack'ed */ u8 rxack; /* Last packet sent by us that the peer ack'ed */
struct timer_list tbcsp; struct timer_list tbcsp;
struct hci_uart *hu;
enum { enum {
BCSP_W4_PKT_DELIMITER, BCSP_W4_PKT_DELIMITER,
@ -697,10 +698,10 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
} }
/* Arrange to retransmit all messages in the relq. */ /* Arrange to retransmit all messages in the relq. */
static void bcsp_timed_event(unsigned long arg) static void bcsp_timed_event(struct timer_list *t)
{ {
struct hci_uart *hu = (struct hci_uart *)arg; struct bcsp_struct *bcsp = from_timer(bcsp, t, tbcsp);
struct bcsp_struct *bcsp = hu->priv; struct hci_uart *hu = bcsp->hu;
struct sk_buff *skb; struct sk_buff *skb;
unsigned long flags; unsigned long flags;
@ -729,11 +730,12 @@ static int bcsp_open(struct hci_uart *hu)
return -ENOMEM; return -ENOMEM;
hu->priv = bcsp; hu->priv = bcsp;
bcsp->hu = hu;
skb_queue_head_init(&bcsp->unack); skb_queue_head_init(&bcsp->unack);
skb_queue_head_init(&bcsp->rel); skb_queue_head_init(&bcsp->rel);
skb_queue_head_init(&bcsp->unrel); skb_queue_head_init(&bcsp->unrel);
setup_timer(&bcsp->tbcsp, bcsp_timed_event, (u_long)hu); timer_setup(&bcsp->tbcsp, bcsp_timed_event, 0);
bcsp->rx_state = BCSP_W4_PKT_DELIMITER; bcsp->rx_state = BCSP_W4_PKT_DELIMITER;

View File

@ -78,6 +78,7 @@ struct h5 {
int (*rx_func)(struct hci_uart *hu, u8 c); int (*rx_func)(struct hci_uart *hu, u8 c);
struct timer_list timer; /* Retransmission timer */ struct timer_list timer; /* Retransmission timer */
struct hci_uart *hu; /* Parent HCI UART */
u8 tx_seq; /* Next seq number to send */ u8 tx_seq; /* Next seq number to send */
u8 tx_ack; /* Next ack number to send */ u8 tx_ack; /* Next ack number to send */
@ -120,12 +121,12 @@ static u8 h5_cfg_field(struct h5 *h5)
return h5->tx_win & 0x07; return h5->tx_win & 0x07;
} }
static void h5_timed_event(unsigned long arg) static void h5_timed_event(struct timer_list *t)
{ {
const unsigned char sync_req[] = { 0x01, 0x7e }; const unsigned char sync_req[] = { 0x01, 0x7e };
unsigned char conf_req[3] = { 0x03, 0xfc }; unsigned char conf_req[3] = { 0x03, 0xfc };
struct hci_uart *hu = (struct hci_uart *)arg; struct h5 *h5 = from_timer(h5, t, timer);
struct h5 *h5 = hu->priv; struct hci_uart *hu = h5->hu;
struct sk_buff *skb; struct sk_buff *skb;
unsigned long flags; unsigned long flags;
@ -197,6 +198,7 @@ static int h5_open(struct hci_uart *hu)
return -ENOMEM; return -ENOMEM;
hu->priv = h5; hu->priv = h5;
h5->hu = hu;
skb_queue_head_init(&h5->unack); skb_queue_head_init(&h5->unack);
skb_queue_head_init(&h5->rel); skb_queue_head_init(&h5->rel);
@ -204,7 +206,7 @@ static int h5_open(struct hci_uart *hu)
h5_reset_rx(h5); h5_reset_rx(h5);
setup_timer(&h5->timer, h5_timed_event, (unsigned long)hu); timer_setup(&h5->timer, h5_timed_event, 0);
h5->tx_win = H5_TX_WIN_MAX; h5->tx_win = H5_TX_WIN_MAX;

View File

@ -307,10 +307,10 @@ static void qca_wq_serial_tx_clock_vote_off(struct work_struct *work)
serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu); serial_clock_vote(HCI_IBS_TX_VOTE_CLOCK_OFF, hu);
} }
static void hci_ibs_tx_idle_timeout(unsigned long arg) static void hci_ibs_tx_idle_timeout(struct timer_list *t)
{ {
struct hci_uart *hu = (struct hci_uart *)arg; struct qca_data *qca = from_timer(qca, t, tx_idle_timer);
struct qca_data *qca = hu->priv; struct hci_uart *hu = qca->hu;
unsigned long flags; unsigned long flags;
BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state); BT_DBG("hu %p idle timeout in %d state", hu, qca->tx_ibs_state);
@ -342,10 +342,10 @@ static void hci_ibs_tx_idle_timeout(unsigned long arg)
spin_unlock_irqrestore(&qca->hci_ibs_lock, flags); spin_unlock_irqrestore(&qca->hci_ibs_lock, flags);
} }
static void hci_ibs_wake_retrans_timeout(unsigned long arg) static void hci_ibs_wake_retrans_timeout(struct timer_list *t)
{ {
struct hci_uart *hu = (struct hci_uart *)arg; struct qca_data *qca = from_timer(qca, t, wake_retrans_timer);
struct qca_data *qca = hu->priv; struct hci_uart *hu = qca->hu;
unsigned long flags, retrans_delay; unsigned long flags, retrans_delay;
bool retransmit = false; bool retransmit = false;
@ -438,11 +438,10 @@ static int qca_open(struct hci_uart *hu)
hu->priv = qca; hu->priv = qca;
setup_timer(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, timer_setup(&qca->wake_retrans_timer, hci_ibs_wake_retrans_timeout, 0);
(u_long)hu);
qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS; qca->wake_retrans = IBS_WAKE_RETRANS_TIMEOUT_MS;
setup_timer(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, (u_long)hu); timer_setup(&qca->tx_idle_timer, hci_ibs_tx_idle_timeout, 0);
qca->tx_idle_delay = IBS_TX_IDLE_TIMEOUT_MS; qca->tx_idle_delay = IBS_TX_IDLE_TIMEOUT_MS;
BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u", BT_DBG("HCI_UART_QCA open, tx_idle_delay=%u, wake_retrans=%u",