spi: Dont call prepare/unprepare transfer if not populated
Shubhrajyoti D [Thu, 10 May 2012 13:50:41 +0000 (18:50 +0530)]
Currently the prepare/unprepare transfer are called unconditionally.
The assumption is that every driver using the spi core queue infrastructure
has to populate the prepare and unprepare functions. This encourages
drivers to populate empty functions to prevent crashing.
This patch prevents the call to prepare/unprepare if not populated.

Bug 1297342
Bug 1394476

Change-Id: I90ea3f18818eea7169d9d365ef26c61519debafb
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Shardar Shariff Md <smohammed@nvidia.com>
Reviewed-on: http://git-master/r/240007
(cherry picked commit from mainline 7dfd2bd70228d1f8d468d58cb3d12ecd618479ed)
(cherry picked from commit c01241fe4c38dbc168c302c4ecde8703959b2890)
Reviewed-on: http://git-master/r/333032
Reviewed-by: Harry Hong <hhong@nvidia.com>
Tested-by: Harry Hong <hhong@nvidia.com>

drivers/spi/spi.c

index 3d8f662..1d3de42 100644 (file)
@@ -2,6 +2,7 @@
  * SPI init/core code
  *
  * Copyright (C) 2005 David Brownell
+ * Copyright (C) 2012-2013, NVIDIA Corporation.  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 as published by
@@ -530,7 +531,7 @@ static void spi_pump_messages(struct kthread_work *work)
        /* Lock queue and check for queue work */
        spin_lock_irqsave(&master->queue_lock, flags);
        if (list_empty(&master->queue) || !master->running) {
-               if (master->busy) {
+               if (master->busy && master->unprepare_transfer_hardware) {
                        ret = master->unprepare_transfer_hardware(master);
                        if (ret) {
                                spin_unlock_irqrestore(&master->queue_lock, flags);
@@ -560,7 +561,7 @@ static void spi_pump_messages(struct kthread_work *work)
                master->busy = true;
        spin_unlock_irqrestore(&master->queue_lock, flags);
 
-       if (!was_busy) {
+       if (!was_busy && master->prepare_transfer_hardware) {
                ret = master->prepare_transfer_hardware(master);
                if (ret) {
                        dev_err(&master->dev,