The comment to flush_scheduled_work states that calling this function in the context of a work routine will lead to deadlock. I think it means following scenario:

static void
handler(struct work_struct *work)
{
    flush_scheduled_work();
}
static DECLARE_WORK(work, handler);
schedule_work(&work);

If this is true for system workqueue (system_wq) is it also applied to custom workqueue? I want to wait for completion of the workqueues in another workqueue. For example:

static void
handler(struct work_struct *work)
{
    struct work_data * data = (struct work_data *)work;
    flush_scheduled_work();
    kfree(data);
}
  wq = create_workqueue("wq_test");
  data = kmalloc(sizeof(struct work_data), GFP_KERNEL);
  INIT_WORK(&data->work, handler);
  queue_work(wq, &data->work);