[for-4.16,v3,1/3] block: only bdi_unregister() in del_gendisk() if !GENHD_FL_HIDDEN
diff mbox

Message ID 20180111021256.37490-2-snitzer@redhat.com
State New
Headers show

Commit Message

Mike Snitzer Jan. 11, 2018, 2:12 a.m. UTC
device_add_disk() will only call bdi_register_owner() if
!GENHD_FL_HIDDEN, so it follows that del_gendisk() should only call
bdi_unregister() if !GENHD_FL_HIDDEN.

Found with code inspection.  bdi_unregister() won't do any harm if
bdi_register_owner() wasn't used but best to avoid the unnecessary
call to bdi_unregister().

Fixes: 8ddcd65325 ("block: introduce GENHD_FL_HIDDEN")
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
 block/genhd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ming Lei Jan. 11, 2018, 2:48 a.m. UTC | #1
On Wed, Jan 10, 2018 at 09:12:54PM -0500, Mike Snitzer wrote:
> device_add_disk() will only call bdi_register_owner() if
> !GENHD_FL_HIDDEN, so it follows that del_gendisk() should only call
> bdi_unregister() if !GENHD_FL_HIDDEN.
> 
> Found with code inspection.  bdi_unregister() won't do any harm if
> bdi_register_owner() wasn't used but best to avoid the unnecessary
> call to bdi_unregister().
> 
> Fixes: 8ddcd65325 ("block: introduce GENHD_FL_HIDDEN")
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> ---
>  block/genhd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index 96a66f671720..00620e01e043 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -725,7 +725,8 @@ void del_gendisk(struct gendisk *disk)
>  		 * Unregister bdi before releasing device numbers (as they can
>  		 * get reused and we'd get clashes in sysfs).
>  		 */
> -		bdi_unregister(disk->queue->backing_dev_info);
> +		if (!(disk->flags & GENHD_FL_HIDDEN))
> +			bdi_unregister(disk->queue->backing_dev_info);
>  		blk_unregister_queue(disk);
>  	} else {
>  		WARN_ON(1);
> -- 
> 2.15.0
> 

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Hannes Reinecke Jan. 11, 2018, 7:40 a.m. UTC | #2
On 01/11/2018 03:12 AM, Mike Snitzer wrote:
> device_add_disk() will only call bdi_register_owner() if
> !GENHD_FL_HIDDEN, so it follows that del_gendisk() should only call
> bdi_unregister() if !GENHD_FL_HIDDEN.
> 
> Found with code inspection.  bdi_unregister() won't do any harm if
> bdi_register_owner() wasn't used but best to avoid the unnecessary
> call to bdi_unregister().
> 
> Fixes: 8ddcd65325 ("block: introduce GENHD_FL_HIDDEN")
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> ---
>  block/genhd.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index 96a66f671720..00620e01e043 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -725,7 +725,8 @@ void del_gendisk(struct gendisk *disk)
>  		 * Unregister bdi before releasing device numbers (as they can
>  		 * get reused and we'd get clashes in sysfs).
>  		 */
> -		bdi_unregister(disk->queue->backing_dev_info);
> +		if (!(disk->flags & GENHD_FL_HIDDEN))
> +			bdi_unregister(disk->queue->backing_dev_info);
>  		blk_unregister_queue(disk);
>  	} else {
>  		WARN_ON(1);
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes

Patch
diff mbox

diff --git a/block/genhd.c b/block/genhd.c
index 96a66f671720..00620e01e043 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -725,7 +725,8 @@  void del_gendisk(struct gendisk *disk)
 		 * Unregister bdi before releasing device numbers (as they can
 		 * get reused and we'd get clashes in sysfs).
 		 */
-		bdi_unregister(disk->queue->backing_dev_info);
+		if (!(disk->flags & GENHD_FL_HIDDEN))
+			bdi_unregister(disk->queue->backing_dev_info);
 		blk_unregister_queue(disk);
 	} else {
 		WARN_ON(1);