Skip to content

Commit d7459ef

Browse files
warthog618Bartosz Golaszewski
authored andcommitted
gpio: sim: quietly ignore configured lines outside the bank
The user-space policy of the gpio-sim is that configuration for lines with offsets outside the bounds of the corresponding bank is ignored, but gpio-sim is still using that configuration when constructing the sim. In the case of named lines this results in temporarily allocating space for names that are not used, and for hogs results in errors being logged when the gpio-sim attempts to register the out of range hog with gpiolib: gpiochip_machine_hog: unable to get GPIO desc: -22 Add checks to filter out any line configuration outside the bounds of the bank when constructing the sim. Signed-off-by: Kent Gibson <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 95ae997 commit d7459ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
696696
char **line_names;
697697

698698
list_for_each_entry(line, &bank->line_list, siblings) {
699+
if (line->offset >= bank->num_lines)
700+
continue;
701+
699702
if (line->name) {
700703
if (line->offset > max_offset)
701704
max_offset = line->offset;
@@ -722,6 +725,9 @@ static char **gpio_sim_make_line_names(struct gpio_sim_bank *bank,
722725
return ERR_PTR(-ENOMEM);
723726

724727
list_for_each_entry(line, &bank->line_list, siblings) {
728+
if (line->offset >= bank->num_lines)
729+
continue;
730+
725731
if (line->name && (line->offset <= max_offset))
726732
line_names[line->offset] = line->name;
727733
}
@@ -756,6 +762,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
756762

757763
list_for_each_entry(bank, &dev->bank_list, siblings) {
758764
list_for_each_entry(line, &bank->line_list, siblings) {
765+
if (line->offset >= bank->num_lines)
766+
continue;
767+
759768
if (line->hog)
760769
num_hogs++;
761770
}
@@ -771,6 +780,9 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
771780

772781
list_for_each_entry(bank, &dev->bank_list, siblings) {
773782
list_for_each_entry(line, &bank->line_list, siblings) {
783+
if (line->offset >= bank->num_lines)
784+
continue;
785+
774786
if (!line->hog)
775787
continue;
776788

0 commit comments

Comments
 (0)