From 30a5d8997ffe75f660450a3a19c3ab2d1b2d89f1 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 13 Sep 2018 14:47:52 -0700 Subject: [PATCH] soc: qcom: sysmon-qmi: Fix duplicate BEFORE_POWERUP SSCTL events Currently, when sending an SSCTL SSR event, the event is obtained by blindly following a map from the notification ID provided by the subsystem notifier framework to an SSCTL SSR event. Since all the entries in the map that are not explicitly defined are initialized to 0 (SSCTL_SSR_EVENT_BEFORE_POWERUP), then notifications, such as SUBSYS_PROXY_VOTE, that do not map to an actual SSCTL event map to SSCTL_SSR_EVENT_BEFORE_POWERUP, resulting in multiple SSCTL_SSR_EVENT_BEFORE_POWERUP notifications being sent. To avoid this, mark all the notification ID to SSCTL event mappings that are not defined, as SSCTL_EVENT_SSR_INVALID, and prior to sending an SSCTL SSR event for a notification ID, check to ensure that the notification ID maps to a defined SSCTL event. Change-Id: If4e4fcd12f7acc6eb82f9776a9db8bc9066d3c4e Signed-off-by: Isaac J. Manjarres --- drivers/soc/qcom/sysmon-qmi.c | 12 +++++++++--- include/soc/qcom/sysmon.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/soc/qcom/sysmon-qmi.c b/drivers/soc/qcom/sysmon-qmi.c index f4c7779f286d..ea4b5a5b5bc2 100644 --- a/drivers/soc/qcom/sysmon-qmi.c +++ b/drivers/soc/qcom/sysmon-qmi.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -88,6 +88,7 @@ static void sysmon_clnt_svc_arrive(struct work_struct *work); static void sysmon_clnt_svc_exit(struct work_struct *work); static const int notif_map[SUBSYS_NOTIF_TYPE_COUNT] = { + [0 ... SUBSYS_NOTIF_TYPE_COUNT - 1] = SSCTL_SSR_EVENT_INVALID, [SUBSYS_BEFORE_POWERUP] = SSCTL_SSR_EVENT_BEFORE_POWERUP, [SUBSYS_AFTER_POWERUP] = SSCTL_SSR_EVENT_AFTER_POWERUP, [SUBSYS_BEFORE_SHUTDOWN] = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN, @@ -147,6 +148,11 @@ static void sysmon_clnt_notify(struct qmi_handle *handle, } } +static bool is_ssctl_event(enum subsys_notif_type notif) +{ + return notif_map[notif] != SSCTL_SSR_EVENT_INVALID; +} + static void sysmon_clnt_svc_arrive(struct work_struct *work) { int rc; @@ -318,8 +324,8 @@ int sysmon_send_event(struct subsys_desc *dest_desc, const char *dest_ss = dest_desc->name; int ret; - if (notif < 0 || notif >= SUBSYS_NOTIF_TYPE_COUNT || event_ss == NULL - || dest_ss == NULL) + if (notif < 0 || notif >= SUBSYS_NOTIF_TYPE_COUNT || + !is_ssctl_event(notif) || event_ss == NULL || dest_ss == NULL) return -EINVAL; mutex_lock(&sysmon_list_lock); diff --git a/include/soc/qcom/sysmon.h b/include/soc/qcom/sysmon.h index 2ad3a5e1fb33..cca1dcc05e5e 100644 --- a/include/soc/qcom/sysmon.h +++ b/include/soc/qcom/sysmon.h @@ -40,6 +40,7 @@ enum subsys_id { */ enum ssctl_ssr_event_enum_type { SSCTL_SSR_EVENT_ENUM_TYPE_MIN_ENUM_VAL = -2147483647, + SSCTL_SSR_EVENT_INVALID = -1, SSCTL_SSR_EVENT_BEFORE_POWERUP = 0, SSCTL_SSR_EVENT_AFTER_POWERUP = 1, SSCTL_SSR_EVENT_BEFORE_SHUTDOWN = 2,