Skip to content

Commit bfb88d6

Browse files
Pavan Savoygregkh
authored andcommitted
drivers:misc: ti-st: protect registrations
Concurrent access to UART2/combo-interface by multiple protocol drivers such as BT, FM and GPS caused issues during firmware download failure cases or cases when the firmware download took longer than usual. This was because of un-safe access to protos_registered & st_states. Protecting this will also make the registration complete callback un-safe for sleep. Signed-off-by: Pavan Savoy <pavan_savoy@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 1ff9764 commit bfb88d6

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎drivers/misc/ti-st/st_core.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
137137
* st_reg_complete -
138138
* to call registration complete callbacks
139139
* of all protocol stack drivers
140+
* This function is being called with spin lock held, protocol drivers are
141+
* only expected to complete their waits and do nothing more than that.
140142
*/
141143
void st_reg_complete(struct st_data_s *st_gdata, char err)
142144
{
@@ -538,11 +540,12 @@ long st_register(struct st_proto_s *new_proto)
538540
set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
539541
st_recv = st_kim_recv;
540542

543+
/* enable the ST LL - to set default chip state */
544+
st_ll_enable(st_gdata);
545+
541546
/* release lock previously held - re-locked below */
542547
spin_unlock_irqrestore(&st_gdata->lock, flags);
543548

544-
/* enable the ST LL - to set default chip state */
545-
st_ll_enable(st_gdata);
546549
/* this may take a while to complete
547550
* since it involves BT fw download
548551
*/
@@ -553,10 +556,13 @@ long st_register(struct st_proto_s *new_proto)
553556
(test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
554557
pr_err(" KIM failure complete callback ");
555558
st_reg_complete(st_gdata, err);
559+
clear_bit(ST_REG_PENDING, &st_gdata->st_state);
556560
}
557561
return -EINVAL;
558562
}
559563

564+
spin_lock_irqsave(&st_gdata->lock, flags);
565+
560566
clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
561567
st_recv = st_int_recv;
562568

@@ -576,10 +582,10 @@ long st_register(struct st_proto_s *new_proto)
576582
if (st_gdata->is_registered[new_proto->chnl_id] == true) {
577583
pr_err(" proto %d already registered ",
578584
new_proto->chnl_id);
585+
spin_unlock_irqrestore(&st_gdata->lock, flags);
579586
return -EALREADY;
580587
}
581588

582-
spin_lock_irqsave(&st_gdata->lock, flags);
583589
add_channel_to_table(st_gdata, new_proto);
584590
st_gdata->protos_registered++;
585591
new_proto->write = st_write;
@@ -619,7 +625,7 @@ long st_unregister(struct st_proto_s *proto)
619625

620626
spin_lock_irqsave(&st_gdata->lock, flags);
621627

622-
if (st_gdata->list[proto->chnl_id] == NULL) {
628+
if (st_gdata->is_registered[proto->chnl_id] == false) {
623629
pr_err(" chnl_id %d not registered", proto->chnl_id);
624630
spin_unlock_irqrestore(&st_gdata->lock, flags);
625631
return -EPROTONOSUPPORT;
@@ -629,6 +635,10 @@ long st_unregister(struct st_proto_s *proto)
629635
remove_channel_from_table(st_gdata, proto);
630636
spin_unlock_irqrestore(&st_gdata->lock, flags);
631637

638+
/* paranoid check */
639+
if (st_gdata->protos_registered < ST_EMPTY)
640+
st_gdata->protos_registered = ST_EMPTY;
641+
632642
if ((st_gdata->protos_registered == ST_EMPTY) &&
633643
(!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
634644
pr_info(" all chnl_ids unregistered ");

0 commit comments

Comments
 (0)