Skip to content

Commit 5c3c16e

Browse files
committed
Check event delay function before calling it
If no event handler has been set or an event handler has been removed, the delay function will be NULL. Nevertheless, events may still be sent by the EC (whether configured to do so or not), so we need to check the delay function and ensure it is non-NULL before calling it. In case it is NULL, we assume a delay of zero, forwarding it to the workq-queue and let the work function take care of logging it as unhandled event. Reported by: Blaž Hrastnik <blaz@mxxn.io>
1 parent 3ae7719 commit 5c3c16e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

module/surface_sam_ssh.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static void ssh_handle_event(struct sam_ssh_ec *ec, const u8 *buf)
909909

910910
surface_sam_ssh_event_handler_delay delay_fn;
911911
void *handler_data;
912-
unsigned long delay = 0;
912+
unsigned long delay;
913913

914914
ctrl = (const struct ssh_frame_ctrl *)(buf + SSH_FRAME_OFFS_CTRL);
915915
cmd = (const struct ssh_frame_cmd *)(buf + SSH_FRAME_OFFS_CMD);
@@ -945,7 +945,12 @@ static void ssh_handle_event(struct sam_ssh_ec *ec, const u8 *buf)
945945
spin_lock_irqsave(&ec->events.lock, flags);
946946
handler_data = ec->events.handler[work->event.rqid - 1].data;
947947
delay_fn = ec->events.handler[work->event.rqid - 1].delay;
948-
delay = delay_fn(&work->event, handler_data);
948+
949+
/* Note:
950+
* We need to check delay_fn here: This may have never been set as we
951+
* can't guarantee that events only occur when they have been enabled.
952+
*/
953+
delay = delay_fn ? delay_fn(&work->event, handler_data) : 0;
949954
spin_unlock_irqrestore(&ec->events.lock, flags);
950955

951956
// immediate execution for high priority events (e.g. keyboard)

0 commit comments

Comments
 (0)