Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: vchiq_core: introduce handle_poll

The function slot_handler_func() has very deep indentations. Moving the
poll handling into separate function could improve the readability.
Use the return value to keep the poll_needed handling at the same place.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Link: https://lore.kernel.org/r/1622735405-9980-17-git-send-email-stefan.wahren@i2se.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Stefan Wahren and committed by
Greg Kroah-Hartman
33e82ff2 826818f8

+52 -40
+52 -40
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
··· 1992 1992 } 1993 1993 } 1994 1994 1995 + /** 1996 + * handle_poll() - handle service polling and other rare conditions 1997 + * @state: vchiq state struct 1998 + * 1999 + * Context: Process context 2000 + * 2001 + * Return: 2002 + * * 0 - poll handled successful 2003 + * * -EAGAIN - retry later 2004 + */ 2005 + static int 2006 + handle_poll(struct vchiq_state *state) 2007 + { 2008 + switch (state->conn_state) { 2009 + case VCHIQ_CONNSTATE_CONNECTED: 2010 + /* Poll the services as requested */ 2011 + poll_services(state); 2012 + break; 2013 + 2014 + case VCHIQ_CONNSTATE_PAUSING: 2015 + if (queue_message(state, NULL, MAKE_PAUSE, NULL, NULL, 0, 2016 + QMFLAGS_NO_MUTEX_UNLOCK) != VCHIQ_RETRY) { 2017 + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSE_SENT); 2018 + } else { 2019 + /* Retry later */ 2020 + return -EAGAIN; 2021 + } 2022 + break; 2023 + 2024 + case VCHIQ_CONNSTATE_RESUMING: 2025 + if (queue_message(state, NULL, MAKE_RESUME, NULL, NULL, 0, 2026 + QMFLAGS_NO_MUTEX_LOCK) != VCHIQ_RETRY) { 2027 + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED); 2028 + } else { 2029 + /* 2030 + * This should really be impossible, 2031 + * since the PAUSE should have flushed 2032 + * through outstanding messages. 2033 + */ 2034 + vchiq_log_error(vchiq_core_log_level, 2035 + "Failed to send RESUME message"); 2036 + } 2037 + break; 2038 + default: 2039 + break; 2040 + } 2041 + 2042 + return 0; 2043 + } 2044 + 1995 2045 /* Called by the slot handler thread */ 1996 2046 static int 1997 2047 slot_handler_func(void *v) ··· 2060 2010 2061 2011 DEBUG_TRACE(SLOT_HANDLER_LINE); 2062 2012 if (state->poll_needed) { 2063 - 2064 2013 state->poll_needed = 0; 2065 2014 2066 2015 /* 2067 2016 * Handle service polling and other rare conditions here 2068 2017 * out of the mainline code 2069 2018 */ 2070 - switch (state->conn_state) { 2071 - case VCHIQ_CONNSTATE_CONNECTED: 2072 - /* Poll the services as requested */ 2073 - poll_services(state); 2074 - break; 2075 - 2076 - case VCHIQ_CONNSTATE_PAUSING: 2077 - if (queue_message(state, NULL, MAKE_PAUSE, 2078 - NULL, NULL, 0, 2079 - QMFLAGS_NO_MUTEX_UNLOCK) 2080 - != VCHIQ_RETRY) { 2081 - vchiq_set_conn_state(state, 2082 - VCHIQ_CONNSTATE_PAUSE_SENT); 2083 - } else { 2084 - /* Retry later */ 2085 - state->poll_needed = 1; 2086 - } 2087 - break; 2088 - 2089 - case VCHIQ_CONNSTATE_RESUMING: 2090 - if (queue_message(state, NULL, MAKE_RESUME, 2091 - NULL, NULL, 0, QMFLAGS_NO_MUTEX_LOCK) 2092 - != VCHIQ_RETRY) { 2093 - vchiq_set_conn_state(state, 2094 - VCHIQ_CONNSTATE_CONNECTED); 2095 - } else { 2096 - /* 2097 - * This should really be impossible, 2098 - * since the PAUSE should have flushed 2099 - * through outstanding messages. 2100 - */ 2101 - vchiq_log_error(vchiq_core_log_level, 2102 - "Failed to send RESUME message"); 2103 - } 2104 - break; 2105 - default: 2106 - break; 2107 - } 2108 - 2019 + if (handle_poll(state) == -EAGAIN) 2020 + state->poll_needed = 1; 2109 2021 } 2110 2022 2111 2023 DEBUG_TRACE(SLOT_HANDLER_LINE);