Message ID | 20121106165144.bdeca850.akpm@linux-foundation.org |
---|---|
State | Accepted |
Headers | show |
On 11/07/2012 08:51 AM, Andrew Morton wrote: > On Tue, 23 Oct 2012 13:08:41 +0800 > Wei Yongjun <weiyj.lk@gmail.com> wrote: > >> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn> >> >> In case of error, the function test_init() need to call >> platform_device_del() instead of platform_device_unregister(). >> Otherwise, we may call platform_device_put() twice. >> > Is platform_device_del() the partner to platform_device_add()? If so > then yes, this looks right. But I think the labels can be improved: > > _ > > > However, take a look at test_exit(). it does > platform_device_unregister(test0) when test0 is in the same state. Is > that code wrong as well? Presumably it's working OK? platform_device_unregister() is a warp of platform_device_del() and platform_device_put(), if platform_device_add() success, we can use platform_device_unregister() to do this, so that code is OK.
--- a/drivers/rtc/rtc-test.c~rtc-avoid-calling-platform_device_put-twice-in-test_init-fix +++ a/drivers/rtc/rtc-test.c @@ -152,24 +152,24 @@ static int __init test_init(void) if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) { err = -ENOMEM; - goto exit_free_test0; + goto exit_put_test0; } if ((err = platform_device_add(test0))) - goto exit_free_test1; + goto exit_put_test1; if ((err = platform_device_add(test1))) - goto exit_device_unregister; + goto exit_del_test0; return 0; -exit_device_unregister: +exit_del_test0: platform_device_del(test0); -exit_free_test1: +exit_put_test1: platform_device_put(test1); -exit_free_test0: +exit_put_test0: platform_device_put(test0); exit_driver_unregister: