Commit cc2439fd authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:core simplify and fix a bug in iio_device_(un)register_event_set.

The unwinding index was j, not i and it is much simpler to do these as a single
loop unwinding those elements necessary in before jumping to the error handler.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent cd038019
...@@ -1061,7 +1061,7 @@ static int iio_device_register_eventset(struct iio_dev *dev_info) ...@@ -1061,7 +1061,7 @@ static int iio_device_register_eventset(struct iio_dev *dev_info)
if (ret) { if (ret) {
dev_err(&dev_info->dev, dev_err(&dev_info->dev,
"Could not get chrdev interface\n"); "Could not get chrdev interface\n");
goto error_free_setup_ev_ints; goto error_free_setup_event_lines;
} }
dev_set_drvdata(&dev_info->event_interfaces[i].dev, dev_set_drvdata(&dev_info->event_interfaces[i].dev,
...@@ -1077,31 +1077,33 @@ static int iio_device_register_eventset(struct iio_dev *dev_info) ...@@ -1077,31 +1077,33 @@ static int iio_device_register_eventset(struct iio_dev *dev_info)
if (ret) { if (ret) {
dev_err(&dev_info->dev, dev_err(&dev_info->dev,
"Failed to register sysfs for event attrs"); "Failed to register sysfs for event attrs");
goto error_remove_sysfs_interfaces; iio_free_ev_int(&dev_info->event_interfaces[i]);
} goto error_free_setup_event_lines;
} }
for (i = 0; i < dev_info->info->num_interrupt_lines; i++) {
ret = __iio_add_event_config_attrs(dev_info, i); ret = __iio_add_event_config_attrs(dev_info, i);
if (ret) if (ret) {
goto error_unregister_config_attrs; if (dev_info->info->event_attrs != NULL)
sysfs_remove_group(&dev_info
->event_interfaces[i]
.dev.kobj,
&dev_info->info
->event_attrs[i]);
iio_free_ev_int(&dev_info->event_interfaces[i]);
goto error_free_setup_event_lines;
}
} }
return 0; return 0;
error_unregister_config_attrs: error_free_setup_event_lines:
for (j = 0; j < i; j++) for (j = 0; j < i; j++) {
__iio_remove_event_config_attrs(dev_info, i); __iio_remove_event_config_attrs(dev_info, j);
i = dev_info->info->num_interrupt_lines - 1;
error_remove_sysfs_interfaces:
for (j = 0; j < i; j++)
if (dev_info->info->event_attrs != NULL) if (dev_info->info->event_attrs != NULL)
sysfs_remove_group(&dev_info sysfs_remove_group(&dev_info
->event_interfaces[j].dev.kobj, ->event_interfaces[j].dev.kobj,
&dev_info->info->event_attrs[j]); &dev_info->info->event_attrs[j]);
error_free_setup_ev_ints:
for (j = 0; j < i; j++)
iio_free_ev_int(&dev_info->event_interfaces[j]); iio_free_ev_int(&dev_info->event_interfaces[j]);
}
kfree(dev_info->event_interfaces); kfree(dev_info->event_interfaces);
error_ret: error_ret:
...@@ -1120,10 +1122,8 @@ static void iio_device_unregister_eventset(struct iio_dev *dev_info) ...@@ -1120,10 +1122,8 @@ static void iio_device_unregister_eventset(struct iio_dev *dev_info)
sysfs_remove_group(&dev_info sysfs_remove_group(&dev_info
->event_interfaces[i].dev.kobj, ->event_interfaces[i].dev.kobj,
&dev_info->info->event_attrs[i]); &dev_info->info->event_attrs[i]);
}
for (i = 0; i < dev_info->info->num_interrupt_lines; i++)
iio_free_ev_int(&dev_info->event_interfaces[i]); iio_free_ev_int(&dev_info->event_interfaces[i]);
}
kfree(dev_info->event_interfaces); kfree(dev_info->event_interfaces);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment