* [PATCH] android: ashmem: handle the failures in ashmen driver
@ 2016-08-29 15:02 Arvind Yadav
0 siblings, 0 replies; only message in thread
From: Arvind Yadav @ 2016-08-29 15:02 UTC (permalink / raw)
To: gregkh, arve, riandrews, greg; +Cc: devel, linux-kernel, Arvind Yadav
Check return value of range_alloc, ashmem_shrink_scan and
register_shrinker. Handle errors correctly.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/staging/android/ashmem.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index ca9a53c..eacc48d 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -595,6 +595,7 @@ static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend)
{
struct ashmem_range *range, *next;
int ret = ASHMEM_NOT_PURGED;
+ int err;
list_for_each_entry_safe(range, next, &asma->unpinned_list, unpinned) {
/* moved past last applicable page; we can short circuit */
@@ -643,8 +644,11 @@ static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend)
* more complicated, we allocate a new range for the
* second half and adjust the first chunk's endpoint.
*/
- range_alloc(asma, range, range->purged,
- pgend + 1, range->pgend);
+ err = range_alloc(asma, range, range->purged,
+ pgend + 1, range->pgend);
+ if (err)
+ return err;
+
range_shrink(range, range->pgstart, pgstart - 1);
break;
}
@@ -800,7 +804,9 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
.nr_to_scan = LONG_MAX,
};
ret = ashmem_shrink_count(&ashmem_shrinker, &sc);
- ashmem_shrink_scan(&ashmem_shrinker, &sc);
+ if (ret)
+ return ret;
+ ret = ashmem_shrink_scan(&ashmem_shrinker, &sc);
}
break;
}
@@ -870,12 +876,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_free3;
+ }
pr_info("initialized\n");
return 0;
+out_free3:
+ misc_deregister(&ashmem_misc);
out_free2:
kmem_cache_destroy(ashmem_range_cachep);
out_free1:
--
2.7.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-08-29 15:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-29 15:02 [PATCH] android: ashmem: handle the failures in ashmen driver Arvind Yadav
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®