diff mbox series

[3/3] scsi: sd: add support for expect_media_change_suspend flag

Message ID 20210111152029.28426-4-martin.kepplinger@puri.sm (mailing list archive)
State Superseded
Headers show
Series scsi: add runtime PM workaround for SD cardreaders | expand

Commit Message

Martin Kepplinger Jan. 11, 2021, 3:20 p.m. UTC
Make the sd driver act appropriately when the user has set
expect_media_change_suspend for a device.

Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
---
 drivers/scsi/sd.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Martin Kepplinger Jan. 11, 2021, 3:31 p.m. UTC | #1
On 11.01.21 16:20, Martin Kepplinger wrote:
> Make the sd driver act appropriately when the user has set
> expect_media_change_suspend for a device.
> 
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> ---
>   drivers/scsi/sd.c | 21 ++++++++++++++++++++-
>   1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index a3d2d4bc4a3d..ad89f8c76a27 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -608,7 +608,7 @@ static const struct dev_pm_ops sd_pm_ops = {
>   	.poweroff		= sd_suspend_system,
>   	.restore		= sd_resume,
>   	.runtime_suspend	= sd_suspend_runtime,
> -	.runtime_resume		= sd_resume,
> +	.runtime_resume		= sd_resume_runtime,
>   };
>   
>   static struct scsi_driver sd_template = {
> @@ -3699,6 +3699,25 @@ static int sd_resume(struct device *dev)
>   	return ret;
>   }
>   
> +static int sd_resume_runtime(struct device *dev)
> +{
> +	struct scsi_disk *sdkp = dev_get_drvdata(dev);
> +	int ret;
> +
> +	if (!sdkp)	/* E.g.: runtime resume at the start of sd_probe() */
> +		return 0;
> +
> +	/*
> +	 * expect_media_change_suspend is the userspace setting and
> +	 * expecting_media_change is what is checked and cleared in the
> +	 * error path if we set it here.
> +	 */
> +	if (sdkp->device->expect_media_change_suspend)
> +		sdkp->device->expecting_media_change = 1;
> +
> +	return sd_resume(dev);
> +}
> +
>   /**
>    *	init_sd - entry point for this driver (both when built in or when
>    *	a module).
> 

oops, I'm very sorry, but the following is missing in order for this to 
build:

--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -114,6 +114,7 @@ static void sd_shutdown(struct device *);
  static int sd_suspend_system(struct device *);
  static int sd_suspend_runtime(struct device *);
  static int sd_resume(struct device *);
+static int sd_resume_runtime(struct device *);
  static void sd_rescan(struct device *);
  static blk_status_t sd_init_command(struct scsi_cmnd *SCpnt);
  static void sd_uninit_command(struct scsi_cmnd *SCpnt);
kernel test robot Jan. 11, 2021, 5:37 p.m. UTC | #2
Hi Martin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next v5.11-rc3 next-20210111]
[cannot apply to target/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Martin-Kepplinger/scsi-add-runtime-PM-workaround-for-SD-cardreaders/20210111-232622
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: riscv-randconfig-r023-20210111 (attached as .config)
compiler: riscv32-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/7d6cb920cac7d125589fb70381b8ab199d7f0d67
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Martin-Kepplinger/scsi-add-runtime-PM-workaround-for-SD-cardreaders/20210111-232622
        git checkout 7d6cb920cac7d125589fb70381b8ab199d7f0d67
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/scsi/sd.c:611:21: error: 'sd_resume_runtime' undeclared here (not in a function); did you mean 'sd_suspend_runtime'?
     611 |  .runtime_resume  = sd_resume_runtime,
         |                     ^~~~~~~~~~~~~~~~~
         |                     sd_suspend_runtime
   drivers/scsi/sd.c: In function 'sd_remove':
   drivers/scsi/sd.c:3513:8: warning: variable 'devt' set but not used [-Wunused-but-set-variable]
    3513 |  dev_t devt;
         |        ^~~~
   drivers/scsi/sd.c: In function 'sd_resume_runtime':
   drivers/scsi/sd.c:3705:6: warning: unused variable 'ret' [-Wunused-variable]
    3705 |  int ret;
         |      ^~~
   At top level:
   drivers/scsi/sd.c:3702:12: warning: 'sd_resume_runtime' defined but not used [-Wunused-function]
    3702 | static int sd_resume_runtime(struct device *dev)
         |            ^~~~~~~~~~~~~~~~~


vim +611 drivers/scsi/sd.c

   604	
   605	static const struct dev_pm_ops sd_pm_ops = {
   606		.suspend		= sd_suspend_system,
   607		.resume			= sd_resume,
   608		.poweroff		= sd_suspend_system,
   609		.restore		= sd_resume,
   610		.runtime_suspend	= sd_suspend_runtime,
 > 611		.runtime_resume		= sd_resume_runtime,
   612	};
   613	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a3d2d4bc4a3d..ad89f8c76a27 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -608,7 +608,7 @@  static const struct dev_pm_ops sd_pm_ops = {
 	.poweroff		= sd_suspend_system,
 	.restore		= sd_resume,
 	.runtime_suspend	= sd_suspend_runtime,
-	.runtime_resume		= sd_resume,
+	.runtime_resume		= sd_resume_runtime,
 };
 
 static struct scsi_driver sd_template = {
@@ -3699,6 +3699,25 @@  static int sd_resume(struct device *dev)
 	return ret;
 }
 
+static int sd_resume_runtime(struct device *dev)
+{
+	struct scsi_disk *sdkp = dev_get_drvdata(dev);
+	int ret;
+
+	if (!sdkp)	/* E.g.: runtime resume at the start of sd_probe() */
+		return 0;
+
+	/*
+	 * expect_media_change_suspend is the userspace setting and
+	 * expecting_media_change is what is checked and cleared in the
+	 * error path if we set it here.
+	 */
+	if (sdkp->device->expect_media_change_suspend)
+		sdkp->device->expecting_media_change = 1;
+
+	return sd_resume(dev);
+}
+
 /**
  *	init_sd - entry point for this driver (both when built in or when
  *	a module).