[RFC PATCH 19/20] loop: set error value in case of actual error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function add loop_add() set err = -ENOMEM before the call to
kzalloc(), err = -ENOMEM before the call to alloc_disk(). None of these
error number values are shared. That requires err to be set explicitly
before actual error happens.

Conditionally set the error after we actually know that error condition
is true insted of setting it before the if check.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
---
 drivers/block/loop.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d99ae348e4e2..ef70795e36ab 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2062,10 +2062,11 @@ static int loop_add(struct loop_device **l, int i)
 
 	lockdep_assert_held(&loop_ctl_mutex);
 
-	err = -ENOMEM;
 	lo = kzalloc(sizeof(*lo), GFP_KERNEL);
-	if (!lo)
+	if (!lo) {
+		err = -ENOMEM;
 		goto out;
+	}
 
 	lo->lo_state = Lo_unbound;
 
@@ -2081,7 +2082,6 @@ static int loop_add(struct loop_device **l, int i)
 		goto out_free_dev;
 	i = err;
 
-	err = -ENOMEM;
 	lo->tag_set.ops = &loop_mq_ops;
 	lo->tag_set.nr_hw_queues = 1;
 	lo->tag_set.queue_depth = hw_queue_depth;
@@ -2091,8 +2091,10 @@ static int loop_add(struct loop_device **l, int i)
 	lo->tag_set.driver_data = lo;
 
 	err = blk_mq_alloc_tag_set(&lo->tag_set);
-	if (err)
+	if (err) {
+		err = -ENOMEM;
 		goto out_free_idr;
+	}
 
 	lo->lo_queue = blk_mq_init_queue(&lo->tag_set);
 	if (IS_ERR(lo->lo_queue)) {
@@ -2111,10 +2113,11 @@ static int loop_add(struct loop_device **l, int i)
 	 */
 	blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
 
-	err = -ENOMEM;
 	disk = lo->lo_disk = alloc_disk(1 << part_shift);
-	if (!disk)
+	if (!disk) {
+		err = -ENOMEM;
 		goto out_free_queue;
+	}
 
 	/*
 	 * Disable partition scanning by default. The in-kernel partition
-- 
2.22.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux