Re: [PATCH 18/19] sr: simplify sr_block_revalidate_disk

2020-09-09 Thread Hannes Reinecke
On 9/8/20 4:53 PM, Christoph Hellwig wrote:
> Both callers have a valid CD struture available, so rely on that instead
> of getting another reference.  Also move the function to avoid a forward
> declaration.
> 
> Signed-off-by: Christoph Hellwig 
> Reviewed-by: Johannes Thumshirn 
> ---
>  drivers/scsi/sr.c | 36 +---
>  1 file changed, 13 insertions(+), 23 deletions(-)
> 
Reviewed-by: Hannes Reinecke 

Cheers,

Hannes
-- 
Dr. Hannes ReineckeKernel Storage Architect
h...@suse.de  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer


[PATCH 18/19] sr: simplify sr_block_revalidate_disk

2020-09-08 Thread Christoph Hellwig
Both callers have a valid CD struture available, so rely on that instead
of getting another reference.  Also move the function to avoid a forward
declaration.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Johannes Thumshirn 
---
 drivers/scsi/sr.c | 36 +---
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 34be94b62523fa..2b43c0f97442d4 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -86,7 +86,6 @@ static int sr_remove(struct device *);
 static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt);
 static int sr_done(struct scsi_cmnd *);
 static int sr_runtime_suspend(struct device *dev);
-static int sr_block_revalidate_disk(struct gendisk *disk);
 
 static const struct dev_pm_ops sr_pm_ops = {
.runtime_suspend= sr_runtime_suspend,
@@ -518,6 +517,17 @@ static blk_status_t sr_init_command(struct scsi_cmnd 
*SCpnt)
return ret;
 }
 
+static void sr_revalidate_disk(struct scsi_cd *cd)
+{
+   struct scsi_sense_hdr sshdr;
+
+   /* if the unit is not ready, nothing more to do */
+   if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, ))
+   return;
+   sr_cd_check(>cdi);
+   get_sectorsize(cd);
+}
+
 static int sr_block_open(struct block_device *bdev, fmode_t mode)
 {
struct scsi_cd *cd;
@@ -531,7 +541,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t 
mode)
sdev = cd->device;
scsi_autopm_get_device(sdev);
if (bdev_check_media_change(bdev))
-   sr_block_revalidate_disk(bdev->bd_disk);
+   sr_revalidate_disk(cd);
 
mutex_lock(>lock);
ret = cdrom_open(>cdi, bdev, mode);
@@ -660,26 +670,6 @@ static unsigned int sr_block_check_events(struct gendisk 
*disk,
return ret;
 }
 
-static int sr_block_revalidate_disk(struct gendisk *disk)
-{
-   struct scsi_sense_hdr sshdr;
-   struct scsi_cd *cd;
-
-   cd = scsi_cd_get(disk);
-   if (!cd)
-   return -ENXIO;
-
-   /* if the unit is not ready, nothing more to do */
-   if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, ))
-   goto out;
-
-   sr_cd_check(>cdi);
-   get_sectorsize(cd);
-out:
-   scsi_cd_put(cd);
-   return 0;
-}
-
 static const struct block_device_operations sr_bdops =
 {
.owner  = THIS_MODULE,
@@ -803,7 +793,7 @@ static int sr_probe(struct device *dev)
 
dev_set_drvdata(dev, cd);
disk->flags |= GENHD_FL_REMOVABLE;
-   sr_block_revalidate_disk(disk);
+   sr_revalidate_disk(cd);
device_add_disk(>sdev_gendev, disk, NULL);
 
sdev_printk(KERN_DEBUG, sdev,
-- 
2.28.0



Re: [PATCH 18/19] sr: simplify sr_block_revalidate_disk

2020-09-02 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 


[PATCH 18/19] sr: simplify sr_block_revalidate_disk

2020-09-02 Thread Christoph Hellwig
Both callers have a valid CD struture available, so rely on that instead
of getting another reference.  Also move the function to avoid a forward
declaration.

Signed-off-by: Christoph Hellwig 
---
 drivers/scsi/sr.c | 36 +---
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 34be94b62523fa..2b43c0f97442d4 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -86,7 +86,6 @@ static int sr_remove(struct device *);
 static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt);
 static int sr_done(struct scsi_cmnd *);
 static int sr_runtime_suspend(struct device *dev);
-static int sr_block_revalidate_disk(struct gendisk *disk);
 
 static const struct dev_pm_ops sr_pm_ops = {
.runtime_suspend= sr_runtime_suspend,
@@ -518,6 +517,17 @@ static blk_status_t sr_init_command(struct scsi_cmnd 
*SCpnt)
return ret;
 }
 
+static void sr_revalidate_disk(struct scsi_cd *cd)
+{
+   struct scsi_sense_hdr sshdr;
+
+   /* if the unit is not ready, nothing more to do */
+   if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, ))
+   return;
+   sr_cd_check(>cdi);
+   get_sectorsize(cd);
+}
+
 static int sr_block_open(struct block_device *bdev, fmode_t mode)
 {
struct scsi_cd *cd;
@@ -531,7 +541,7 @@ static int sr_block_open(struct block_device *bdev, fmode_t 
mode)
sdev = cd->device;
scsi_autopm_get_device(sdev);
if (bdev_check_media_change(bdev))
-   sr_block_revalidate_disk(bdev->bd_disk);
+   sr_revalidate_disk(cd);
 
mutex_lock(>lock);
ret = cdrom_open(>cdi, bdev, mode);
@@ -660,26 +670,6 @@ static unsigned int sr_block_check_events(struct gendisk 
*disk,
return ret;
 }
 
-static int sr_block_revalidate_disk(struct gendisk *disk)
-{
-   struct scsi_sense_hdr sshdr;
-   struct scsi_cd *cd;
-
-   cd = scsi_cd_get(disk);
-   if (!cd)
-   return -ENXIO;
-
-   /* if the unit is not ready, nothing more to do */
-   if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, ))
-   goto out;
-
-   sr_cd_check(>cdi);
-   get_sectorsize(cd);
-out:
-   scsi_cd_put(cd);
-   return 0;
-}
-
 static const struct block_device_operations sr_bdops =
 {
.owner  = THIS_MODULE,
@@ -803,7 +793,7 @@ static int sr_probe(struct device *dev)
 
dev_set_drvdata(dev, cd);
disk->flags |= GENHD_FL_REMOVABLE;
-   sr_block_revalidate_disk(disk);
+   sr_revalidate_disk(cd);
device_add_disk(>sdev_gendev, disk, NULL);
 
sdev_printk(KERN_DEBUG, sdev,
-- 
2.28.0