Merge tag 'driver-core-4.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull driver core fixes from Greg KH:
"Here are three firmware core fixes for 4.13-rc5.

All three of these fix reported issues and have been floating around
for a few weeks. They have been in linux-next with no reported
problems"

* tag 'driver-core-4.13-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
firmware: avoid invalid fallback aborts by using killable wait
firmware: fix batched requests - send wake up on failure on direct lookups
firmware: fix batched requests - wake all waiters

Changed files
+34 -15
drivers
+34 -15
drivers/base/firmware_class.c
··· 30 30 #include <linux/syscore_ops.h> 31 31 #include <linux/reboot.h> 32 32 #include <linux/security.h> 33 - #include <linux/swait.h> 34 33 35 34 #include <generated/utsrelease.h> 36 35 ··· 111 112 * state of the firmware loading. 112 113 */ 113 114 struct fw_state { 114 - struct swait_queue_head wq; 115 + struct completion completion; 115 116 enum fw_status status; 116 117 }; 117 118 118 119 static void fw_state_init(struct fw_state *fw_st) 119 120 { 120 - init_swait_queue_head(&fw_st->wq); 121 + init_completion(&fw_st->completion); 121 122 fw_st->status = FW_STATUS_UNKNOWN; 122 123 } 123 124 ··· 130 131 { 131 132 long ret; 132 133 133 - ret = swait_event_interruptible_timeout(fw_st->wq, 134 - __fw_state_is_done(READ_ONCE(fw_st->status)), 135 - timeout); 134 + ret = wait_for_completion_killable_timeout(&fw_st->completion, timeout); 136 135 if (ret != 0 && fw_st->status == FW_STATUS_ABORTED) 137 136 return -ENOENT; 138 137 if (!ret) ··· 145 148 WRITE_ONCE(fw_st->status, status); 146 149 147 150 if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED) 148 - swake_up(&fw_st->wq); 151 + complete_all(&fw_st->completion); 149 152 } 150 153 151 154 #define fw_state_start(fw_st) \ 152 155 __fw_state_set(fw_st, FW_STATUS_LOADING) 153 156 #define fw_state_done(fw_st) \ 154 157 __fw_state_set(fw_st, FW_STATUS_DONE) 158 + #define fw_state_aborted(fw_st) \ 159 + __fw_state_set(fw_st, FW_STATUS_ABORTED) 155 160 #define fw_state_wait(fw_st) \ 156 161 __fw_state_wait_common(fw_st, MAX_SCHEDULE_TIMEOUT) 157 - 158 - #ifndef CONFIG_FW_LOADER_USER_HELPER 159 - 160 - #define fw_state_is_aborted(fw_st) false 161 - 162 - #else /* CONFIG_FW_LOADER_USER_HELPER */ 163 162 164 163 static int __fw_state_check(struct fw_state *fw_st, enum fw_status status) 165 164 { 166 165 return fw_st->status == status; 167 166 } 167 + 168 + #define fw_state_is_aborted(fw_st) \ 169 + __fw_state_check(fw_st, FW_STATUS_ABORTED) 170 + 171 + #ifdef CONFIG_FW_LOADER_USER_HELPER 168 172 169 173 #define fw_state_aborted(fw_st) \ 170 174 __fw_state_set(fw_st, FW_STATUS_ABORTED) ··· 173 175 __fw_state_check(fw_st, FW_STATUS_DONE) 174 176 #define fw_state_is_loading(fw_st) \ 175 177 __fw_state_check(fw_st, FW_STATUS_LOADING) 176 - #define fw_state_is_aborted(fw_st) \ 177 - __fw_state_check(fw_st, FW_STATUS_ABORTED) 178 178 #define fw_state_wait_timeout(fw_st, timeout) \ 179 179 __fw_state_wait_common(fw_st, timeout) 180 180 ··· 1196 1200 return 1; /* need to load */ 1197 1201 } 1198 1202 1203 + /* 1204 + * Batched requests need only one wake, we need to do this step last due to the 1205 + * fallback mechanism. The buf is protected with kref_get(), and it won't be 1206 + * released until the last user calls release_firmware(). 1207 + * 1208 + * Failed batched requests are possible as well, in such cases we just share 1209 + * the struct firmware_buf and won't release it until all requests are woken 1210 + * and have gone through this same path. 1211 + */ 1212 + static void fw_abort_batch_reqs(struct firmware *fw) 1213 + { 1214 + struct firmware_buf *buf; 1215 + 1216 + /* Loaded directly? */ 1217 + if (!fw || !fw->priv) 1218 + return; 1219 + 1220 + buf = fw->priv; 1221 + if (!fw_state_is_aborted(&buf->fw_st)) 1222 + fw_state_aborted(&buf->fw_st); 1223 + } 1224 + 1199 1225 /* called from request_firmware() and request_firmware_work_func() */ 1200 1226 static int 1201 1227 _request_firmware(const struct firmware **firmware_p, const char *name, ··· 1261 1243 1262 1244 out: 1263 1245 if (ret < 0) { 1246 + fw_abort_batch_reqs(fw); 1264 1247 release_firmware(fw); 1265 1248 fw = NULL; 1266 1249 }