From patchwork Fri Mar 4 16:10:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 8505101 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 51B43C0553 for ; Fri, 4 Mar 2016 16:11:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62BF420122 for ; Fri, 4 Mar 2016 16:11:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 790B420114 for ; Fri, 4 Mar 2016 16:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759681AbcCDQL1 (ORCPT ); Fri, 4 Mar 2016 11:11:27 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:47259 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759106AbcCDQLY (ORCPT ); Fri, 4 Mar 2016 11:11:24 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.15.0.59/8.15.0.59) with SMTP id u24G9RWv031370; Fri, 4 Mar 2016 08:11:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=aK00k7GmCy4pN1KDnPVWodNV2nfMSY7u2ixmI0Y+nOs=; b=IoVvx8ipprpLurFlefU9KqMdjmo2jS3e5JvdV0VwdCzcKLnKjj3AsOyFk6DFWZLCNt/m gpjmsfctoqOEATZtnRwLx9SiAFRP0tO51JaXJsAXo99iZXVefSuKI/QhbCYmuE1oLs6S hTysIx/Wpv+JF7a8WminniBg/qkAGuqqUGw= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 21f6yj1f44-3 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 04 Mar 2016 08:11:21 -0800 Received: from localhost.localdomain (192.168.54.13) by mail.thefacebook.com (192.168.16.15) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 4 Mar 2016 08:10:59 -0800 From: Jens Axboe To: , CC: , , , Jens Axboe Subject: [PATCH 01/11] idr: make ida_simple_remove() return an error Date: Fri, 4 Mar 2016 09:10:43 -0700 Message-ID: <1457107853-8689-2-git-send-email-axboe@fb.com> X-Mailer: git-send-email 2.4.1.168.g1ea28e1 In-Reply-To: <1457107853-8689-1-git-send-email-axboe@fb.com> References: <1457107853-8689-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-03-04_07:, , signatures=0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The idr interface is pretty horrible, in that it doesn't return an error if we attempt to free an invalid ID, instead it calls WARN(). That's not great if we're potentially exposing this as a user visible interface, indirectly. So add __ida_remove() that returns an error instead of warning, and change ida_simple_remove() to use that interface. Alternatively we could make ida_remove() return an error, but then I'd have to verify all call sites... Signed-off-by: Jens Axboe --- include/linux/idr.h | 3 ++- lib/idr.c | 30 +++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 083d61e92706..5d9b35233200 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -175,13 +175,14 @@ struct ida { int ida_pre_get(struct ida *ida, gfp_t gfp_mask); int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); +int __ida_remove(struct ida *ida, int id); void ida_remove(struct ida *ida, int id); void ida_destroy(struct ida *ida); void ida_init(struct ida *ida); int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, gfp_t gfp_mask); -void ida_simple_remove(struct ida *ida, unsigned int id); +int ida_simple_remove(struct ida *ida, unsigned int id); /** * ida_get_new - allocate new ID diff --git a/lib/idr.c b/lib/idr.c index 6098336df267..106aca69a5e9 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -1007,7 +1007,7 @@ EXPORT_SYMBOL(ida_get_new_above); * @ida: ida handle * @id: ID to free */ -void ida_remove(struct ida *ida, int id) +int __ida_remove(struct ida *ida, int id) { struct idr_layer *p = ida->idr.top; int shift = (ida->idr.layers - 1) * IDR_BITS; @@ -1017,7 +1017,7 @@ void ida_remove(struct ida *ida, int id) struct ida_bitmap *bitmap; if (idr_id > idr_max(ida->idr.layers)) - goto err; + return -EINVAL; /* clear full bits while looking up the leaf idr_layer */ while ((shift > 0) && p) { @@ -1028,14 +1028,14 @@ void ida_remove(struct ida *ida, int id) } if (p == NULL) - goto err; + return -EINVAL; n = idr_id & IDR_MASK; __clear_bit(n, p->bitmap); bitmap = (void *)p->ary[n]; if (!bitmap || !test_bit(offset, bitmap->bitmap)) - goto err; + return -EINVAL; /* update bitmap and remove it if empty */ __clear_bit(offset, bitmap->bitmap); @@ -1045,10 +1045,19 @@ void ida_remove(struct ida *ida, int id) free_bitmap(ida, bitmap); } - return; + return 0; +} +EXPORT_SYMBOL(__ida_remove); - err: - WARN(1, "ida_remove called for id=%d which is not allocated.\n", id); +/** + * ida_remove - remove the given ID + * @ida: ida handle + * @id: ID to free + */ +void ida_remove(struct ida *ida, int id) +{ + if (__ida_remove(ida, id)) + WARN(1, "ida_remove called for id=%d which is not allocated.\n", id); } EXPORT_SYMBOL(ida_remove); @@ -1120,14 +1129,17 @@ EXPORT_SYMBOL(ida_simple_get); * @ida: the (initialized) ida. * @id: the id returned by ida_simple_get. */ -void ida_simple_remove(struct ida *ida, unsigned int id) +int ida_simple_remove(struct ida *ida, unsigned int id) { unsigned long flags; + int ret; BUG_ON((int)id < 0); spin_lock_irqsave(&simple_ida_lock, flags); - ida_remove(ida, id); + ret = __ida_remove(ida, id); spin_unlock_irqrestore(&simple_ida_lock, flags); + + return ret; } EXPORT_SYMBOL(ida_simple_remove);