Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754706AbcJZO1u (ORCPT ); Wed, 26 Oct 2016 10:27:50 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36888 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753088AbcJZO1s (ORCPT ); Wed, 26 Oct 2016 10:27:48 -0400 From: Daniel Vetter To: LKML Cc: Intel Graphics Development , Daniel Vetter , Mel Gorman , Michal Hocko , Vlastimil Babka , Tejun Heo , Andrew Morton , Daniel Vetter Subject: [PATCH] lib/ida: Document locking requirements a bit better Date: Wed, 26 Oct 2016 16:27:39 +0200 Message-Id: <20161026142739.20266-1-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.10.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2061 Lines: 55 I wanted to wrap a bunch of ida_simple_get calls into their own locking, until I dug around and read the original commit message. Stuff like this should imo be added to the kernel doc, let's do that. Cc: Mel Gorman Cc: Michal Hocko Cc: Vlastimil Babka Cc: Tejun Heo Cc: Andrew Morton Signed-off-by: Daniel Vetter --- lib/idr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/idr.c b/lib/idr.c index 6098336df267..5508d7f6d7be 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -927,6 +927,9 @@ EXPORT_SYMBOL(ida_pre_get); * and go back to the ida_pre_get() call. If the ida is full, it will * return %-ENOSPC. * + * Note that callers must ensure that concurrent access to @ida is not possible. + * When simplicity trumps concurrency needs look at ida_simple_get() instead. + * * @p_id returns a value in the range @starting_id ... %0x7fffffff. */ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) @@ -1073,6 +1076,10 @@ EXPORT_SYMBOL(ida_destroy); * Allocates an id in the range start <= id < end, or returns -ENOSPC. * On memory allocation failure, returns -ENOMEM. * + * Compared to ida_get_new_above() this function does its own locking and hence + * is recommended everywhere where simplicity is preferred over the last bit of + * speed. + * * Use ida_simple_remove() to get rid of an id. */ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, @@ -1119,6 +1126,13 @@ EXPORT_SYMBOL(ida_simple_get); * ida_simple_remove - remove an allocated id. * @ida: the (initialized) ida. * @id: the id returned by ida_simple_get. + * + * Use to release an id allocated with ida_simple_get(). + * + * Compared to ida_get_new_above() this function does its own locking and hence + * is recommended everywhere where simplicity is preferred over the last bit of + * speed. + * */ void ida_simple_remove(struct ida *ida, unsigned int id) { -- 2.10.1