All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: android: check the return value of register_shrinker
@ 2018-01-04  0:08 Xiongwei Song
  2018-01-04 14:55 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Xiongwei Song @ 2018-01-04  0:08 UTC (permalink / raw)
  To: gregkh, arve, tkjos, maco; +Cc: devel, linux-kernel

register_shrinker call is made in ashmem_init, it may return error code,
so we need to check it.

Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
---
 drivers/staging/android/ashmem.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 4e8947923904..0b23c3e25cd4 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -854,12 +854,18 @@ static int __init ashmem_init(void)
 		goto out_free2;
 	}
 
-	register_shrinker(&ashmem_shrinker);
+	ret = register_shrinker(&ashmem_shrinker);
+	if (unlikely(ret)) {
+		pr_err("failed to register shrinker!\n");
+		goto out_demisc;
+	}
 
 	pr_info("initialized\n");
 
 	return 0;
 
+out_demisc:
+	misc_deregister(&ashmem_misc);
 out_free2:
 	kmem_cache_destroy(ashmem_range_cachep);
 out_free1:
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: android: check the return value of register_shrinker
  2018-01-04  0:08 [PATCH] staging: android: check the return value of register_shrinker Xiongwei Song
@ 2018-01-04 14:55 ` Dan Carpenter
  2018-01-04 15:15   ` Xiongwei Song
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2018-01-04 14:55 UTC (permalink / raw)
  To: Xiongwei Song; +Cc: gregkh, arve, tkjos, maco, devel, linux-kernel

On Thu, Jan 04, 2018 at 08:08:53AM +0800, Xiongwei Song wrote:
> register_shrinker call is made in ashmem_init, it may return error code,
> so we need to check it.
> 
> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> ---
>  drivers/staging/android/ashmem.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
> index 4e8947923904..0b23c3e25cd4 100644
> --- a/drivers/staging/android/ashmem.c
> +++ b/drivers/staging/android/ashmem.c
> @@ -854,12 +854,18 @@ static int __init ashmem_init(void)
>  		goto out_free2;
>  	}
>  
> -	register_shrinker(&ashmem_shrinker);
> +	ret = register_shrinker(&ashmem_shrinker);
> +	if (unlikely(ret)) {

Don't add the unlikely() here.  It hurts readability and this is not a
fast path.  I know the other callers all have it...  :/

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: android: check the return value of register_shrinker
  2018-01-04 14:55 ` Dan Carpenter
@ 2018-01-04 15:15   ` Xiongwei Song
  0 siblings, 0 replies; 3+ messages in thread
From: Xiongwei Song @ 2018-01-04 15:15 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: gregkh, arve, tkjos, maco, devel, linux-kernel

2018-01-04 22:55 GMT+08:00 Dan Carpenter <dan.carpenter@oracle.com>:
> On Thu, Jan 04, 2018 at 08:08:53AM +0800, Xiongwei Song wrote:
>> register_shrinker call is made in ashmem_init, it may return error code,
>> so we need to check it.
>>
>> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
>> ---
>>  drivers/staging/android/ashmem.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
>> index 4e8947923904..0b23c3e25cd4 100644
>> --- a/drivers/staging/android/ashmem.c
>> +++ b/drivers/staging/android/ashmem.c
>> @@ -854,12 +854,18 @@ static int __init ashmem_init(void)
>>               goto out_free2;
>>       }
>>
>> -     register_shrinker(&ashmem_shrinker);
>> +     ret = register_shrinker(&ashmem_shrinker);
>> +     if (unlikely(ret)) {
>
> Don't add the unlikely() here.  It hurts readability and this is not a
> fast path.  I know the other callers all have it...  :/

OK. Thanks for your suggestion. I'll send v2 out.



Thanks,
Xiongwei

>
> regards,
> dan carpenter
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-04 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-04  0:08 [PATCH] staging: android: check the return value of register_shrinker Xiongwei Song
2018-01-04 14:55 ` Dan Carpenter
2018-01-04 15:15   ` Xiongwei Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.