diff mbox series

virtio_scsi: remove unnecessary condition check

Message ID 20180827235231.14185-1-cgxu519@gmx.com (mailing list archive)
State Changes Requested
Headers show
Series virtio_scsi: remove unnecessary condition check | expand

Commit Message

Chengguang Xu Aug. 27, 2018, 11:52 p.m. UTC
kmem_cache_destroy()/mempool_destroy() can handle NULL pointer
correctly, so there is no need to check NULL pointer before calling
kmem_cache_destroy()/mempool_destroy().

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 drivers/scsi/virtio_scsi.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Greg Edwards Aug. 28, 2018, 2:54 p.m. UTC | #1
On Tue, Aug 28, 2018 at 07:52:31AM +0800, Chengguang Xu wrote:
> @@ -1012,14 +1012,11 @@ static int __init init(void)
>  	return 0;
>
>  error:
> -	if (virtscsi_cmd_pool) {
> -		mempool_destroy(virtscsi_cmd_pool);
> -		virtscsi_cmd_pool = NULL;
> -	}
> -	if (virtscsi_cmd_cache) {
> -		kmem_cache_destroy(virtscsi_cmd_cache);
> -		virtscsi_cmd_cache = NULL;
> -	}
> +	mempool_destroy(virtscsi_cmd_pool);
> +	virtscsi_cmd_pool = NULL;
> +	kmem_cache_destroy(virtscsi_cmd_cache);
> +	virtscsi_cmd_cache = NULL;
> +

Since this is in the error unwind path of the module's init function,
you could also drop explicitly setting the pointers to NULL afterwards.

Greg
diff mbox series

Patch

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 1c72db94270e..c8c92fb5910e 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -1012,14 +1012,11 @@  static int __init init(void)
 	return 0;
 
 error:
-	if (virtscsi_cmd_pool) {
-		mempool_destroy(virtscsi_cmd_pool);
-		virtscsi_cmd_pool = NULL;
-	}
-	if (virtscsi_cmd_cache) {
-		kmem_cache_destroy(virtscsi_cmd_cache);
-		virtscsi_cmd_cache = NULL;
-	}
+	mempool_destroy(virtscsi_cmd_pool);
+	virtscsi_cmd_pool = NULL;
+	kmem_cache_destroy(virtscsi_cmd_cache);
+	virtscsi_cmd_cache = NULL;
+
 	return ret;
 }