aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c58
1 files changed, 0 insertions, 58 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index eab303d148d8..3042520c413c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2257,61 +2257,3 @@ scsi_target_unblock(struct device *dev)
2257 device_for_each_child(dev, NULL, target_unblock); 2257 device_for_each_child(dev, NULL, target_unblock);
2258} 2258}
2259EXPORT_SYMBOL_GPL(scsi_target_unblock); 2259EXPORT_SYMBOL_GPL(scsi_target_unblock);
2260
2261
2262struct work_queue_work {
2263 struct work_struct work;
2264 void (*fn)(void *);
2265 void *data;
2266};
2267
2268static void execute_in_process_context_work(void *data)
2269{
2270 void (*fn)(void *data);
2271 struct work_queue_work *wqw = data;
2272
2273 fn = wqw->fn;
2274 data = wqw->data;
2275
2276 kfree(wqw);
2277
2278 fn(data);
2279}
2280
2281/**
2282 * scsi_execute_in_process_context - reliably execute the routine with user context
2283 * @fn: the function to execute
2284 * @data: data to pass to the function
2285 *
2286 * Executes the function immediately if process context is available,
2287 * otherwise schedules the function for delayed execution.
2288 *
2289 * Returns: 0 - function was executed
2290 * 1 - function was scheduled for execution
2291 * <0 - error
2292 */
2293int scsi_execute_in_process_context(void (*fn)(void *data), void *data)
2294{
2295 struct work_queue_work *wqw;
2296
2297 if (!in_interrupt()) {
2298 fn(data);
2299 return 0;
2300 }
2301
2302 wqw = kmalloc(sizeof(struct work_queue_work), GFP_ATOMIC);
2303
2304 if (unlikely(!wqw)) {
2305 printk(KERN_ERR "Failed to allocate memory\n");
2306 WARN_ON(1);
2307 return -ENOMEM;
2308 }
2309
2310 INIT_WORK(&wqw->work, execute_in_process_context_work, wqw);
2311 wqw->fn = fn;
2312 wqw->data = data;
2313 schedule_work(&wqw->work);
2314
2315 return 1;
2316}
2317EXPORT_SYMBOL_GPL(scsi_execute_in_process_context);