Skip to content

Commit 125cda8

Browse files
dpenklergregkh
authored andcommitted
staging: gpib: Cleanup allocate_gpios code
The function was using unnecessary variables error and retval. Simplify the code by testing for failure first and remove the redundant variables. Tested-by: Dave Penkler <dpenkler@gmail.com> Signed-off-by: Dave Penkler <dpenkler@gmail.com> Link: https://lore.kernel.org/r/20250418173434.2892-8-dpenkler@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 427ab51 commit 125cda8

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

drivers/staging/gpib/gpio/gpib_bitbang.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,7 @@ static void release_gpios(void)
11231123

11241124
static int allocate_gpios(struct gpib_board *board)
11251125
{
1126-
int j, retval = 0;
1127-
bool error = false;
1126+
int j;
11281127
int table_index = 0;
11291128
char name[256];
11301129
struct gpio_desc *desc;
@@ -1135,8 +1134,8 @@ static int allocate_gpios(struct gpib_board *board)
11351134
return -ENOENT;
11361135
}
11371136

1138-
lookup_table = lookup_tables[0];
1139-
lookup_table->dev_id = dev_name(board->gpib_dev);
1137+
lookup_table = lookup_tables[table_index];
1138+
lookup_table->dev_id = dev_name(board->gpib_dev);
11401139
gpiod_add_lookup_table(lookup_table);
11411140
dbg_printk(1, "Allocating gpios using table index %d\n", table_index);
11421141

@@ -1153,28 +1152,26 @@ static int allocate_gpios(struct gpib_board *board)
11531152
gpiod_remove_lookup_table(lookup_table);
11541153
table_index++;
11551154
lookup_table = lookup_tables[table_index];
1156-
if (lookup_table) {
1157-
dbg_printk(1, "Allocation failed, now using table_index %d\n",
1158-
table_index);
1159-
lookup_table->dev_id = dev_name(board->gpib_dev);
1160-
gpiod_add_lookup_table(lookup_table);
1161-
goto try_again;
1155+
if (!lookup_table) {
1156+
dev_err(board->gpib_dev, "Unable to obtain gpio descriptor for pin %d error %ld\n",
1157+
gpios_vector[j], PTR_ERR(desc));
1158+
goto alloc_gpios_fail;
11621159
}
1163-
dev_err(board->gpib_dev, "Unable to obtain gpio descriptor for pin %d error %ld\n",
1164-
gpios_vector[j], PTR_ERR(desc));
1165-
error = true;
1166-
break;
1160+
dbg_printk(1, "Allocation failed, now using table_index %d\n", table_index);
1161+
lookup_table->dev_id = dev_name(board->gpib_dev);
1162+
gpiod_add_lookup_table(lookup_table);
1163+
goto try_again;
11671164
}
11681165
all_descriptors[j] = desc;
11691166
}
11701167

1171-
if (error) { /* undo what already done */
1172-
release_gpios();
1173-
retval = -1;
1174-
}
1175-
if (lookup_table)
1176-
gpiod_remove_lookup_table(lookup_table);
1177-
return retval;
1168+
gpiod_remove_lookup_table(lookup_table);
1169+
1170+
return 0;
1171+
1172+
alloc_gpios_fail:
1173+
release_gpios();
1174+
return -1;
11781175
}
11791176

11801177
static void bb_detach(struct gpib_board *board)

0 commit comments

Comments
 (0)