diff options
author | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-05-31 23:09:56 +0200 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-05-31 23:13:26 +0200 |
commit | 5b257571cd487bf3f5779b2b4b15216cc5eb7bb6 (patch) | |
tree | 6a36e989e97637c72e75c10fbc1a786da9f116f5 /drivers/rtc/rtc-test.c | |
parent | 9394270ef9ce455b84f896a0060423019834a0e3 (diff) | |
download | linux-5b257571cd487bf3f5779b2b4b15216cc5eb7bb6.tar.bz2 |
rtc: test: allow registering many devices
Use a loop to register RTC devices
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/rtc-test.c')
-rw-r--r-- | drivers/rtc/rtc-test.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c index f0eb8e0c5055..796c45dee661 100644 --- a/drivers/rtc/rtc-test.c +++ b/drivers/rtc/rtc-test.c @@ -13,7 +13,9 @@ #include <linux/rtc.h> #include <linux/platform_device.h> -static struct platform_device *test0 = NULL, *test1 = NULL; +#define MAX_RTC_TEST 3 + +struct platform_device *pdev[MAX_RTC_TEST]; static int test_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) @@ -122,47 +124,45 @@ static struct platform_driver test_driver = { static int __init test_init(void) { - int err; + int i, err; if ((err = platform_driver_register(&test_driver))) return err; - if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) { - err = -ENOMEM; - goto exit_driver_unregister; + err = -ENOMEM; + for (i = 0; i < MAX_RTC_TEST; i++) { + pdev[i] = platform_device_alloc("rtc-test", i); + if (!pdev[i]) + goto exit_free_mem; } - if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) { - err = -ENOMEM; - goto exit_put_test0; + for (i = 0; i < MAX_RTC_TEST; i++) { + err = platform_device_add(pdev[i]); + if (err) + goto exit_device_del; } - if ((err = platform_device_add(test0))) - goto exit_put_test1; - - if ((err = platform_device_add(test1))) - goto exit_del_test0; - return 0; -exit_del_test0: - platform_device_del(test0); +exit_device_del: + for (; i > 0; i--) + platform_device_del(pdev[i - 1]); -exit_put_test1: - platform_device_put(test1); +exit_free_mem: + for (i = 0; i < MAX_RTC_TEST; i++) + platform_device_put(pdev[i]); -exit_put_test0: - platform_device_put(test0); - -exit_driver_unregister: platform_driver_unregister(&test_driver); return err; } static void __exit test_exit(void) { - platform_device_unregister(test0); - platform_device_unregister(test1); + int i; + + for (i = 0; i < MAX_RTC_TEST; i++) + platform_device_unregister(pdev[i]); + platform_driver_unregister(&test_driver); } |