mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arvind Yadav <arvind.yadav.cs@gmail.com>
To: gregkh@linuxfoundation.org, arve@android.com,
	riandrews@android.com, greg@kroah.com
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	Arvind Yadav <arvind.yadav.cs@gmail.com>
Subject: [PATCH] android: ashmem: handle the failures in ashmen driver
Date: Mon, 29 Aug 2016 20:32:18 +0530	[thread overview]
Message-ID: <1472482938-6025-1-git-send-email-arvind.yadav.cs@gmail.com> (raw)

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

                 reply	other threads:[~2016-08-29 15:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472482938-6025-1-git-send-email-arvind.yadav.cs@gmail.com \
    --to=arvind.yadav.cs@gmail.com \
    --cc=arve@android.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=greg@kroah.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riandrews@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®